Java Code Examples for org.jboss.msc.service.ServiceController#getService()

The following examples show how to use org.jboss.msc.service.ServiceController#getService() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CredentialStoreResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
protected void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException {
    ServiceName credentialStoreServiceName = CREDENTIAL_STORE_UTIL.serviceName(operation);
    ServiceController<?> credentialStoreServiceController = context.getServiceRegistry(writeAccess).getRequiredService(credentialStoreServiceName);
    State serviceState;
    if ((serviceState = credentialStoreServiceController.getState()) != State.UP) {
        if (serviceMustBeUp) {
            try {
                // give it another chance to wait at most 500 mill-seconds
                credentialStoreServiceController.awaitValue(500, TimeUnit.MILLISECONDS);
            } catch (InterruptedException | IllegalStateException | TimeoutException e) {
                throw ROOT_LOGGER.requiredServiceNotUp(credentialStoreServiceName, credentialStoreServiceController.getState());
            }
        }
        serviceState = credentialStoreServiceController.getState();
        if (serviceState != State.UP) {
            if (serviceMustBeUp) {
                throw ROOT_LOGGER.requiredServiceNotUp(credentialStoreServiceName, serviceState);
            }
            return;
        }
    }
    CredentialStoreService service = (CredentialStoreService) credentialStoreServiceController.getService();
    performRuntime(context.getResult(), context, operation, service);
}
 
Example 2
Source File: QueuelessThreadPoolWriteAttributeHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
protected void applyOperation(final OperationContext context, ModelNode model, String attributeName,
                              ServiceController<?> service, boolean forRollback) throws OperationFailedException {

    final QueuelessThreadPoolService pool =  (QueuelessThreadPoolService) service.getService();

    if (PoolAttributeDefinitions.KEEPALIVE_TIME.getName().equals(attributeName)) {
        TimeUnit defaultUnit = pool.getKeepAliveUnit();
        final TimeSpec spec = getTimeSpec(context, model, defaultUnit);
        pool.setKeepAlive(spec);
    } else if(PoolAttributeDefinitions.MAX_THREADS.getName().equals(attributeName)) {
        pool.setMaxThreads(PoolAttributeDefinitions.MAX_THREADS.resolveModelAttribute(context, model).asInt());
    } else if (!forRollback) {
        // Programming bug. Throw a RuntimeException, not OFE, as this is not a client error
        throw ThreadsLogger.ROOT_LOGGER.unsupportedQueuelessThreadPoolAttribute(attributeName);
    }
}
 
Example 3
Source File: EnhancedQueueExecutorWriteAttributeHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
protected void applyOperation(final OperationContext context, ModelNode model, String attributeName,
                              ServiceController<?> service, boolean forRollback) throws OperationFailedException {

    final EnhancedQueueExecutorService pool = (EnhancedQueueExecutorService) service.getService();

    if (PoolAttributeDefinitions.KEEPALIVE_TIME.getName().equals(attributeName)) {
        TimeUnit defaultUnit = pool.getKeepAliveUnit();
        final TimeSpec spec = getTimeSpec(context, model, defaultUnit);
        pool.setKeepAlive(spec);
    } else if (PoolAttributeDefinitions.MAX_THREADS.getName().equals(attributeName)) {
        pool.setMaxThreads(PoolAttributeDefinitions.MAX_THREADS.resolveModelAttribute(context, model).asInt());
    } else if (PoolAttributeDefinitions.CORE_THREADS.getName().equals(attributeName)) {
        pool.setCoreThreads(PoolAttributeDefinitions.CORE_THREADS.resolveModelAttribute(context, model).asInt());
    } else if (!forRollback) {
        // Programming bug. Throw a RuntimeException, not OFE, as this is not a client error
        throw ThreadsLogger.ROOT_LOGGER.unsupportedEnhancedQueueExecutorAttribute(attributeName);
    }
}
 
Example 4
Source File: UnboundedQueueThreadPoolWriteAttributeHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
protected void applyOperation(final OperationContext context, ModelNode model, String attributeName,
                              ServiceController<?> service, boolean forRollback) throws OperationFailedException {

    final UnboundedQueueThreadPoolService pool =  (UnboundedQueueThreadPoolService) service.getService();

    if (PoolAttributeDefinitions.KEEPALIVE_TIME.getName().equals(attributeName)) {
        TimeUnit defaultUnit = pool.getKeepAliveUnit();
        final TimeSpec spec = getTimeSpec(context, model, defaultUnit);
        pool.setKeepAlive(spec);
    } else if(PoolAttributeDefinitions.MAX_THREADS.getName().equals(attributeName)) {
        pool.setMaxThreads(PoolAttributeDefinitions.MAX_THREADS.resolveModelAttribute(context, model).asInt());
    } else if (!forRollback) {
        // Programming bug. Throw a RuntimeException, not OFE, as this is not a client error
        throw ThreadsLogger.ROOT_LOGGER.unsupportedUnboundedQueueThreadPoolAttribute(attributeName);
    }
}
 
Example 5
Source File: MscRuntimeContainerDelegate.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public void unregisterProcessEngine(ProcessEngine processEngine) {

  if(processEngine == null) {
    throw new ProcessEngineException("Cannot unregister process engine with Msc Runtime Container: process engine is 'null'");
  }

  ServiceName serviceName = ServiceNames.forManagedProcessEngine(processEngine.getName());

  // remove the service asynchronously
  ServiceController<ProcessEngine> service = (ServiceController<ProcessEngine>) serviceContainer.getService(serviceName);
  if(service != null && service.getService() instanceof MscManagedProcessEngine) {
    service.setMode(Mode.REMOVE);
  }

}
 
Example 6
Source File: MscRuntimeContainerDelegate.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public void unregisterProcessEngine(ProcessEngine processEngine) {

  if(processEngine == null) {
    throw new ProcessEngineException("Cannot unregister process engine with Msc Runtime Container: process engine is 'null'");
  }

  ServiceName serviceName = ServiceNames.forManagedProcessEngine(processEngine.getName());

  // remove the service asynchronously
  ServiceController<ProcessEngine> service = (ServiceController<ProcessEngine>) serviceContainer.getService(serviceName);
  if(service != null && service.getService() instanceof MscManagedProcessEngine) {
    service.setMode(Mode.REMOVE);
  }

}
 
Example 7
Source File: SecurityPropertiesWriteHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static SecurityPropertyService getService(OperationContext context) {
    ServiceRegistry serviceRegistry = context.getServiceRegistry(true);

    ServiceController<?> service = serviceRegistry.getService(SecurityPropertyService.SERVICE_NAME);
    if (service != null) {
        Object serviceImplementation = service.getService();
        if (serviceImplementation != null && serviceImplementation instanceof SecurityPropertyService) {
            return (SecurityPropertyService) serviceImplementation;
        }
    }

    // Again should not be reachable.
    throw new IllegalStateException("Requires service not available or wrong type.");
}
 
Example 8
Source File: ElytronDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static SecurityPropertyService uninstallSecurityPropertyService(OperationContext context) {
    ServiceRegistry serviceRegistry = context.getServiceRegistry(true);

    ServiceController<?> service = serviceRegistry.getService(SecurityPropertyService.SERVICE_NAME);
    if (service != null) {
        Object serviceImplementation = service.getService();
        context.removeService(service);
        if (serviceImplementation != null && serviceImplementation instanceof SecurityPropertyService) {
            return (SecurityPropertyService) serviceImplementation;
        }
    }

    return null;
}
 
Example 9
Source File: ModifiableKeyStoreDecorator.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Try to obtain a modifiable {@link KeyStoreService} based on the given {@link OperationContext}.
 *
 * @param context the current context
 * @return the modifiable KeyStore service
 * @throws OperationFailedException if an error occurs while attempting to obtain the modifiable KeyStore service
 */
static ModifiableKeyStoreService getModifiableKeyStoreService(OperationContext context) throws OperationFailedException {
    ServiceRegistry serviceRegistry = context.getServiceRegistry(true);
    PathAddress currentAddress = context.getCurrentAddress();
    RuntimeCapability<Void> runtimeCapability = KEY_STORE_RUNTIME_CAPABILITY.fromBaseCapability(currentAddress.getLastElement().getValue());
    ServiceName serviceName = runtimeCapability.getCapabilityServiceName();

    ServiceController<KeyStore> serviceContainer = getRequiredService(serviceRegistry, serviceName, KeyStore.class);
    ServiceController.State serviceState = serviceContainer.getState();
    if (serviceState != ServiceController.State.UP) {
        throw ROOT_LOGGER.requiredServiceNotUp(serviceName, serviceState);
    }

    return (ModifiableKeyStoreService) serviceContainer.getService();
}
 
Example 10
Source File: CertificateAuthorityAccountDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
static ModifiableKeyStoreService getModifiableKeyStoreService(ServiceRegistry serviceRegistry, String keyStoreName) throws OperationFailedException {
    RuntimeCapability<Void> runtimeCapability = KEY_STORE_RUNTIME_CAPABILITY.fromBaseCapability(keyStoreName);
    ServiceName serviceName = runtimeCapability.getCapabilityServiceName();

    ServiceController<KeyStore> serviceContainer = getRequiredService(serviceRegistry, serviceName, KeyStore.class);
    ServiceController.State serviceState = serviceContainer.getState();
    if (serviceState != ServiceController.State.UP) {
        throw ROOT_LOGGER.requiredServiceNotUp(serviceName, serviceState);
    }

    return (ModifiableKeyStoreService) serviceContainer.getService();
}
 
Example 11
Source File: CertificateAuthorityAccountDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static AcmeAccountService getAcmeAccountService(OperationContext context) throws OperationFailedException {
    ServiceRegistry serviceRegistry = context.getServiceRegistry(true);
    PathAddress currentAddress = context.getCurrentAddress();
    RuntimeCapability<Void> runtimeCapability = CERTIFICATE_AUTHORITY_ACCOUNT_RUNTIME_CAPABILITY.fromBaseCapability(currentAddress.getLastElement().getValue());
    ServiceName serviceName = runtimeCapability.getCapabilityServiceName();

    ServiceController<AcmeAccount> serviceContainer = getRequiredService(serviceRegistry, serviceName, AcmeAccount.class);
    ServiceController.State serviceState = serviceContainer.getState();
    if (serviceState != ServiceController.State.UP) {
        throw ROOT_LOGGER.requiredServiceNotUp(serviceName, serviceState);
    }

    return (AcmeAccountService) serviceContainer.getService();
}
 
Example 12
Source File: FileSystemDeploymentScanHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private FileSystemDeploymentService getExistingScanner(OperationContext context, ModelNode operation) throws OperationFailedException {
    final PathAddress address = PathAddress.pathAddress(operation.get(OP_ADDR));
    final String name = address.getLastElement().getValue();
    ServiceController<?> serviceController = context.getServiceRegistry(true).getService(DeploymentScannerService.getServiceName(name));
    if(serviceController != null && serviceController.getState() == ServiceController.State.UP) {
        DeploymentScannerService service =  (DeploymentScannerService) serviceController.getService();
        return (FileSystemDeploymentService) service.getValue();
    }
    return null;
}
 
Example 13
Source File: ThreadPoolMetricsHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException {
    final String attributeName = operation.require(ModelDescriptionConstants.NAME).asString();
    if (context.getRunningMode() == RunningMode.NORMAL) {
        ServiceController<?> serviceController = getService(context, operation);
        final Service<?> service = serviceController.getService();
        setResult(context, attributeName, service);
    }

    context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
}
 
Example 14
Source File: BoundedQueueThreadPoolWriteAttributeHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected void applyOperation(final OperationContext context, ModelNode model, String attributeName,
                              ServiceController<?> service, boolean forRollback) throws OperationFailedException {

    final BoundedQueueThreadPoolService pool =  (BoundedQueueThreadPoolService) service.getService();

    if (PoolAttributeDefinitions.KEEPALIVE_TIME.getName().equals(attributeName)) {
        TimeUnit defaultUnit = pool.getKeepAliveUnit();
        final TimeSpec spec = getTimeSpec(context, model, defaultUnit);
        pool.setKeepAlive(spec);
    } else if(PoolAttributeDefinitions.MAX_THREADS.getName().equals(attributeName)) {
        pool.setMaxThreads(PoolAttributeDefinitions.MAX_THREADS.resolveModelAttribute(context, model).asInt());
    } else if(PoolAttributeDefinitions.CORE_THREADS.getName().equals(attributeName)) {
        int coreCount;
        ModelNode coreNode = PoolAttributeDefinitions.CORE_THREADS.resolveModelAttribute(context, model);
        if (coreNode.isDefined()) {
            coreCount = coreNode.asInt();
        } else {
            // Core is same as max
            coreCount = PoolAttributeDefinitions.MAX_THREADS.resolveModelAttribute(context, model).asInt();
        }
        pool.setCoreThreads(coreCount);
    } else if(PoolAttributeDefinitions.QUEUE_LENGTH.getName().equals(attributeName)) {
        if (forRollback) {
            context.revertReloadRequired();
        } else {
            context.reloadRequired();
        }
    } else if (PoolAttributeDefinitions.ALLOW_CORE_TIMEOUT.getName().equals(attributeName)) {
        pool.setAllowCoreTimeout(PoolAttributeDefinitions.ALLOW_CORE_TIMEOUT.resolveModelAttribute(context, model).asBoolean());
    } else if (!forRollback) {
        // Programming bug. Throw a RuntimeException, not OFE, as this is not a client error
        throw ThreadsLogger.ROOT_LOGGER.unsupportedBoundedQueueThreadPoolAttribute(attributeName);
    }
}
 
Example 15
Source File: OutboundBindAddressUtils.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
static WorkerService getWorkerService(final OperationContext context) {
    final ServiceRegistry serviceRegistry = context.getServiceRegistry(false);
    final String workerName = context.getCurrentAddress().getParent().getLastElement().getValue();
    final ServiceName workerServiceName = WorkerResourceDefinition.IO_WORKER_RUNTIME_CAPABILITY.getCapabilityServiceName(workerName, XnioWorker.class);
    final ServiceController<?> workerServiceController = serviceRegistry.getRequiredService(workerServiceName);
    return (WorkerService) workerServiceController.getService();
}
 
Example 16
Source File: CertificateAuthorityDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
static Service<CertificateAuthority> getCertificateAuthorityService(ServiceRegistry serviceRegistry, String certificateAuthorityName) {
    RuntimeCapability<Void> runtimeCapability = CERTIFICATE_AUTHORITY_RUNTIME_CAPABILITY.fromBaseCapability(certificateAuthorityName);
    ServiceName serviceName = runtimeCapability.getCapabilityServiceName();
    ServiceController<CertificateAuthority> serviceContainer = getRequiredService(serviceRegistry, serviceName, CertificateAuthority.class);
    return serviceContainer.getService();
}