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     */
017    package org.apache.camel.spi;
018    
019    import java.util.Set;
020    
021    import org.apache.camel.CamelContext;
022    import org.apache.camel.Exchange;
023    
024    /**
025     * Access to a repository to store aggregated exchanges to support pluggable implementations.
026     *  
027     * @version 
028     */
029    public interface AggregationRepository {
030    
031        /**
032         * Add the given {@link Exchange} under the correlation key.
033         * <p/>
034         * Will replace any existing exchange.
035         * <p/>
036         * <b>Important:</b> This method is <b>not</b> invoked if only one exchange was completed, and therefore
037         * the exchange does not need to be added to a repository, as its completed immediately.
038         *
039         * @param camelContext   the current CamelContext
040         * @param key            the correlation key
041         * @param exchange       the aggregated exchange
042         * @return the old exchange if any existed
043         */
044        Exchange add(CamelContext camelContext, String key, Exchange exchange);
045    
046        /**
047         * Gets the given exchange with the correlation key
048         * <p/>
049         * This method is always invoked for any incoming exchange in the aggregator.
050         *
051         * @param camelContext   the current CamelContext
052         * @param key            the correlation key
053         * @return the exchange, or <tt>null</tt> if no exchange was previously added
054         */
055        Exchange get(CamelContext camelContext, String key);
056    
057        /**
058         * Removes the exchange with the given correlation key, which should happen
059         * when an {@link Exchange} is completed
060         * <p/>
061         * <b>Important:</b> This method is <b>not</b> invoked if only one exchange was completed, and therefore
062         * the exchange does not need to be added to a repository, as its completed immediately.
063         *
064         * @param camelContext   the current CamelContext
065         * @param key            the correlation key
066         * @param exchange       the exchange to remove
067         */
068        void remove(CamelContext camelContext, String key, Exchange exchange);
069    
070        /**
071         * Confirms the completion of the {@link Exchange}.
072         * <p/>
073         * This method is always invoked.
074         *
075         * @param camelContext  the current CamelContext
076         * @param exchangeId    exchange id to confirm
077         */
078        void confirm(CamelContext camelContext, String exchangeId);
079    
080        /**
081         * Gets the keys currently in the repository.
082         *
083         * @return the keys
084         */
085        Set<String> getKeys();
086    
087    }