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.processor.MulticastProcessor; 030 import org.apache.camel.processor.aggregate.AggregationStrategy; 031 import org.apache.camel.processor.aggregate.UseLatestAggregationStrategy; 032 import org.apache.camel.processor.interceptor.StreamCachingInterceptor; 033 import org.apache.camel.spi.RouteContext; 034 035 /** 036 * Represents an XML <multicast/> element 037 * 038 * @version $Revision: 671918 $ 039 */ 040 @XmlRootElement(name = "multicast") 041 @XmlAccessorType(XmlAccessType.FIELD) 042 public class MulticastType extends OutputType<ProcessorType> { 043 @XmlAttribute(required = false) 044 private Boolean parallelProcessing; 045 @XmlTransient 046 private AggregationStrategy aggregationStrategy; 047 @XmlTransient 048 private ThreadPoolExecutor threadPoolExecutor; 049 050 @Override 051 public String toString() { 052 return "Multicast[" + getOutputs() + "]"; 053 } 054 055 @Override 056 public String getShortName() { 057 return "multicast"; 058 } 059 060 @Override 061 public Processor createProcessor(RouteContext routeContext) throws Exception { 062 return createOutputsProcessor(routeContext); 063 } 064 065 protected Processor createCompositeProcessor(List<Processor> list) { 066 if (aggregationStrategy == null) { 067 aggregationStrategy = new UseLatestAggregationStrategy(); 068 } 069 return new MulticastProcessor(list, aggregationStrategy, isParallelProcessing(), threadPoolExecutor); 070 } 071 072 public AggregationStrategy getAggregationStrategy() { 073 return aggregationStrategy; 074 } 075 076 public MulticastType setAggregationStrategy(AggregationStrategy aggregationStrategy) { 077 this.aggregationStrategy = aggregationStrategy; 078 return this; 079 } 080 081 public boolean isParallelProcessing() { 082 return parallelProcessing != null ? parallelProcessing : false; 083 } 084 085 public MulticastType setParallelProcessing(boolean parallelProcessing) { 086 this.parallelProcessing = parallelProcessing; 087 return this; 088 } 089 090 public ThreadPoolExecutor getThreadPoolExecutor() { 091 return threadPoolExecutor; 092 } 093 094 public MulticastType setThreadPoolExecutor(ThreadPoolExecutor executor) { 095 this.threadPoolExecutor = executor; 096 return this; 097 } 098 099 @Override 100 protected Processor wrapProcessorInInterceptors(RouteContext routeContext, Processor target) throws Exception { 101 // No need to wrap me in interceptors as they are all applied directly to my children 102 return new StreamCachingInterceptor(target); 103 } 104 }