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.model;
018
019 import java.util.List;
020 import java.util.concurrent.ThreadPoolExecutor;
021
022 import javax.xml.bind.annotation.XmlAccessType;
023 import javax.xml.bind.annotation.XmlAccessorType;
024 import javax.xml.bind.annotation.XmlAttribute;
025 import javax.xml.bind.annotation.XmlRootElement;
026 import javax.xml.bind.annotation.XmlTransient;
027
028 import org.apache.camel.Processor;
029 import org.apache.camel.impl.RouteContext;
030 import org.apache.camel.processor.MulticastProcessor;
031 import org.apache.camel.processor.aggregate.AggregationStrategy;
032 import org.apache.camel.processor.aggregate.UseLatestAggregationStrategy;
033
034 /**
035 * @version $Revision: 36321 $
036 */
037 @XmlRootElement(name = "multicast")
038 @XmlAccessorType(XmlAccessType.FIELD)
039 public class MulticastType extends OutputType<ProcessorType> {
040 @XmlAttribute(required = false)
041 private Boolean parallelProcessing;
042 @XmlTransient
043 private AggregationStrategy aggregationStrategy;
044 @XmlTransient
045 private ThreadPoolExecutor threadPoolExecutor;
046
047 @Override
048 public String toString() {
049 return "Multicast[" + getOutputs() + "]";
050 }
051
052 @Override
053 public Processor createProcessor(RouteContext routeContext) throws Exception {
054 return createOutputsProcessor(routeContext);
055 }
056
057 protected Processor createCompositeProcessor(List<Processor> list) {
058 if (aggregationStrategy == null) {
059 aggregationStrategy = new UseLatestAggregationStrategy();
060 }
061 return new MulticastProcessor(list, aggregationStrategy, isParallelProcessing(), threadPoolExecutor);
062 }
063
064 public AggregationStrategy getAggregationStrategy() {
065 return aggregationStrategy;
066 }
067
068 public void setAggregationStrategy(AggregationStrategy aggregationStrategy) {
069 this.aggregationStrategy = aggregationStrategy;
070 }
071
072 public boolean isParallelProcessing() {
073 return parallelProcessing != null ? parallelProcessing : false;
074 }
075
076 public void setParallelProcessing(boolean parallelProcessing) {
077 this.parallelProcessing = parallelProcessing;
078 }
079
080 public ThreadPoolExecutor getThreadPoolExecutor() {
081 return threadPoolExecutor;
082 }
083
084 public void setThreadPoolExecutor(ThreadPoolExecutor executor) {
085 this.threadPoolExecutor = executor;
086
087 }
088 }