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.model; 018 019import java.util.concurrent.TimeUnit; 020 021import javax.xml.bind.annotation.XmlAccessType; 022import javax.xml.bind.annotation.XmlAccessorType; 023import javax.xml.bind.annotation.XmlAttribute; 024import javax.xml.bind.annotation.XmlRootElement; 025 026import org.apache.camel.spi.Metadata; 027import org.apache.camel.util.concurrent.ThreadPoolRejectedPolicy; 028 029/** 030 * To configure thread pools 031 */ 032@Metadata(label = "configuration") 033@XmlRootElement(name = "threadPoolProfile") 034@XmlAccessorType(XmlAccessType.FIELD) 035public class ThreadPoolProfileDefinition extends OptionalIdentifiedDefinition<ThreadPoolProfileDefinition> { 036 @XmlAttribute 037 @Metadata(javaType = "java.lang.Boolean") 038 private String defaultProfile; 039 @XmlAttribute 040 @Metadata(javaType = "java.lang.Integer") 041 private String poolSize; 042 @XmlAttribute 043 @Metadata(javaType = "java.lang.Integer") 044 private String maxPoolSize; 045 @XmlAttribute 046 @Metadata(javaType = "java.lang.Long") 047 private String keepAliveTime; 048 @XmlAttribute 049 @Metadata(javaType = "java.util.concurrent.TimeUnit", 050 enums = "NANOSECONDS,MICROSECONDS,MILLISECONDS,SECONDS,MINUTES,HOURS,DAYS") 051 private String timeUnit; 052 @XmlAttribute 053 @Metadata(javaType = "java.lang.Integer") 054 private String maxQueueSize; 055 @XmlAttribute 056 @Metadata(javaType = "java.lang.Boolean") 057 private String allowCoreThreadTimeOut; 058 @XmlAttribute 059 @Metadata(javaType = "org.apache.camel.util.concurrent.ThreadPoolRejectedPolicy") 060 private String rejectedPolicy; 061 062 public ThreadPoolProfileDefinition() { 063 } 064 065 @Override 066 public String getShortName() { 067 return "threadPoolProfile"; 068 } 069 070 @Override 071 public String getLabel() { 072 return "ThreadPoolProfile " + getId(); 073 } 074 075 public ThreadPoolProfileDefinition poolSize(int poolSize) { 076 return poolSize(Integer.toString(poolSize)); 077 } 078 079 public ThreadPoolProfileDefinition poolSize(String poolSize) { 080 setPoolSize(poolSize); 081 return this; 082 } 083 084 public ThreadPoolProfileDefinition maxPoolSize(int maxPoolSize) { 085 return maxPoolSize(Integer.toString(maxPoolSize)); 086 } 087 088 public ThreadPoolProfileDefinition maxPoolSize(String maxPoolSize) { 089 setMaxPoolSize(maxPoolSize); 090 return this; 091 } 092 093 public ThreadPoolProfileDefinition keepAliveTime(long keepAliveTime) { 094 return keepAliveTime(Long.toString(keepAliveTime)); 095 } 096 097 public ThreadPoolProfileDefinition keepAliveTime(String keepAliveTime) { 098 setKeepAliveTime(keepAliveTime); 099 return this; 100 } 101 102 public ThreadPoolProfileDefinition timeUnit(TimeUnit timeUnit) { 103 return timeUnit(timeUnit.name()); 104 } 105 106 public ThreadPoolProfileDefinition timeUnit(String timeUnit) { 107 setTimeUnit(timeUnit); 108 return this; 109 } 110 111 public ThreadPoolProfileDefinition maxQueueSize(int maxQueueSize) { 112 return maxQueueSize(Integer.toString(maxQueueSize)); 113 } 114 115 public ThreadPoolProfileDefinition maxQueueSize(String maxQueueSize) { 116 setMaxQueueSize(maxQueueSize); 117 return this; 118 } 119 120 public ThreadPoolProfileDefinition rejectedPolicy(ThreadPoolRejectedPolicy rejectedPolicy) { 121 setRejectedPolicy(rejectedPolicy.name()); 122 return this; 123 } 124 125 public ThreadPoolProfileDefinition rejectedPolicy(String rejectedPolicy) { 126 setRejectedPolicy(rejectedPolicy); 127 return this; 128 } 129 130 public ThreadPoolProfileDefinition allowCoreThreadTimeOut(boolean allowCoreThreadTimeOut) { 131 return allowCoreThreadTimeOut(Boolean.toString(allowCoreThreadTimeOut)); 132 } 133 134 public ThreadPoolProfileDefinition allowCoreThreadTimeOut(String allowCoreThreadTimeOut) { 135 setAllowCoreThreadTimeOut(allowCoreThreadTimeOut); 136 return this; 137 } 138 139 public String getDefaultProfile() { 140 return defaultProfile; 141 } 142 143 /** 144 * Whether this profile is the default thread pool profile 145 */ 146 public void setDefaultProfile(String defaultProfile) { 147 this.defaultProfile = defaultProfile; 148 } 149 150 public String getPoolSize() { 151 return poolSize; 152 } 153 154 /** 155 * Sets the core pool size 156 */ 157 public void setPoolSize(String poolSize) { 158 this.poolSize = poolSize; 159 } 160 161 public String getMaxPoolSize() { 162 return maxPoolSize; 163 } 164 165 /** 166 * Sets the maximum pool size 167 */ 168 public void setMaxPoolSize(String maxPoolSize) { 169 this.maxPoolSize = maxPoolSize; 170 } 171 172 public String getKeepAliveTime() { 173 return keepAliveTime; 174 } 175 176 /** 177 * Sets the keep alive time for idle threads in the pool 178 */ 179 public void setKeepAliveTime(String keepAliveTime) { 180 this.keepAliveTime = keepAliveTime; 181 } 182 183 public String getMaxQueueSize() { 184 return maxQueueSize; 185 } 186 187 /** 188 * Sets the maximum number of tasks in the work queue. 189 * <p/> 190 * Use <tt>-1</tt> or <tt>Integer.MAX_VALUE</tt> for an unbounded queue 191 */ 192 public void setMaxQueueSize(String maxQueueSize) { 193 this.maxQueueSize = maxQueueSize; 194 } 195 196 public String getAllowCoreThreadTimeOut() { 197 return allowCoreThreadTimeOut; 198 } 199 200 /** 201 * Whether idle core threads is allowed to timeout and therefore can shrink 202 * the pool size below the core pool size 203 * <p/> 204 * Is by default <tt>true</tt> 205 */ 206 public void setAllowCoreThreadTimeOut(String allowCoreThreadTimeOut) { 207 this.allowCoreThreadTimeOut = allowCoreThreadTimeOut; 208 } 209 210 public String getTimeUnit() { 211 return timeUnit; 212 } 213 214 /** 215 * Sets the time unit to use for keep alive time By default SECONDS is used. 216 */ 217 public void setTimeUnit(String timeUnit) { 218 this.timeUnit = timeUnit; 219 } 220 221 public String getRejectedPolicy() { 222 return rejectedPolicy; 223 } 224 225 /** 226 * Sets the handler for tasks which cannot be executed by the thread pool. 227 */ 228 public void setRejectedPolicy(String rejectedPolicy) { 229 this.rejectedPolicy = rejectedPolicy; 230 } 231 232}