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 */
029public interface RecoverableAggregationRepository extends AggregationRepository {
030
031    /**
032     * Scans the repository for {@link Exchange}s to be recovered
033     * 
034     * @param camelContext   the current CamelContext
035     * @return the exchange ids for to be recovered
036     */
037    Set<String> scan(CamelContext camelContext);
038
039    /**
040     * Recovers the exchange with the given exchange id
041     *
042     * @param camelContext   the current CamelContext
043     * @param exchangeId     exchange id
044     * @return the recovered exchange or <tt>null</tt> if not found
045     */
046    Exchange recover(CamelContext camelContext, String exchangeId);
047
048    /**
049     * Sets the interval between recovery scans
050     *
051     * @param interval  the interval
052     * @param timeUnit  the time unit
053     */
054    void setRecoveryInterval(long interval, TimeUnit timeUnit);
055
056    /**
057     * Sets the interval between recovery scans
058     *
059     * @param interval  the interval in millis
060     */
061    void setRecoveryInterval(long interval);
062
063    /**
064     * Gets the interval between recovery scans in millis.
065     *
066     * @return the interval in millis
067     */
068    long getRecoveryIntervalInMillis();
069
070    /**
071     * Sets whether or not recovery is enabled
072     *
073     * @param useRecovery whether or not recovery is enabled
074     */
075    void setUseRecovery(boolean useRecovery);
076
077    /**
078     * Whether or not recovery is enabled or not
079     *
080     * @return <tt>true</tt> to use recovery, <tt>false</tt> otherwise.
081     */
082    boolean isUseRecovery();
083
084    /**
085     * Sets an optional dead letter channel which exhausted recovered {@link Exchange}
086     * should be send to.
087     * <p/>
088     * By default this option is disabled
089     *
090     * @param deadLetterUri  the uri of the dead letter channel
091     */
092    void setDeadLetterUri(String deadLetterUri);
093
094    /**
095     * Gets the dead letter channel
096     *
097     * @return  the uri of the dead letter channel
098     */
099    String getDeadLetterUri();
100
101    /**
102     * Sets an optional limit of the number of redelivery attempt of recovered {@link Exchange}
103     * should be attempted, before its exhausted.
104     * <p/>
105     * When this limit is hit, then the {@link Exchange} is moved to the dead letter channel.
106     * <p/>
107     * By default this option is disabled
108     *
109     * @param maximumRedeliveries the maximum redeliveries
110     */
111    void setMaximumRedeliveries(int maximumRedeliveries);
112
113    /**
114     * Gets the maximum redelivery attempts to do before a recovered {@link Exchange} is doomed
115     * as exhausted and moved to the dead letter channel.
116     *
117     * @return the maximum redeliveries
118     */
119    int getMaximumRedeliveries();
120
121}