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.impl;
018
019 import java.util.ArrayList;
020 import java.util.List;
021
022 import org.apache.camel.CamelContext;
023 import org.apache.camel.Endpoint;
024 import org.apache.camel.Exchange;
025 import org.apache.camel.ExchangePattern;
026
027
028 /**
029 * A grouped exchange that groups together other exchanges, as a holder object.
030 * <p/>
031 * This grouped exchange is useable for the aggregator so multiple exchanges can be grouped
032 * into this single exchange and thus only one exchange is sent for further processing.
033 */
034 public class GroupedExchange extends DefaultExchange {
035
036 private List<Exchange> exchanges = new ArrayList<Exchange>();
037
038 public GroupedExchange(CamelContext context) {
039 super(context);
040 }
041
042 public GroupedExchange(CamelContext context, ExchangePattern pattern) {
043 super(context, pattern);
044 }
045
046 public GroupedExchange(Exchange parent) {
047 super(parent);
048 }
049
050 public GroupedExchange(Endpoint fromEndpoint) {
051 super(fromEndpoint);
052 }
053
054 public GroupedExchange(Endpoint fromEndpoint, ExchangePattern pattern) {
055 super(fromEndpoint, pattern);
056 }
057
058 public List<Exchange> getExchanges() {
059 return exchanges;
060 }
061
062 public void setExchanges(List<Exchange> exchanges) {
063 this.exchanges = exchanges;
064 }
065
066 public void addExchange(Exchange exchange) {
067 this.exchanges.add(exchange);
068 }
069
070 public int size() {
071 return exchanges.size();
072 }
073
074 public Exchange get(int index) {
075 return exchanges.get(index);
076 }
077
078 @Override
079 public String toString() {
080 return "Exchange[Grouped with: " + exchanges.size() + " exchanges]";
081 }
082
083 }