// right now, our criteria is simple - if blocking is desired or if core threads can time out, use the queue executor instead
if (metaData.isAllowCoreTimeout() || "block".equals(policyName)) {
// use SimpleQueueExecutor
executorBuilder = BeanMetaDataBuilder.createBuilder(SimpleQueueExecutor.class.getName());
final RejectionPolicy rejectionPolicy;
final ValueMetaData handoffExecutorValue;
if ("abort".equals(policyName)) {
rejectionPolicy = RejectionPolicy.ABORT;
handoffExecutorValue = executorBuilder.createNull();
} else if ("block".equals(policyName)) {
rejectionPolicy = RejectionPolicy.BLOCK;
handoffExecutorValue = executorBuilder.createNull();
} else if ("caller-runs".equals(policyName)) {
rejectionPolicy = RejectionPolicy.HANDOFF;
handoffExecutorValue = executorBuilder.createValue(JBossExecutors.directExecutor());
} else if ("discard".equals(policyName)) {
rejectionPolicy = RejectionPolicy.DISCARD;
handoffExecutorValue = executorBuilder.createNull();
} else if ("discard-oldest".equals(policyName)) {
rejectionPolicy = RejectionPolicy.DISCARD_OLDEST;
handoffExecutorValue = executorBuilder.createNull();
} else if ("handoff".equals(policyName)) {
rejectionPolicy = RejectionPolicy.HANDOFF;
handoffExecutorValue = executorBuilder.createInject(rejectPolicyMetaData.getExecutorName());
} else {
throw new IllegalStateException();
}
final Queue<Runnable> queue;
if (queueLength == null) {
queue = new LinkedList<Runnable>();
} else {
queue = new ArrayQueue<Runnable>(queueLength.intValue());
}
executorBuilder.addConstructorParameter(String.class.getName(), name);
executorBuilder.addConstructorParameter("int", Integer.valueOf(corePoolSize));
executorBuilder.addConstructorParameter("int", Integer.valueOf(maxPoolSize));
executorBuilder.addConstructorParameter("long", Long.valueOf(time));
executorBuilder.addConstructorParameter(TimeUnit.class.getName(), unit);
executorBuilder.addConstructorParameter(Queue.class.getName(), executorBuilder.createValue(queue));
executorBuilder.addConstructorParameter(ThreadFactory.class.getName(), executorBuilder.createInject(threadFactory));
executorBuilder.addConstructorParameter(RejectionPolicy.class.getName(), rejectionPolicy);
executorBuilder.addConstructorParameter(Executor.class.getName(), handoffExecutorValue);
if (metaData.isAllowCoreTimeout()) {
executorBuilder.addPropertyMetaData("allowCoreTimeout", Boolean.TRUE);
}
} else {
// use ThreadPoolExecutor
executorBuilder = BeanMetaDataBuilder.createBuilder(JBossThreadPoolExecutor.class.getName());
final ValueMetaData policyValue;
if ("abort".equals(policyName)) {
policyValue = executorBuilder.createValue(JBossExecutors.abortPolicy());
} else if ("block".equals(policyName)) {
throw new IllegalStateException();
} else if ("caller-runs".equals(policyName)) {