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.impl;
018
019import java.util.ArrayDeque;
020import java.util.Deque;
021import java.util.HashMap;
022import java.util.Map;
023
024import org.apache.camel.Exchange;
025import org.apache.camel.spi.ClaimCheckRepository;
026
027/**
028 * The default {@link ClaimCheckRepository} implementation that is an in-memory storage.
029 */
030public class DefaultClaimCheckRepository implements ClaimCheckRepository {
031
032    private final Map<String, Exchange> map = new HashMap<>();
033    private final Deque<Exchange> stack = new ArrayDeque<>();
034
035    @Override
036    public boolean add(String key, Exchange exchange) {
037        return map.put(key, exchange) == null;
038    }
039
040    @Override
041    public boolean contains(String key) {
042        return map.containsKey(key);
043    }
044
045    @Override
046    public Exchange get(String key) {
047        return map.get(key);
048    }
049
050    @Override
051    public Exchange getAndRemove(String key) {
052        return map.remove(key);
053    }
054
055    @Override
056    public void push(Exchange exchange) {
057        stack.push(exchange);
058    }
059
060    @Override
061    public Exchange pop() {
062        if (!stack.isEmpty()) {
063            return stack.pop();
064        } else {
065            return null;
066        }
067    }
068
069    @Override
070    public void clear() {
071        map.clear();
072        stack.clear();
073    }
074
075    @Override
076    public void start() throws Exception {
077        // noop
078    }
079
080    @Override
081    public void stop() throws Exception {
082        // noop
083    }
084}