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 org.apache.camel.Exchange;
020import org.apache.camel.Service;
021
022/**
023 * Access to a repository of keys to implement the
024 * <a href="http://camel.apache.org/claim-check.html">Claim Check</a> pattern.
025 * <p/>
026 * The <tt>add</tt> and <tt>contains</tt> methods is operating according to the {@link java.util.Map} contract,
027 * and the <tt>push</tt> and <tt>pop</tt> methods is operating according to the {@link java.util.Stack} contract.
028 * <p/>
029 * See important details about the Claim Check EIP implementation in Apache Camel at {@link org.apache.camel.processor.ClaimCheckProcessor}.
030 */
031public interface ClaimCheckRepository extends Service {
032
033    /**
034     * Adds the exchange to the repository.
035     *
036     * @param key the claim check key
037     * @return <tt>true</tt> if this repository did <b>not</b> already contain the specified key
038     */
039    boolean add(String key, Exchange exchange);
040
041    /**
042     * Returns <tt>true</tt> if this repository contains the specified key.
043     *
044     * @param key the claim check key
045     * @return <tt>true</tt> if this repository contains the specified key
046     */
047    boolean contains(String key);
048
049    /**
050     * Gets the exchange from the repository.
051     *
052     * @param key the claim check key
053     */
054    Exchange get(String key);
055
056    /**
057     * Gets and removes the exchange from the repository.
058     *
059     * @param key the claim check key
060     * @return the removed exchange, or <tt>null</tt> if the key did not exists.
061     */
062    Exchange getAndRemove(String key);
063
064    /**
065     * Pushes the exchange on top of the repository.
066     */
067    void push(Exchange exchange);
068
069    /**
070     * Pops the repository and returns the latest. Or returns <tt>null</tt> if the stack is empty.
071     */
072    Exchange pop();
073
074    /**
075     * Clear the repository.
076     */
077    void clear();
078
079}