Java Code Examples for org.jboss.msc.service.ServiceController#State

The following examples show how to use org.jboss.msc.service.ServiceController#State . 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: LdapConnectionRemoveHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) {
    PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
    String name = address.getLastElement().getValue();
    ServiceName svcName = LdapConnectionManagerService.ServiceUtil.createServiceName(name);
    ServiceRegistry registry = context.getServiceRegistry(true);
    ServiceController<?> controller = registry.getService(svcName);
    boolean removeIt;
    ServiceController.State state = controller == null ? null : controller.getState();
    if (state == ServiceController.State.UP) {
        removeIt = operation.hasDefined(OPERATION_HEADERS)
                && operation.get(OPERATION_HEADERS).hasDefined(ALLOW_RESOURCE_SERVICE_RESTART)
                && operation.get(OPERATION_HEADERS, ALLOW_RESOURCE_SERVICE_RESTART).asBoolean();
    } else {
        removeIt = true;
    }

    if (removeIt) {
        context.removeService(svcName);
    } else {
        context.reloadRequired();
    }
}
 
Example 2
Source File: LdapKeyStoreDefinition.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 {
    ServiceName ldapKeyStoreName = LDAP_KEY_STORE_UTIL.serviceName(operation);

    ServiceController<KeyStore> serviceContainer = getRequiredService(context.getServiceRegistry(writeAccess), ldapKeyStoreName, KeyStore.class);
    ServiceController.State serviceState;
    if ((serviceState = serviceContainer.getState()) != ServiceController.State.UP) {
        if (serviceMustBeUp) {
            throw ROOT_LOGGER.requiredServiceNotUp(ldapKeyStoreName, serviceState);
        }
        return;
    }

    performRuntime(context.getResult(), context, operation, (LdapKeyStoreService) serviceContainer.getService());
}
 
Example 3
Source File: AdvancedModifiableKeyStoreDecorator.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static AcmeAccount getAcmeAccount(OperationContext context, String certificateAuthorityAccountName, boolean staging) throws OperationFailedException {
    ServiceRegistry serviceRegistry = context.getServiceRegistry(true);
    RuntimeCapability<Void> runtimeCapability = CERTIFICATE_AUTHORITY_ACCOUNT_RUNTIME_CAPABILITY.fromBaseCapability(certificateAuthorityAccountName);
    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);
    }
    AcmeAccount acmeAccount = serviceContainer.getService().getValue();
    return resetAcmeAccount(acmeAccount, staging);
}
 
Example 4
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 5
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 6
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 7
Source File: BindingRemoveHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) {
    String name = context.getCurrentAddressValue();
    ServiceName svcName = SOCKET_BINDING_CAPABILITY.getCapabilityServiceName(name);
    ServiceRegistry registry = context.getServiceRegistry(true);
    ServiceController<?> controller = registry.getService(svcName);
    ServiceController.State state = controller == null ? null : controller.getState();
    if (!context.isResourceServiceRestartAllowed() || (state == ServiceController.State.UP)) {
        context.reloadRequired();
    } else {
        context.removeService(svcName);
    }
}
 
Example 8
Source File: ManagementUtil.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
static boolean isSecurityRealmReloadRequired(final OperationContext context, final ServiceController<?> controller) {
    final ServiceController.State state = controller == null ? null : controller.getState();
    return state == ServiceController.State.UP && !context.isResourceServiceRestartAllowed();
}