Search in sources :

Example 1 with ServiceController

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

the class JMSService method doStart.

private synchronized void doStart(final StartContext context) throws StartException {
    final ServiceContainer serviceContainer = context.getController().getServiceContainer();
    ClassLoader oldTccl = WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(getClass());
    try {
        jmsServer = new JMSServerManagerImpl(activeMQServer.getValue(), new WildFlyBindingRegistry(context.getController().getServiceContainer()));
        activeMQServer.getValue().registerActivateCallback(new ActivateCallback() {

            private volatile ServiceController<Void> activeMQActivationController;

            public void preActivate() {
            }

            public void activated() {
                if (overrideInVMSecurity) {
                    activeMQServer.getValue().getRemotingService().allowInvmSecurityOverride(new ActiveMQPrincipal(DefaultCredentials.getUsername(), DefaultCredentials.getPassword()));
                }
                //   ActiveMQ backup server is activated during failover while the WildFly server is shutting down.
                if (serviceContainer.isShutdown()) {
                    return;
                }
                if (activeMQActivationController == null) {
                    activeMQActivationController = serviceContainer.addService(ActiveMQActivationService.getServiceName(serverServiceName), new ActiveMQActivationService()).setInitialMode(Mode.ACTIVE).install();
                } else {
                    activeMQActivationController.setMode(ACTIVE);
                }
            }

            @Override
            public void activationComplete() {
            }

            public void deActivate() {
                // and *not* during AS7 service container shutdown or reload (AS7-6840 / AS7-6881)
                if (activeMQActivationController != null) {
                    if (!activeMQActivationController.getState().in(STOPPING, REMOVED)) {
                        // [WFLY-4597] When Artemis is deactivated during failover, we block until its
                        // activation controller is REMOVED before giving back control to Artemis.
                        // This allow to properly stop any service depending on the activation controller
                        // and avoid spurious warning messages because the resources used by the services
                        // are stopped outside the control of the services.
                        final CountDownLatch latch = new CountDownLatch(1);
                        activeMQActivationController.compareAndSetMode(ACTIVE, REMOVE);
                        activeMQActivationController.addListener(new AbstractServiceListener<Void>() {

                            @Override
                            public void transition(ServiceController<? extends Void> controller, ServiceController.Transition transition) {
                                if (transition.enters(REMOVED)) {
                                    latch.countDown();
                                }
                            }
                        });
                        try {
                            latch.await(5, TimeUnit.SECONDS);
                        } catch (InterruptedException e) {
                        }
                        activeMQActivationController = null;
                    }
                }
            }
        });
        jmsServer.start();
    } catch (StartException e) {
        throw e;
    } catch (Throwable t) {
        throw MessagingLogger.ROOT_LOGGER.failedToStartService(t);
    } finally {
        WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(oldTccl);
    }
}
Also used : ActiveMQPrincipal(org.apache.activemq.artemis.core.security.ActiveMQPrincipal) AbstractServiceListener(org.jboss.msc.service.AbstractServiceListener) CountDownLatch(java.util.concurrent.CountDownLatch) ServiceContainer(org.jboss.msc.service.ServiceContainer) ActiveMQActivationService(org.wildfly.extension.messaging.activemq.ActiveMQActivationService) JMSServerManagerImpl(org.apache.activemq.artemis.jms.server.impl.JMSServerManagerImpl) ServiceController(org.jboss.msc.service.ServiceController) StartException(org.jboss.msc.service.StartException) ActivateCallback(org.apache.activemq.artemis.core.server.ActivateCallback)

Example 2 with ServiceController

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

the class AbstractPicketLinkMetricsOperationHandler method execute.

@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
    context.addStep(new OperationStepHandler() {

        @Override
        public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
            final PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
            final String name = address.getLastElement().getValue();
            final String attributeName = operation.require(NAME).asString();
            final ServiceController<?> controller = context.getServiceRegistry(false).getRequiredService(createServiceName(name));
            try {
                PicketLinkFederationService<?> service = (PicketLinkFederationService<?>) controller.getValue();
                doPopulateResult(service.getMetrics(), context.getResult(), attributeName);
            } catch (Exception e) {
                throw PicketLinkLogger.ROOT_LOGGER.failedToGetMetrics(e.getMessage());
            }
            context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
        }
    }, OperationContext.Stage.RUNTIME);
    context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) PicketLinkFederationService(org.wildfly.extension.picketlink.federation.service.PicketLinkFederationService) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) PathAddress(org.jboss.as.controller.PathAddress) OperationFailedException(org.jboss.as.controller.OperationFailedException) ServiceController(org.jboss.msc.service.ServiceController) ModelNode(org.jboss.dmr.ModelNode) OperationFailedException(org.jboss.as.controller.OperationFailedException)

Example 3 with ServiceController

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

the class MailSessionDefinitionInjectionSource method startMailSession.

private void startMailSession(final MailSessionService mailSessionService, final String jndiName, final EEModuleDescription moduleDescription, final ResolutionContext context, final ServiceTarget serviceTarget, final ServiceBuilder<?> valueSourceServiceBuilder, final Injector<ManagedReferenceFactory> injector) {
    final ServiceName mailSessionServiceName = MailSessionAdd.MAIL_SESSION_SERVICE_NAME.append("MailSessionDefinition", moduleDescription.getApplicationName(), moduleDescription.getModuleName(), jndiName);
    final ServiceBuilder<?> mailSessionServiceBuilder = serviceTarget.addService(mailSessionServiceName, mailSessionService);
    final ContextNames.BindInfo bindInfo = ContextNames.bindInfoForEnvEntry(context.getApplicationName(), context.getModuleName(), context.getComponentName(), !context.isCompUsesModule(), jndiName);
    final MailSessionManagedReferenceFactory referenceFactoryService = new MailSessionManagedReferenceFactory(mailSessionService);
    final BinderService binderService = new BinderService(bindInfo.getBindName(), this);
    final ServiceBuilder<?> binderBuilder = serviceTarget.addService(bindInfo.getBinderServiceName(), binderService).addInjection(binderService.getManagedObjectInjector(), referenceFactoryService).addDependency(bindInfo.getParentContextServiceName(), ServiceBasedNamingStore.class, binderService.getNamingStoreInjector()).addListener(new AbstractServiceListener<Object>() {

        public void transition(final ServiceController<? extends Object> controller, final ServiceController.Transition transition) {
            switch(transition) {
                case STARTING_to_UP:
                    {
                        MailLogger.ROOT_LOGGER.boundMailSession(jndiName);
                        break;
                    }
                case START_REQUESTED_to_DOWN:
                    {
                        MailLogger.ROOT_LOGGER.unboundMailSession(jndiName);
                        break;
                    }
                case REMOVING_to_REMOVED:
                    {
                        MailLogger.ROOT_LOGGER.debugf("Removed Mail Session [%s]", jndiName);
                        break;
                    }
            }
        }
    });
    mailSessionServiceBuilder.setInitialMode(ServiceController.Mode.ACTIVE).install();
    binderBuilder.setInitialMode(ServiceController.Mode.ACTIVE).install();
    valueSourceServiceBuilder.addDependency(bindInfo.getBinderServiceName(), ManagedReferenceFactory.class, injector);
}
Also used : BinderService(org.jboss.as.naming.service.BinderService) ServiceName(org.jboss.msc.service.ServiceName) ServiceBasedNamingStore(org.jboss.as.naming.ServiceBasedNamingStore) ServiceController(org.jboss.msc.service.ServiceController) ContextNames(org.jboss.as.naming.deployment.ContextNames)

Example 4 with ServiceController

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

the class BinderServiceUtil method installAliasBinderService.

public static void installAliasBinderService(final ServiceTarget serviceTarget, final BindInfo bindInfo, final String alias) {
    final BindInfo aliasBindInfo = ContextNames.bindInfoFor(alias);
    final BinderService aliasBinderService = new BinderService(alias);
    aliasBinderService.getManagedObjectInjector().inject(new AliasManagedReferenceFactory(bindInfo.getAbsoluteJndiName()));
    serviceTarget.addService(aliasBindInfo.getBinderServiceName(), aliasBinderService).addDependency(bindInfo.getParentContextServiceName(), ServiceBasedNamingStore.class, aliasBinderService.getNamingStoreInjector()).addDependency(bindInfo.getBinderServiceName()).addListener(new AbstractServiceListener<ManagedReferenceFactory>() {

        @Override
        public void transition(ServiceController<? extends ManagedReferenceFactory> controller, ServiceController.Transition transition) {
            switch(transition) {
                case STARTING_to_UP:
                    {
                        ROOT_LOGGER.boundJndiName(alias);
                        break;
                    }
                case STOPPING_to_DOWN:
                    {
                        ROOT_LOGGER.unboundJndiName(alias);
                        break;
                    }
                case REMOVING_to_REMOVED:
                    {
                        ROOT_LOGGER.debugf("Removed messaging object [%s]", alias);
                        break;
                    }
            }
        }
    }).install();
}
Also used : BinderService(org.jboss.as.naming.service.BinderService) ServiceBasedNamingStore(org.jboss.as.naming.ServiceBasedNamingStore) ContextListAndJndiViewManagedReferenceFactory(org.jboss.as.naming.ContextListAndJndiViewManagedReferenceFactory) ContextListManagedReferenceFactory(org.jboss.as.naming.ContextListManagedReferenceFactory) ManagedReferenceFactory(org.jboss.as.naming.ManagedReferenceFactory) ValueManagedReferenceFactory(org.jboss.as.naming.ValueManagedReferenceFactory) AbstractServiceListener(org.jboss.msc.service.AbstractServiceListener) ServiceController(org.jboss.msc.service.ServiceController) BindInfo(org.jboss.as.naming.deployment.ContextNames.BindInfo)

Example 5 with ServiceController

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

the class ExportJournalOperation method executeRuntimeStep.

@Override
protected void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException {
    if (context.getRunningMode() != ADMIN_ONLY) {
        throw MessagingLogger.ROOT_LOGGER.managementOperationAllowedOnlyInRunningMode("export-journal", ADMIN_ONLY);
    }
    final ServiceController<PathManager> service = (ServiceController<PathManager>) context.getServiceRegistry(false).getService(PathManagerService.SERVICE_NAME);
    final PathManager pathManager = service.getService().getValue();
    final String journal = resolvePath(context, pathManager, JOURNAL_DIRECTORY_PATH);
    final String bindings = resolvePath(context, pathManager, BINDINGS_DIRECTORY_PATH);
    final String paging = resolvePath(context, pathManager, PAGING_DIRECTORY_PATH);
    final String largeMessages = resolvePath(context, pathManager, LARGE_MESSAGES_DIRECTORY_PATH);
    final XmlDataExporter exporter = new XmlDataExporter();
    String name = String.format(FILE_NAME_FORMAT, new Date());
    // write the exported dump at the same level than the journal directory
    File dump = new File(new File(journal).getParent(), name);
    FileOutputStream fos = null;
    try {
        fos = new FileOutputStream(dump);
        exporter.process(fos, bindings, journal, paging, largeMessages);
        context.getResult().set(dump.getAbsolutePath());
    } catch (Exception e) {
        throw new OperationFailedException(e);
    } finally {
        if (fos != null) {
            try {
                fos.close();
            } catch (IOException e) {
            }
        }
    }
}
Also used : PathManager(org.jboss.as.controller.services.path.PathManager) FileOutputStream(java.io.FileOutputStream) OperationFailedException(org.jboss.as.controller.OperationFailedException) ServiceController(org.jboss.msc.service.ServiceController) IOException(java.io.IOException) File(java.io.File) XmlDataExporter(org.apache.activemq.artemis.cli.commands.tools.XmlDataExporter) Date(java.util.Date) IOException(java.io.IOException) OperationFailedException(org.jboss.as.controller.OperationFailedException)

Aggregations

ServiceController (org.jboss.msc.service.ServiceController)51 ServiceName (org.jboss.msc.service.ServiceName)20 ModelNode (org.jboss.dmr.ModelNode)17 OperationFailedException (org.jboss.as.controller.OperationFailedException)15 OperationContext (org.jboss.as.controller.OperationContext)12 ServiceRegistry (org.jboss.msc.service.ServiceRegistry)12 BinderService (org.jboss.as.naming.service.BinderService)9 PathAddress (org.jboss.as.controller.PathAddress)8 ContextNames (org.jboss.as.naming.deployment.ContextNames)8 HttpHandler (io.undertow.server.HttpHandler)7 PathHandler (io.undertow.server.handlers.PathHandler)7 OperationStepHandler (org.jboss.as.controller.OperationStepHandler)7 FilterService (org.wildfly.extension.undertow.filters.FilterService)7 ServiceBasedNamingStore (org.jboss.as.naming.ServiceBasedNamingStore)6 ArrayList (java.util.ArrayList)5 Resource (org.jboss.as.controller.registry.Resource)5 ManagedReferenceFactory (org.jboss.as.naming.ManagedReferenceFactory)5 AbstractServiceListener (org.jboss.msc.service.AbstractServiceListener)5 List (java.util.List)4 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)4