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.concurrent.Executors;
020 import java.util.concurrent.LinkedBlockingQueue;
021 import java.util.concurrent.ThreadPoolExecutor;
022 import java.util.concurrent.TimeUnit;
023
024 import javax.xml.bind.annotation.XmlAccessType;
025 import javax.xml.bind.annotation.XmlAccessorType;
026 import javax.xml.bind.annotation.XmlAttribute;
027 import javax.xml.bind.annotation.XmlRootElement;
028 import javax.xml.bind.annotation.XmlTransient;
029
030 import org.apache.camel.Expression;
031 import org.apache.camel.Processor;
032 import org.apache.camel.impl.RouteContext;
033 import org.apache.camel.model.language.ExpressionType;
034 import org.apache.camel.processor.Splitter;
035 import org.apache.camel.processor.aggregate.AggregationStrategy;
036 import org.apache.camel.processor.aggregate.UseLatestAggregationStrategy;
037
038 /**
039 * @version $Revision: 36865 $
040 */
041 @XmlRootElement(name = "splitter")
042 @XmlAccessorType(XmlAccessType.FIELD)
043 public class SplitterType extends ExpressionNode {
044 @XmlTransient
045 private AggregationStrategy aggregationStrategy;
046 @XmlAttribute(required = false)
047 private Boolean parallelProcessing;
048 @XmlTransient
049 private ThreadPoolExecutor threadPoolExecutor;
050
051 public SplitterType() {
052 }
053
054 public SplitterType(Expression expression) {
055 super(expression);
056 }
057
058 public SplitterType(ExpressionType expression) {
059 super(expression);
060 }
061
062 @Override
063 public String toString() {
064 return "Splitter[ " + getExpression() + " -> " + getOutputs() + "]";
065 }
066
067 @Override
068 public Processor createProcessor(RouteContext routeContext) throws Exception {
069 Processor childProcessor = routeContext.createProcessor(this);
070 if (aggregationStrategy == null) {
071 aggregationStrategy = new UseLatestAggregationStrategy();
072 }
073 if (threadPoolExecutor == null) {
074 threadPoolExecutor = new ThreadPoolExecutor(4, 16, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue());
075 }
076 return new Splitter(getExpression().createExpression(routeContext), childProcessor, aggregationStrategy,
077 isParallelProcessing(), threadPoolExecutor);
078 }
079
080 public AggregationStrategy getAggregationStrategy() {
081 return aggregationStrategy;
082 }
083
084 public void setAggregationStrategy(AggregationStrategy aggregationStrategy) {
085 this.aggregationStrategy = aggregationStrategy;
086 }
087
088 public boolean isParallelProcessing() {
089 return parallelProcessing != null ? parallelProcessing : false;
090 }
091
092 public void setParallelProcessing(boolean parallelProcessing) {
093 this.parallelProcessing = parallelProcessing;
094 }
095
096 public ThreadPoolExecutor getThreadPoolExecutor() {
097 return threadPoolExecutor;
098 }
099
100 public void setThreadPoolExecutor(ThreadPoolExecutor threadPoolExecutor) {
101 this.threadPoolExecutor = threadPoolExecutor;
102 }
103 }