/**
* {@inheritDoc}
*/
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
final BoundedOperationParameters params = ThreadsSubsystemThreadPoolOperationUtils.parseBoundedThreadPoolOperationParameters(operation);
final PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
final String name = address.getLastElement().getValue();
//Apply to the model
final ModelNode model = context.readModelForUpdate(PathAddress.EMPTY_ADDRESS);
model.get(NAME).set(name);
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));
}
model.get(BLOCKING).set(params.isBlocking());
if (params.getHandoffExecutor() != null) {
model.get(HANDOFF_EXECUTOR).set(params.getHandoffExecutor());
}
model.get(ALLOW_CORE_TIMEOUT).set(params.isAllowCoreTimeout());
if (params.getQueueLength() != null) {
model.get(QUEUE_LENGTH).set(operation.get(QUEUE_LENGTH));
} else {
throw new OperationFailedException(new ModelNode().set("Parameter " + QUEUE_LENGTH + " may not be null."));
}
if (params.getCoreThreads() != null) {
model.get(CORE_THREADS).set(operation.get(CORE_THREADS));
}
if (context.getType() == OperationContext.Type.SERVER) {
context.addStep(new OperationStepHandler() {
public void execute(OperationContext context, ModelNode operation) {
final ServiceVerificationHandler verificationHandler = new ServiceVerificationHandler();
ServiceTarget target = context.getServiceTarget();
final int coreThreads = params.getCoreThreads() == null ? params.getMaxThreads().getScaledCount() : params.getCoreThreads().getScaledCount();
final ServiceName serviceName = ThreadsServices.executorName(params.getName());
final BoundedQueueThreadPoolService service = new BoundedQueueThreadPoolService(
coreThreads,
params.getMaxThreads().getScaledCount(),
params.getQueueLength().getScaledCount(),
params.isBlocking(),
params.getKeepAliveTime(),
params.isAllowCoreTimeout());
//TODO add the handoffExceutor injection
final ServiceBuilder<ExecutorService> serviceBuilder = target.addService(serviceName, service);
ThreadsSubsystemThreadPoolOperationUtils.addThreadFactoryDependency(params.getThreadFactory(), serviceName, serviceBuilder, service.getThreadFactoryInjector(), target, params.getName() + "-threads");
serviceBuilder.addListener(verificationHandler);
serviceBuilder.install();
context.addStep(verificationHandler, OperationContext.Stage.VERIFY);