001/**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.camel.spi;
018
019import java.util.Set;
020import java.util.concurrent.TimeUnit;
021
022import org.apache.camel.CamelContext;
023import org.apache.camel.Exchange;
024
025/**
026 * A specialized {@link org.apache.camel.spi.AggregationRepository} which also supports
027 * recovery. This usually requires a repository which is persisted.
028 *
029 * @version 
030 */
031public interface RecoverableAggregationRepository extends AggregationRepository {
032
033    /**
034     * Scans the repository for {@link Exchange}s to be recovered
035     * 
036     * @param camelContext   the current CamelContext
037     * @return the exchange ids for to be recovered
038     */
039    Set<String> scan(CamelContext camelContext);
040
041    /**
042     * Recovers the exchange with the given exchange id
043     *
044     * @param camelContext   the current CamelContext
045     * @param exchangeId     exchange id
046     * @return the recovered exchange or <tt>null</tt> if not found
047     */
048    Exchange recover(CamelContext camelContext, String exchangeId);
049
050    /**
051     * Sets the interval between recovery scans
052     *
053     * @param interval  the interval
054     * @param timeUnit  the time unit
055     */
056    void setRecoveryInterval(long interval, TimeUnit timeUnit);
057
058    /**
059     * Sets the interval between recovery scans
060     *
061     * @param interval  the interval in millis
062     */
063    void setRecoveryInterval(long interval);
064
065    /**
066     * Gets the interval between recovery scans in millis.
067     *
068     * @return the interval in millis
069     */
070    long getRecoveryIntervalInMillis();
071
072    /**
073     * Sets whether or not recovery is enabled
074     *
075     * @param useRecovery whether or not recovery is enabled
076     */
077    void setUseRecovery(boolean useRecovery);
078
079    /**
080     * Whether or not recovery is enabled or not
081     *
082     * @return <tt>true</tt> to use recovery, <tt>false</tt> otherwise.
083     */
084    boolean isUseRecovery();
085
086    /**
087     * Sets an optional dead letter channel which exhausted recovered {@link Exchange}
088     * should be send to.
089     * <p/>
090     * By default this option is disabled
091     *
092     * @param deadLetterUri  the uri of the dead letter channel
093     */
094    void setDeadLetterUri(String deadLetterUri);
095
096    /**
097     * Gets the dead letter channel
098     *
099     * @return  the uri of the dead letter channel
100     */
101    String getDeadLetterUri();
102
103    /**
104     * Sets an optional limit of the number of redelivery attempt of recovered {@link Exchange}
105     * should be attempted, before its exhausted.
106     * <p/>
107     * When this limit is hit, then the {@link Exchange} is moved to the dead letter channel.
108     * <p/>
109     * By default this option is disabled
110     *
111     * @param maximumRedeliveries the maximum redeliveries
112     */
113    void setMaximumRedeliveries(int maximumRedeliveries);
114
115    /**
116     * Gets the maximum redelivery attempts to do before a recovered {@link Exchange} is doomed
117     * as exhausted and moved to the dead letter channel.
118     *
119     * @return the maximum redeliveries
120     */
121    int getMaximumRedeliveries();
122
123}