private void transition(State targetState) { // Short-circuit if the service is already at the target state if (this.controller.getState() == targetState) return; StabilityMonitor monitor = new StabilityMonitor(); monitor.addController(this.controller); try { // Force service to transition to desired state Mode targetMode = modeToggle.get(targetState).get(this.controller.getMode()); if (targetMode != null) { this.controller.setMode(targetMode); } monitor.awaitStability(); if (this.controller.getState() == ServiceController.State.START_FAILED) { throw new IllegalStateException(this.controller.getStartException()); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); } finally { monitor.removeController(this.controller); } } }
throw new IllegalStateException(new TimeoutException()); switch (controller.getState()) { case START_FAILED: { throw new IllegalStateException(controller.getStartException());
static ListenerService getListenerService(OperationContext context) { final String name = context.getCurrentAddressValue(); ServiceName serviceName = LISTENER_CAPABILITY.getCapabilityServiceName(name); ServiceController<ListenerService> listenerSC = (ServiceController<ListenerService>) context.getServiceRegistry(false).getService(serviceName); if (listenerSC == null || listenerSC.getState() != ServiceController.State.UP) { return null; } return listenerSC.getValue(); }
/** * 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()); } }
private T getComponent(final ServiceName serviceName, final PathAddress operationAddress, final OperationContext context, final boolean forWrite) throws OperationFailedException { ServiceRegistry registry = context.getServiceRegistry(forWrite); ServiceController<?> controller = registry.getService(serviceName); if (controller == null) { String exceptionMessage = EjbLogger.ROOT_LOGGER.noComponentAvailableForAddress(operationAddress); throw new OperationFailedException(exceptionMessage); } ServiceController.State controllerState = controller.getState(); if (controllerState != ServiceController.State.UP) { String exceptionMessage = EjbLogger.ROOT_LOGGER.invalidComponentState(operationAddress, controllerState, ServiceController.State.UP); throw new OperationFailedException(exceptionMessage); } return componentClass.cast(controller.getValue()); }
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { if (context.isDefaultRequiresRuntime()) { context.addStep((ctx, op) -> { RuntimeCapability<Void> runtimeCapability = APPLICATION_SECURITY_DOMAIN_RUNTIME_CAPABILITY.fromBaseCapability(context.getCurrentAddressValue()); ServiceName serviceName = runtimeCapability.getCapabilityServiceName(ApplicationSecurityDomain.class); ServiceRegistry serviceRegistry = context.getServiceRegistry(false); ServiceController<?> controller = serviceRegistry.getRequiredService(serviceName); ModelNode deploymentList = new ModelNode(); if (controller.getState() == State.UP) { Service service = controller.getService(); if (service instanceof ApplicationSecurityDomainService) { for (String current : ((ApplicationSecurityDomainService) service).getDeployments()) { deploymentList.add(current); } } } context.getResult().set(deploymentList); }, OperationContext.Stage.RUNTIME); } } }
ModelNode result = new ModelNode(); final ServiceController<?> controller = context.getServiceRegistry(false).getService(UndertowService.deploymentServiceName(server, host, path)); if (controller != null && controller.getState() != ServiceController.State.UP) {//check if deployment is active at all return;
private static SessionManager getSessionManager(OperationContext context, ModelNode operation) throws OperationFailedException { final PathAddress address = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)); final Resource web = context.readResourceFromRoot(address.subAddress(0, address.size()), false); final ModelNode subModel = web.getModel(); final String host = VIRTUAL_HOST.resolveModelAttribute(context, subModel).asString(); final String path = CONTEXT_ROOT.resolveModelAttribute(context, subModel).asString(); final String server = SERVER.resolveModelAttribute(context, subModel).asString(); final UndertowDeploymentService deploymentService; final ServiceController<?> controller = context.getServiceRegistry(false).getService(UndertowService.deploymentServiceName(server, host, path)); if (controller != null && controller.getState() != ServiceController.State.UP) {//check if deployment is active at all throw UndertowLogger.ROOT_LOGGER.sessionManagerNotAvailable(); } else { deploymentService = (UndertowDeploymentService) controller.getService(); if (deploymentService == null || deploymentService.getDeployment() == null) { //we might be in shutdown and it is possible throw UndertowLogger.ROOT_LOGGER.sessionManagerNotAvailable(); } } Deployment deployment = deploymentService.getDeployment(); return deployment.getSessionManager(); }
XaDataSourcePropertiesService xaPropService = (XaDataSourcePropertiesService) xaConfigPropertyController.getService(); if (!ServiceController.State.UP.equals(xaConfigPropertyController.getState())) { propertiesCount++; xaConfigPropertyController.setMode(ServiceController.Mode.ACTIVE); ConnectionPropertiesService connPropService = (ConnectionPropertiesService) connPropServiceController.getService(); if (!ServiceController.State.UP.equals(connPropServiceController.getState())) { connPropServiceController.setMode(ServiceController.Mode.ACTIVE); builder.addDependency(name, String.class, configService.getConnectionPropertyInjector(connPropService.getName())); if (!ServiceController.State.UP.equals(dataSourceController.getState())) { final boolean statsEnabled = STATISTICS_ENABLED.resolveModelAttribute(context, model).asBoolean(); DataSourceStatisticsService statsService = new DataSourceStatisticsService(datasourceRegistration, statsEnabled);
/** {@inheritDoc} */ @Override public State getState() { return getDelegate().getState(); }
private ManagementService getManagementService() { if (activeMQServerServiceController == null || activeMQServerServiceController.getState() != ServiceController.State.UP) { return null; } else { return activeMQServerServiceController.getValue().getManagementService(); } } }
/** * Returns the value of the specified service, if the service exists and is started. * @param registry the service registry * @param name the service name * @return the service value, if the service exists and is started, null otherwise */ public static <T> T findValue(ServiceRegistry registry, ServiceName name) { ServiceController<T> service = findService(registry, name); return ((service != null) && (service.getState() == State.UP)) ? service.getValue() : null; }
@Override public void listenerAdded(ServiceController<? extends ModuleSpec> controller) { log.tracef("listenerAdded: %s", controller); State state = controller.getState(); if (state == State.UP || state == State.START_FAILED) { done(controller, controller.getStartException()); } }
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; }
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()]); }
private ActiveMQServerControl getServerControl(final OperationContext context, ModelNode operation) throws OperationFailedException { final ServiceName serviceName = MessagingServices.getActiveMQServiceName(PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR))); ServiceController<?> service = context.getServiceRegistry(false).getService(serviceName); if (service == null || service.getState() != ServiceController.State.UP) { throw MessagingLogger.ROOT_LOGGER.activeMQServerNotInstalled(serviceName.getSimpleName()); } ActiveMQServer server = ActiveMQServer.class.cast(service.getValue()); return server.getActiveMQServerControl(); } }
static ListenerService getListenerService(OperationContext context) { final String name = context.getCurrentAddressValue(); ServiceName serviceName = LISTENER_CAPABILITY.getCapabilityServiceName(name); ServiceController<ListenerService> listenerSC = (ServiceController<ListenerService>) context.getServiceRegistry(false).getService(serviceName); if (listenerSC == null || listenerSC.getState() != ServiceController.State.UP) { return null; } return listenerSC.getValue(); }
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); } }
@Override protected void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException { ServiceName securityRealmName = SECURITY_REALM_RUNTIME_CAPABILITY.fromBaseCapability(context.getCurrentAddressValue()).getCapabilityServiceName(); ServiceController<SecurityRealm> serviceContainer = getRequiredService(context.getServiceRegistry(writeAccess), securityRealmName, SecurityRealm.class); State serviceState; if ((serviceState = serviceContainer.getState()) != State.UP) { throw ROOT_LOGGER.requiredServiceNotUp(securityRealmName, serviceState); } SecurityRealm securityRealm = serviceContainer.getValue(); assert securityRealm instanceof RealmWrapper; performRuntime(context, (RealmWrapper) securityRealm); }