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.spi.ThreadPoolProfile;
022import org.apache.camel.util.concurrent.ThreadPoolRejectedPolicy;
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    public ThreadPoolProfileBuilder poolSize(Integer poolSize) {
047        profile.setPoolSize(poolSize);
048        return this;
049    }
050
051    public ThreadPoolProfileBuilder maxPoolSize(Integer maxPoolSize) {
052        profile.setMaxPoolSize(maxPoolSize);
053        return this;
054    }
055
056    public ThreadPoolProfileBuilder keepAliveTime(Long keepAliveTime, TimeUnit timeUnit) {
057        profile.setKeepAliveTime(keepAliveTime);
058        profile.setTimeUnit(timeUnit);
059        return this;
060    }
061
062    public ThreadPoolProfileBuilder keepAliveTime(Long keepAliveTime) {
063        profile.setKeepAliveTime(keepAliveTime);
064        return this;
065    }
066
067    public ThreadPoolProfileBuilder maxQueueSize(Integer maxQueueSize) {
068        if (maxQueueSize != null) {
069            profile.setMaxQueueSize(maxQueueSize);
070        }
071        return this;
072    }
073
074    public ThreadPoolProfileBuilder allowCoreThreadTimeOut(Boolean allowCoreThreadTimeOut) {
075        profile.setAllowCoreThreadTimeOut(allowCoreThreadTimeOut);
076        return this;
077    }
078
079    public ThreadPoolProfileBuilder rejectedPolicy(ThreadPoolRejectedPolicy rejectedPolicy) {
080        profile.setRejectedPolicy(rejectedPolicy);
081        return this;
082    }
083
084    /**
085     * Builds the thread pool profile
086     * 
087     * @return the thread pool profile
088     */
089    public ThreadPoolProfile build() {
090        return profile;
091    }
092
093}