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 org.apache.camel.Service;
020    
021    /**
022     * Access to a repository of Message IDs to implement the
023     * <a href="http://camel.apache.org/idempotent-consumer.html">Idempotent Consumer</a> pattern.
024     * <p/>
025     * The <tt>add</tt> and <tt>contains</tt> methods is operating according to the {@link java.util.Set} contract.
026     *
027     * @version 
028     */
029    public interface IdempotentRepository<E> extends Service {
030    
031        /**
032         * Adds the key to the repository.
033         *
034         * @param key the key of the message for duplicate test
035         * @return <tt>true</tt> if this repository did <b>not</b> already contain the specified element
036         */
037        boolean add(E key);
038    
039        /**
040         * Returns <tt>true</tt> if this repository contains the specified element.
041         * <p/>
042         * This operation is used if the option <tt>eager</tt> has been enabled.
043         *
044         * @param key the key of the message
045         * @return <tt>true</tt> if this repository contains the specified element
046         */
047        boolean contains(E key);
048    
049        /**
050         * Removes the key from the repository.
051         * <p/>
052         * Is usually invoked if the exchange failed.
053         *
054         * @param key the key of the message for duplicate test
055         * @return <tt>true</tt> if the key was removed
056         */
057        boolean remove(E key);
058    
059        /**
060         * Confirms the key, after the exchange has been processed successfully.
061         * <p/>
062         * This operation is used if the option <tt>eager</tt> has been enabled.
063         *
064         * @param key the key of the message for duplicate test
065         * @return <tt>true</tt> if the key was confirmed
066         */
067        boolean confirm(E key);
068    
069    }