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