Search in sources :

Example 1 with StabilityMonitor

use of org.jboss.msc.service.StabilityMonitor in project wildfly by wildfly.

the class ServiceContainerHelper method transition.

private static <T> void transition(final ServiceController<T> targetController, final State targetState) {
    // Short-circuit if the service is already at the target state
    if (targetController.getState() == targetState)
        return;
    StabilityMonitor monitor = new StabilityMonitor();
    monitor.addController(targetController);
    try {
        // Force service to transition to desired state
        Mode targetMode = modeToggle.get(targetState).get(targetController.getMode());
        if (targetMode != null) {
            targetController.setMode(targetMode);
        }
        monitor.awaitStability();
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    } finally {
        monitor.removeController(targetController);
    }
}
Also used : Mode(org.jboss.msc.service.ServiceController.Mode) StabilityMonitor(org.jboss.msc.service.StabilityMonitor)

Example 2 with StabilityMonitor

use of org.jboss.msc.service.StabilityMonitor in project wildfly by wildfly.

the class ServiceReferenceObjectFactory method getObjectInstance.

@SuppressWarnings("unchecked")
@Override
public final Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception {
    final Reference reference = (Reference) obj;
    final ServiceNameRefAdr nameAdr = (ServiceNameRefAdr) reference.get("srof");
    if (nameAdr == null) {
        throw NamingLogger.ROOT_LOGGER.invalidContextReference("srof");
    }
    final ServiceName serviceName = (ServiceName) nameAdr.getContent();
    final ServiceController<?> controller;
    try {
        controller = serviceRegistry.getRequiredService(serviceName);
    } catch (ServiceNotFoundException e) {
        throw NamingLogger.ROOT_LOGGER.cannotResolveService(serviceName);
    }
    final StabilityMonitor monitor = new StabilityMonitor();
    monitor.addController(controller);
    try {
        monitor.awaitStability();
    } catch (InterruptedException e) {
        throw NamingLogger.ROOT_LOGGER.threadInterrupt(serviceName);
    } finally {
        monitor.removeController(controller);
    }
    switch(controller.getState()) {
        case UP:
            return getObjectInstance(controller.getValue(), obj, name, nameCtx, environment);
        case START_FAILED:
            throw NamingLogger.ROOT_LOGGER.cannotResolveService(serviceName, getClass().getName(), "START_FAILED");
        case REMOVED:
            throw NamingLogger.ROOT_LOGGER.cannotResolveService(serviceName, getClass().getName(), "REMOVED");
    }
    // we should never get here, as the listener should not notify unless the state was one of the above
    throw NamingLogger.ROOT_LOGGER.cannotResolveServiceBug(serviceName, getClass().getName(), controller.getState().toString());
}
Also used : ServiceName(org.jboss.msc.service.ServiceName) Reference(javax.naming.Reference) ModularReference(org.jboss.as.naming.context.ModularReference) ServiceNotFoundException(org.jboss.msc.service.ServiceNotFoundException) StabilityMonitor(org.jboss.msc.service.StabilityMonitor)

Example 3 with StabilityMonitor

use of org.jboss.msc.service.StabilityMonitor in project wildfly by wildfly.

the class SecurityDomainResourceDefinition method waitForService.

/**
     * Wait for the required service to start up and fail otherwise. This method is necessary when a runtime operation
     * uses a service that might have been created within a composite operation.
     *
     * This method will wait at most 100 millis.
     *
     * @param controller the service to wait for
     * @throws OperationFailedException if the service is not available, or the thread was interrupted.
     */
private static void waitForService(final ServiceController<?> controller) throws OperationFailedException {
    if (controller.getState() == ServiceController.State.UP)
        return;
    final StabilityMonitor monitor = new StabilityMonitor();
    monitor.addController(controller);
    try {
        monitor.awaitStability(100, MILLISECONDS);
    } catch (final InterruptedException e) {
        Thread.currentThread().interrupt();
        throw SecurityLogger.ROOT_LOGGER.interruptedWaitingForSecurityDomain(controller.getName().getSimpleName());
    } finally {
        monitor.removeController(controller);
    }
    if (controller.getState() != ServiceController.State.UP) {
        throw SecurityLogger.ROOT_LOGGER.requiredSecurityDomainServiceNotAvailable(controller.getName().getSimpleName());
    }
}
Also used : StabilityMonitor(org.jboss.msc.service.StabilityMonitor)

Aggregations

StabilityMonitor (org.jboss.msc.service.StabilityMonitor)3 Reference (javax.naming.Reference)1 ModularReference (org.jboss.as.naming.context.ModularReference)1 Mode (org.jboss.msc.service.ServiceController.Mode)1 ServiceName (org.jboss.msc.service.ServiceName)1 ServiceNotFoundException (org.jboss.msc.service.ServiceNotFoundException)1