static final OperationHandler INSTANCE = new UnboundedQueueThreadPoolAdd();
@Override
public OperationResult execute(final OperationContext context, final ModelNode operation, final ResultHandler resultHandler) {
final BaseOperationParameters params = ThreadsSubsystemThreadPoolOperationUtils.parseUnboundedQueueThreadPoolOperationParameters(operation);
//Apply to the model
final ModelNode model = context.getSubModel();
model.get(NAME).set(params.getName());
if (params.getThreadFactory() != null) {
model.get(THREAD_FACTORY).set(params.getThreadFactory());
}
if (params.getProperties() != null && params.getProperties().asList().size() > 0) {
model.get(PROPERTIES).set(params.getProperties());
}
if (params.getMaxThreads() != null) {
model.get(MAX_THREADS).set(operation.get(MAX_THREADS));
}
if (params.getKeepAliveTime() != null) {
model.get(KEEPALIVE_TIME).set(operation.get(KEEPALIVE_TIME));
}
if (context.getRuntimeContext() != null) {
context.getRuntimeContext().setRuntimeTask(new RuntimeTask() {
public void execute(RuntimeTaskContext context) throws OperationFailedException {
ServiceTarget target = context.getServiceTarget();
final ServiceName serviceName = ThreadsServices.executorName(params.getName());
final UnboundedQueueThreadPoolService service = new UnboundedQueueThreadPoolService(params.getMaxThreads().getScaledCount(), params.getKeepAliveTime());
final ServiceBuilder<ExecutorService> serviceBuilder = target.addService(serviceName, service);
ThreadsSubsystemThreadPoolOperationUtils.addThreadFactoryDependency(params.getThreadFactory(), serviceName, serviceBuilder, service.getThreadFactoryInjector(), target, params.getName() + "-threads");
serviceBuilder.install();
resultHandler.handleResultComplete();
}
});
} else {
resultHandler.handleResultComplete();
}
// Compensating is remove
final ModelNode compensating = Util.getResourceRemoveOperation(params.getAddress());
return new BasicOperationResult(compensating);
}