Search in sources :

Example 1 with StrictMaxPoolConfigService

use of org.jboss.as.ejb3.component.pool.StrictMaxPoolConfigService in project wildfly by wildfly.

the class StrictMaxPoolAdd method installRuntimeService.

ServiceController<PoolConfig> installRuntimeService(OperationContext context, ModelNode operation, ModelNode strictMaxPoolModel, ServiceVerificationHandler verificationHandler) throws OperationFailedException {
    final String poolName = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.ADDRESS)).getLastElement().getValue();
    final int maxPoolSize = StrictMaxPoolResourceDefinition.MAX_POOL_SIZE.resolveModelAttribute(context, strictMaxPoolModel).asInt();
    final Derive derive = StrictMaxPoolResourceDefinition.parseDeriveSize(context, strictMaxPoolModel);
    final long timeout = StrictMaxPoolResourceDefinition.INSTANCE_ACQUISITION_TIMEOUT.resolveModelAttribute(context, strictMaxPoolModel).asLong();
    final String unit = StrictMaxPoolResourceDefinition.INSTANCE_ACQUISITION_TIMEOUT_UNIT.resolveModelAttribute(context, strictMaxPoolModel).asString();
    // create and install the service
    final StrictMaxPoolConfigService poolConfigService = new StrictMaxPoolConfigService(poolName, maxPoolSize, derive, timeout, TimeUnit.valueOf(unit));
    final ServiceName serviceName = StrictMaxPoolConfigService.EJB_POOL_CONFIG_BASE_SERVICE_NAME.append(poolName);
    ServiceBuilder<PoolConfig> svcBuilder = context.getServiceTarget().addService(serviceName, poolConfigService);
    if (verificationHandler != null) {
        svcBuilder.addListener(verificationHandler);
    }
    if (context.hasOptionalCapability(IO_MAX_THREADS_RUNTIME_CAPABILITY_NAME, null, null)) {
        ServiceName name = context.getCapabilityServiceName(IO_MAX_THREADS_RUNTIME_CAPABILITY_NAME, Integer.class);
        svcBuilder.addDependency(name, Integer.class, poolConfigService.getMaxThreadsInjector());
    }
    return svcBuilder.install();
}
Also used : ServiceName(org.jboss.msc.service.ServiceName) Derive(org.jboss.as.ejb3.component.pool.StrictMaxPoolConfigService.Derive) PoolConfig(org.jboss.as.ejb3.component.pool.PoolConfig) StrictMaxPoolConfigService(org.jboss.as.ejb3.component.pool.StrictMaxPoolConfigService)

Example 2 with StrictMaxPoolConfigService

use of org.jboss.as.ejb3.component.pool.StrictMaxPoolConfigService in project wildfly by wildfly.

the class StrictMaxPoolDerivedSizeReadHandler method executeRuntimeStep.

@Override
protected void executeRuntimeStep(final OperationContext context, final ModelNode operation) throws OperationFailedException {
    final String poolName = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)).getLastElement().getValue();
    ServiceName serviceName = context.getCapabilityServiceName(StrictMaxPoolResourceDefinition.STRICT_MAX_POOL_CONFIG_CAPABILITY_NAME, poolName, StrictMaxPoolConfigService.class);
    final ServiceRegistry registry = context.getServiceRegistry(true);
    ServiceController<?> sc = registry.getService(serviceName);
    if (sc != null) {
        StrictMaxPoolConfigService smpc = (StrictMaxPoolConfigService) sc.getService();
        if (smpc != null) {
            context.getResult().set(smpc.getDerivedSize());
            return;
        }
    }
    throw EjbLogger.ROOT_LOGGER.cannotReadStrictMaxPoolDerivedSize(serviceName);
}
Also used : ServiceName(org.jboss.msc.service.ServiceName) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) StrictMaxPoolConfigService(org.jboss.as.ejb3.component.pool.StrictMaxPoolConfigService)

Example 3 with StrictMaxPoolConfigService

use of org.jboss.as.ejb3.component.pool.StrictMaxPoolConfigService in project wildfly by wildfly.

the class StrictMaxPoolWriteHandler method applyModelToRuntime.

private void applyModelToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode model) throws OperationFailedException {
    final String poolName = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)).getLastElement().getValue();
    ServiceName serviceName = context.getCapabilityServiceName(StrictMaxPoolResourceDefinition.STRICT_MAX_POOL_CONFIG_CAPABILITY_NAME, poolName, StrictMaxPoolConfigService.class);
    final ServiceRegistry registry = context.getServiceRegistry(true);
    ServiceController<?> sc = registry.getService(serviceName);
    if (sc != null) {
        StrictMaxPoolConfigService smpc = (StrictMaxPoolConfigService) sc.getService();
        if (smpc != null) {
            if (StrictMaxPoolResourceDefinition.MAX_POOL_SIZE.getName().equals(attributeName)) {
                int maxPoolSize = StrictMaxPoolResourceDefinition.MAX_POOL_SIZE.resolveModelAttribute(context, model).asInt(-1);
                smpc.setMaxPoolSize(maxPoolSize);
            } else if (StrictMaxPoolResourceDefinition.DERIVE_SIZE.getName().equals(attributeName)) {
                StrictMaxPoolConfigService.Derive derive = StrictMaxPoolResourceDefinition.parseDeriveSize(context, model);
                smpc.setDerive(derive);
            } else if (StrictMaxPoolResourceDefinition.INSTANCE_ACQUISITION_TIMEOUT.getName().equals(attributeName)) {
                long timeout = StrictMaxPoolResourceDefinition.INSTANCE_ACQUISITION_TIMEOUT.resolveModelAttribute(context, model).asLong();
                smpc.setTimeout(timeout);
            } else if (StrictMaxPoolResourceDefinition.INSTANCE_ACQUISITION_TIMEOUT_UNIT.getName().equals(attributeName)) {
                String timeoutUnit = StrictMaxPoolResourceDefinition.INSTANCE_ACQUISITION_TIMEOUT_UNIT.resolveModelAttribute(context, model).asString();
                smpc.setTimeoutUnit(TimeUnit.valueOf(timeoutUnit));
            }
        }
    }
}
Also used : ServiceName(org.jboss.msc.service.ServiceName) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) StrictMaxPoolConfigService(org.jboss.as.ejb3.component.pool.StrictMaxPoolConfigService)

Example 4 with StrictMaxPoolConfigService

use of org.jboss.as.ejb3.component.pool.StrictMaxPoolConfigService in project wildfly by wildfly.

the class StrictMaxPoolAdd method performRuntime.

@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode strictMaxPoolModel) throws OperationFailedException {
    final String poolName = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.ADDRESS)).getLastElement().getValue();
    final int maxPoolSize = StrictMaxPoolResourceDefinition.MAX_POOL_SIZE.resolveModelAttribute(context, strictMaxPoolModel).asInt();
    final Derive derive = StrictMaxPoolResourceDefinition.parseDeriveSize(context, strictMaxPoolModel);
    final long timeout = StrictMaxPoolResourceDefinition.INSTANCE_ACQUISITION_TIMEOUT.resolveModelAttribute(context, strictMaxPoolModel).asLong();
    final String unit = StrictMaxPoolResourceDefinition.INSTANCE_ACQUISITION_TIMEOUT_UNIT.resolveModelAttribute(context, strictMaxPoolModel).asString();
    // create and install the service
    final StrictMaxPoolConfigService poolConfigService = new StrictMaxPoolConfigService(poolName, maxPoolSize, derive, timeout, TimeUnit.valueOf(unit));
    CapabilityServiceTarget capabilityServiceTarget = context.getCapabilityServiceTarget();
    CapabilityServiceBuilder<StrictMaxPoolConfig> capabilityServiceBuilder = capabilityServiceTarget.addCapability(StrictMaxPoolResourceDefinition.STRICT_MAX_POOL_CONFIG_CAPABILITY, poolConfigService);
    if (context.hasOptionalCapability(IO_MAX_THREADS_RUNTIME_CAPABILITY_NAME, null, null)) {
        capabilityServiceBuilder.addCapabilityRequirement(IO_MAX_THREADS_RUNTIME_CAPABILITY_NAME, Integer.class, poolConfigService.getMaxThreadsInjector());
    }
    capabilityServiceBuilder.install();
}
Also used : StrictMaxPoolConfig(org.jboss.as.ejb3.component.pool.StrictMaxPoolConfig) Derive(org.jboss.as.ejb3.component.pool.StrictMaxPoolConfigService.Derive) StrictMaxPoolConfigService(org.jboss.as.ejb3.component.pool.StrictMaxPoolConfigService) CapabilityServiceTarget(org.jboss.as.controller.CapabilityServiceTarget)

Aggregations

StrictMaxPoolConfigService (org.jboss.as.ejb3.component.pool.StrictMaxPoolConfigService)4 ServiceName (org.jboss.msc.service.ServiceName)3 Derive (org.jboss.as.ejb3.component.pool.StrictMaxPoolConfigService.Derive)2 ServiceRegistry (org.jboss.msc.service.ServiceRegistry)2 CapabilityServiceTarget (org.jboss.as.controller.CapabilityServiceTarget)1 PoolConfig (org.jboss.as.ejb3.component.pool.PoolConfig)1 StrictMaxPoolConfig (org.jboss.as.ejb3.component.pool.StrictMaxPoolConfig)1