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