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 allowCoreThreadTimeOut(Boolean allowCoreThreadTimeOut) { 076 profile.setAllowCoreThreadTimeOut(allowCoreThreadTimeOut); 077 return this; 078 } 079 080 public ThreadPoolProfileBuilder rejectedPolicy(ThreadPoolRejectedPolicy rejectedPolicy) { 081 profile.setRejectedPolicy(rejectedPolicy); 082 return this; 083 } 084 085 /** 086 * Builds the thread pool profile 087 * 088 * @return the thread pool profile 089 */ 090 public ThreadPoolProfile build() { 091 return profile; 092 } 093 094}