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.processor.aggregate; 018 019 import java.util.Collections; 020 import java.util.Map; 021 import java.util.Set; 022 import java.util.concurrent.ConcurrentHashMap; 023 024 import org.apache.camel.CamelContext; 025 import org.apache.camel.Exchange; 026 import org.apache.camel.spi.AggregationRepository; 027 import org.apache.camel.support.ServiceSupport; 028 029 /** 030 * A memory based {@link org.apache.camel.spi.AggregationRepository} which stores in memory only. 031 * 032 * @version 033 */ 034 public class MemoryAggregationRepository extends ServiceSupport implements AggregationRepository { 035 private final Map<String, Exchange> cache = new ConcurrentHashMap<String, Exchange>(); 036 037 public Exchange add(CamelContext camelContext, String key, Exchange exchange) { 038 return cache.put(key, exchange); 039 } 040 041 public Exchange get(CamelContext camelContext, String key) { 042 return cache.get(key); 043 } 044 045 public void remove(CamelContext camelContext, String key, Exchange exchange) { 046 cache.remove(key); 047 } 048 049 public void confirm(CamelContext camelContext, String exchangeId) { 050 // noop 051 } 052 053 public Set<String> getKeys() { 054 // do not allow edits to the set 055 return Collections.unmodifiableSet(cache.keySet()); 056 } 057 058 @Override 059 protected void doStart() throws Exception { 060 } 061 062 @Override 063 protected void doStop() throws Exception { 064 cache.clear(); 065 } 066 067 }