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 */
017package org.apache.camel.builder;
018
019import java.util.concurrent.TimeUnit;
020
021import org.apache.camel.ThreadPoolRejectedPolicy;
022import org.apache.camel.spi.ThreadPoolProfile;
023
024/**
025 * Builder to build {@link org.apache.camel.spi.ThreadPoolProfile}.
026 * <p/>
027 * Use the {@link #build()} method when done setting up the profile.
028 */
029public class ThreadPoolProfileBuilder {
030    private final ThreadPoolProfile profile;
031
032    public ThreadPoolProfileBuilder(String id) {
033        this.profile = new ThreadPoolProfile(id);
034    }
035
036    public ThreadPoolProfileBuilder(String id, ThreadPoolProfile origProfile) {
037        this.profile = origProfile.clone();
038        this.profile.setId(id);
039    }
040    
041    public ThreadPoolProfileBuilder defaultProfile(Boolean defaultProfile) {
042        this.profile.setDefaultProfile(defaultProfile);
043        return this;
044    }
045
046
047    public ThreadPoolProfileBuilder poolSize(Integer poolSize) {
048        profile.setPoolSize(poolSize);
049        return this;
050    }
051
052    public ThreadPoolProfileBuilder maxPoolSize(Integer maxPoolSize) {
053        profile.setMaxPoolSize(maxPoolSize);
054        return this;
055    }
056
057    public ThreadPoolProfileBuilder keepAliveTime(Long keepAliveTime, TimeUnit timeUnit) {
058        profile.setKeepAliveTime(keepAliveTime);
059        profile.setTimeUnit(timeUnit);
060        return this;
061    }
062
063    public ThreadPoolProfileBuilder keepAliveTime(Long keepAliveTime) {
064        profile.setKeepAliveTime(keepAliveTime);
065        return this;
066    }
067    
068    public ThreadPoolProfileBuilder maxQueueSize(Integer maxQueueSize) {
069        if (maxQueueSize != null) {
070            profile.setMaxQueueSize(maxQueueSize);
071        }
072        return this;
073    }
074
075    public ThreadPoolProfileBuilder rejectedPolicy(ThreadPoolRejectedPolicy rejectedPolicy) {
076        profile.setRejectedPolicy(rejectedPolicy);
077        return this;
078    }
079
080    /**
081     * Builds the new thread pool
082     * 
083     * @return the created thread pool
084     * @throws Exception is thrown if error building the thread pool
085     */
086    public ThreadPoolProfile build() {
087        return profile;
088    }
089
090
091}