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     * <p/>
027     * The repository supports eager (default) and non-eager mode.
028     * <ul>
029     *     <li>eager: calls <tt>add</tt> and <tt>confirm</tt> if complete, or <tt>remove</tt> if failed</li>
030     *     <li>non-eager: calls <tt>contains</tt> and <tt>add</tt> if complete, or <tt>remove</tt> if failed</li>
031     * </ul>
032     * Notice the remove callback, can be configured to be disabled.
033     *
034     * @version 
035     */
036    public interface IdempotentRepository<E> extends Service {
037    
038        /**
039         * Adds the key to the repository.
040         * <p/>
041         * <b>Important:</b> Read the class javadoc about eager vs non-eager mode.
042         *
043         * @param key the key of the message for duplicate test
044         * @return <tt>true</tt> if this repository did <b>not</b> already contain the specified element
045         */
046        boolean add(E key);
047    
048        /**
049         * Returns <tt>true</tt> if this repository contains the specified element.
050         * <p/>
051         * <b>Important:</b> Read the class javadoc about eager vs non-eager mode.
052         *
053         * @param key the key of the message
054         * @return <tt>true</tt> if this repository contains the specified element
055         */
056        boolean contains(E key);
057    
058        /**
059         * Removes the key from the repository.
060         * <p/>
061         * Is usually invoked if the exchange failed.
062         * <p/>
063         * <b>Important:</b> Read the class javadoc about eager vs non-eager mode.
064         *
065         * @param key the key of the message for duplicate test
066         * @return <tt>true</tt> if the key was removed
067         */
068        boolean remove(E key);
069    
070        /**
071         * Confirms the key, after the exchange has been processed successfully.
072         * <p/>
073         * <b>Important:</b> Read the class javadoc about eager vs non-eager mode.
074         *
075         * @param key the key of the message for duplicate test
076         * @return <tt>true</tt> if the key was confirmed
077         */
078        boolean confirm(E key);
079    
080    }