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;
018
019 import org.apache.camel.Endpoint;
020 import org.apache.camel.Expression;
021 import org.apache.camel.Processor;
022 import org.apache.camel.processor.aggregate.AggregationCollection;
023 import org.apache.camel.processor.aggregate.AggregationStrategy;
024
025 /**
026 * An implementation of the <a
027 * href="http://activemq.apache.org/camel/aggregator.html">Aggregator</a>
028 * pattern where a batch of messages are processed (up to a maximum amount or
029 * until some timeout is reached) and messages for the same correlation key are
030 * combined together using some kind of
031 * {@link AggregationStrategy ) (by default the latest message is used) to compress
032 * many message exchanges * into a smaller number of exchanges. <p/> A good
033 * example of this is stock market data; you may be receiving 30,000
034 * messages/second and you may want to throttle it right down so that multiple
035 * messages for the same stock are combined (or just the latest message is used
036 * and older prices are discarded). Another idea is to combine line item
037 * messages together into a single invoice message.
038 *
039 * @version $Revision: 1.1 $
040 * @param correlationExpression the expression used to calculate the correlation
041 * key. For a JMS message this could be the expression
042 * <code>header("JMSDestination")</code> or
043 * <code>header("JMSCorrelationID")</code>
044 */
045 public class Aggregator extends BatchProcessor {
046 public Aggregator(Endpoint endpoint, Processor processor, Expression correlationExpression,
047 AggregationStrategy aggregationStrategy) {
048 this(endpoint, processor, new AggregationCollection(correlationExpression, aggregationStrategy));
049 }
050
051 public Aggregator(Endpoint endpoint, Processor processor, AggregationCollection collection) {
052 super(endpoint, processor, collection);
053 }
054
055 @Override
056 public String toString() {
057 return "Aggregator[to: " + getProcessor() + "]";
058 }
059 }