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 java.util.Set; 020 021import org.apache.camel.CamelContext; 022import org.apache.camel.Exchange; 023 024/** 025 * Access to a repository to store aggregated exchanges to support pluggable implementations. 026 * 027 */ 028public interface AggregationRepository { 029 030 /** 031 * Add the given {@link Exchange} under the correlation key. 032 * <p/> 033 * Will replace any existing exchange. 034 * <p/> 035 * <b>Important:</b> This method is <b>not</b> invoked if only one exchange was completed, and therefore 036 * the exchange does not need to be added to a repository, as its completed immediately. 037 * 038 * @param camelContext the current CamelContext 039 * @param key the correlation key 040 * @param exchange the aggregated exchange 041 * @return the old exchange if any existed 042 */ 043 Exchange add(CamelContext camelContext, String key, Exchange exchange); 044 045 /** 046 * Gets the given exchange with the correlation key 047 * <p/> 048 * This method is always invoked for any incoming exchange in the aggregator. 049 * 050 * @param camelContext the current CamelContext 051 * @param key the correlation key 052 * @return the exchange, or <tt>null</tt> if no exchange was previously added 053 */ 054 Exchange get(CamelContext camelContext, String key); 055 056 /** 057 * Removes the exchange with the given correlation key, which should happen 058 * when an {@link Exchange} is completed 059 * <p/> 060 * <b>Important:</b> This method is <b>not</b> invoked if only one exchange was completed, and therefore 061 * the exchange does not need to be added to a repository, as its completed immediately. 062 * 063 * @param camelContext the current CamelContext 064 * @param key the correlation key 065 * @param exchange the exchange to remove 066 */ 067 void remove(CamelContext camelContext, String key, Exchange exchange); 068 069 /** 070 * Confirms the completion of the {@link Exchange}. 071 * <p/> 072 * This method is always invoked. 073 * 074 * @param camelContext the current CamelContext 075 * @param exchangeId exchange id to confirm 076 */ 077 void confirm(CamelContext camelContext, String exchangeId); 078 079 /** 080 * Gets the keys currently in the repository. 081 * 082 * @return the keys 083 */ 084 Set<String> getKeys(); 085 086}