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

The following examples show how to use org.jboss.msc.service.ServiceController#getState() . 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: ServiceModuleLoader.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public ModuleSpec findModule(ModuleIdentifier identifier) throws ModuleLoadException {
    ServiceController<ModuleDefinition> controller = (ServiceController<ModuleDefinition>) serviceContainer.getService(moduleSpecServiceName(identifier));
    if (controller == null) {
        ServerLogger.MODULE_SERVICE_LOGGER.debugf("Could not load module '%s' as corresponding module spec service '%s' was not found", identifier, identifier);
        return null;
    }
    UninterruptibleCountDownLatch latch = new UninterruptibleCountDownLatch(1);
    ModuleSpecLoadListener listener = new ModuleSpecLoadListener(latch);
    try {
        synchronized (controller) {
            final State state = controller.getState();
            if (state == State.UP || state == State.START_FAILED) {
                listener.done(controller, controller.getStartException());
            }
        }
        controller.addListener(listener);
    } finally {
        latch.countDown();
    }
    return listener.getModuleSpec();
}
 
Example 2
Source File: ManagementInterfaceAddStepHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
    List<ServiceName> failures = new ArrayList<>();
    ServiceRegistry registry = context.getServiceRegistry(false);
    for (ServiceName serviceName : requiredServices) {
        try {
            ServiceController<?> controller = registry.getService(serviceName);
            if (controller == null || State.UP != controller.getState()) {
                failures.add(serviceName);
            }
        } catch (ServiceNotFoundException ex) {
            failures.add(serviceName);
        }
    }
    if (!failures.isEmpty()) {
        Boolean attachment = context.getAttachment(MANAGEMENT_INTERFACE_KEY);
        if (attachment == null || !context.getAttachment(MANAGEMENT_INTERFACE_KEY)) {
            context.attach(MANAGEMENT_INTERFACE_KEY, false);
            context.addStep(new VerifyInstallationStep(), OperationContext.Stage.VERIFY);
        }
    } else {
        context.attach(MANAGEMENT_INTERFACE_KEY, true);
    }
}
 
Example 3
Source File: AbstractBindingWriteHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
protected boolean applyUpdateToRuntime(final OperationContext context, final ModelNode operation, final String attributeName, final ModelNode resolvedValue,
                                       final ModelNode currentValue, final HandbackHolder<RollbackInfo> handbackHolder) throws OperationFailedException {

    final PathAddress address = PathAddress.pathAddress(operation.get(OP_ADDR));
    final PathElement element = address.getLastElement();
    final String bindingName = element.getValue();
    final ModelNode bindingModel = context.readResource(PathAddress.EMPTY_ADDRESS).getModel();
    final ServiceName serviceName = SOCKET_BINDING_CAPABILITY.getCapabilityServiceName(bindingName, SocketBinding.class);
    final ServiceController<?> controller = context.getServiceRegistry(true).getRequiredService(serviceName);
    final SocketBinding binding = controller.getState() == ServiceController.State.UP ? SocketBinding.class.cast(controller.getValue()) : null;
    final boolean bound = binding != null && binding.isBound();
    if (binding == null) {
        // existing is not started, so can't update it. Instead reinstall the service
        handleBindingReinstall(context, bindingName, bindingModel, serviceName);
    } else if (bound) {
        // Cannot edit bound sockets
        return true;
    } else {
        handleRuntimeChange(context, operation, attributeName, resolvedValue, binding);
    }
    handbackHolder.setHandback(new RollbackInfo(bindingName, bindingModel, binding));
    return requiresRestart();
}
 
Example 4
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 5
Source File: PathsTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testBadAdd() throws Exception {
    ServiceController<?> pathManagerService = getContainer().getRequiredService(PATH_MANAGER_SVC);
    PathManager pathManager = (PathManager) pathManagerService.getValue();

    PerformChangeCallback allCallback1 = new PerformChangeCallback(pathManager, "add1", Event.ADDED, Event.REMOVED, Event.UPDATED);

    ModelNode operation = createOperation(ADD);
    operation.get(OP_ADDR).add(PATH, "add1");
    operation.get(PATH).set("123");
    operation.get(RELATIVE_TO).set("bad");
    executeForFailure(operation);

    try {
        ServiceController<?> svc = getContainer().getRequiredService(AbstractPathService.pathNameOf("add1"));
        if (svc.getState() == State.UP) {
            Assert.fail("Should not managed to install service");
        }
    } catch (Exception expected) {
    }

    allCallback1.checkEvent(Event.ADDED, "add1", "123", "bad");
    allCallback1.checkEvent(Event.REMOVED, "add1", "123", "bad");
    allCallback1.checkDone();
}
 
Example 6
Source File: ModifiableRealmDecorator.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Try to obtain a {@link ModifiableSecurityRealm} based on the given {@link OperationContext}.
 *
 * @param context the current context
 * @return the current security realm
 * @throws OperationFailedException if any error occurs obtaining the reference to the security realm.
 */
static ModifiableSecurityRealm getModifiableSecurityRealm(OperationContext context) throws OperationFailedException {
    ServiceRegistry serviceRegistry = context.getServiceRegistry(true);
    PathAddress currentAddress = context.getCurrentAddress();
    RuntimeCapability<Void> runtimeCapability = MODIFIABLE_SECURITY_REALM_RUNTIME_CAPABILITY.fromBaseCapability(currentAddress.getLastElement().getValue());
    ServiceName realmName = runtimeCapability.getCapabilityServiceName();
    ServiceController<ModifiableSecurityRealm> serviceController = getRequiredService(serviceRegistry, realmName, ModifiableSecurityRealm.class);
    if ( serviceController.getState() != ServiceController.State.UP ){
        try {
            serviceController.awaitValue(500, TimeUnit.MILLISECONDS);
        } catch (IllegalStateException | InterruptedException | TimeoutException e) {
            throw ROOT_LOGGER.requiredServiceNotUp(serviceController.getName(), serviceController.getState());
        }
    }
    return serviceController.getValue();
}
 
Example 7
Source File: BootstrapImpl.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static SuspendController getSuspendController(ServiceContainer sc) {
    SuspendController result = null;
    if (sc != null && !sc.isShutdownComplete()) {
        final ServiceController serviceController = sc.getService(JBOSS_SUSPEND_CONTROLLER);
        if (serviceController != null && serviceController.getState() == ServiceController.State.UP) {
            result = (SuspendController) serviceController.getValue();
        }
    }
    return result;
}
 
Example 8
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 9
Source File: WorkerResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
static XnioWorker getXnioWorker(ServiceRegistry serviceRegistry, String name) {
    ServiceName serviceName = IO_WORKER_RUNTIME_CAPABILITY.getCapabilityServiceName(name, XnioWorker.class);
    ServiceController<XnioWorker> controller = (ServiceController<XnioWorker>) serviceRegistry.getService(serviceName);
    if (controller == null || controller.getState() != ServiceController.State.UP) {
        return null;
    }
    return controller.getValue();
}
 
Example 10
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 11
Source File: SSLDefinitions.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 serviceName = getSSLContextServiceUtil().serviceName(operation);

    ServiceController<SSLContext> serviceController = getRequiredService(context.getServiceRegistry(false), serviceName, SSLContext.class);
    State serviceState;
    if ((serviceState = serviceController.getState()) != State.UP) {
        throw ROOT_LOGGER.requiredServiceNotUp(serviceName, serviceState);
    }

    performRuntime(context.getResult(), operation, serviceController.getService().getValue());
}
 
Example 12
Source File: DomainDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static void startSecurityDomainServiceIfNotUp(ServiceController<SecurityDomain> serviceController) throws OperationFailedException {
    if (serviceController.getState() != ServiceController.State.UP) {
        serviceController.setMode(Mode.ACTIVE);
        try {
            serviceController.awaitValue();
        } catch (InterruptedException e) {
            throw new OperationFailedException(e);
        }
    }
}
 
Example 13
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 14
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 15
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 16
Source File: AuthenticationFactoryDefinitions.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static String[] getAvailableSaslMechanisms(OperationContext context) {
    RuntimeCapability<Void> runtimeCapability = SASL_AUTHENTICATION_FACTORY_RUNTIME_CAPABILITY.fromBaseCapability(context.getCurrentAddressValue());
    ServiceName securityDomainSaslConfigurationName = runtimeCapability.getCapabilityServiceName(SaslAuthenticationFactory.class);

    ServiceController<SaslAuthenticationFactory> serviceContainer = getRequiredService(context.getServiceRegistry(false), securityDomainSaslConfigurationName, SaslAuthenticationFactory.class);
    if (serviceContainer.getState() != State.UP) {
        return null;
    }

    Collection<String> mechanismNames = serviceContainer.getValue().getMechanismNames();
    return  mechanismNames.toArray(new String[mechanismNames.size()]);
}
 
Example 17
Source File: AuthenticationFactoryDefinitions.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static String[] getAvailableHttpMechanisms(OperationContext context) {
    RuntimeCapability<Void> runtimeCapability = HTTP_AUTHENTICATION_FACTORY_RUNTIME_CAPABILITY.fromBaseCapability(context.getCurrentAddressValue());
    ServiceName securityDomainHttpConfigurationName = runtimeCapability.getCapabilityServiceName(HttpAuthenticationFactory.class);

    ServiceController<HttpAuthenticationFactory> serviceContainer = getRequiredService(context.getServiceRegistry(false), securityDomainHttpConfigurationName, HttpAuthenticationFactory.class);
    if (serviceContainer.getState() != State.UP) {
        return null;
    }

    Collection<String> mechanismNames = serviceContainer.getValue().getMechanismNames();
    return  mechanismNames.toArray(new String[mechanismNames.size()]);
}
 
Example 18
Source File: SaslServerDefinitions.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static String[] getSaslServerAvailableMechanisms(OperationContext context) {
    RuntimeCapability<Void> runtimeCapability = SASL_SERVER_FACTORY_RUNTIME_CAPABILITY.fromBaseCapability(context.getCurrentAddressValue());
    ServiceName saslServerFactoryName = runtimeCapability.getCapabilityServiceName(SaslServerFactory.class);

    ServiceController<SaslServerFactory> serviceContainer = getRequiredService(context.getServiceRegistry(false), saslServerFactoryName, SaslServerFactory.class);
    if (serviceContainer.getState() != State.UP) {
        return null;
    }
    return serviceContainer.getValue().getMechanismNames(Collections.emptyMap());
}
 
Example 19
Source File: SSLContextResource.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Get the {@link SSLContext} represented by this {@link Resource} or {@code null} if it is not currently available.
 *
 * @return The {@link SSLContext} represented by this {@link Resource} or {@code null} if it is not currently available.
 */
static SSLContext getSSLContext(ServiceController<SSLContext> sslContextServiceController) {
    if (sslContextServiceController == null || sslContextServiceController.getState() != State.UP) {
        return null;
    } else {
        return sslContextServiceController.getValue();
    }
}
 
Example 20
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());
}