Search in sources :

Example 1 with ServiceContainer

use of org.jboss.msc.service.ServiceContainer 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 ServiceContainer

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

the class ApplicationClientStartService method start.

@Override
public synchronized void start(final StartContext context) throws StartException {
    final ServiceContainer serviceContainer = context.getController().getServiceContainer();
    thread = new Thread(new Runnable() {

        @Override
        public void run() {
            final ClassLoader oldTccl = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
            try {
                try {
                    WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(classLoader);
                    applicationClientDeploymentServiceInjectedValue.getValue().getDeploymentCompleteLatch().await();
                    NamespaceContextSelector.setDefault(namespaceContextSelectorInjectedValue);
                    try {
                        //perform any additional setup that may be needed
                        for (SetupAction action : setupActions) {
                            action.setup(Collections.<String, Object>emptyMap());
                        }
                        //do static injection etc
                        instance = applicationClientComponent.getValue().createInstance();
                        mainMethod.invoke(null, new Object[] { parameters });
                    } finally {
                        final ListIterator<SetupAction> iterator = setupActions.listIterator(setupActions.size());
                        Throwable error = null;
                        while (iterator.hasPrevious()) {
                            SetupAction action = iterator.previous();
                            try {
                                action.teardown(Collections.<String, Object>emptyMap());
                            } catch (Throwable e) {
                                error = e;
                            }
                        }
                        if (error != null) {
                            throw new RuntimeException(error);
                        }
                    }
                } catch (Exception e) {
                    ROOT_LOGGER.exceptionRunningAppClient(e, e.getClass().getSimpleName());
                } finally {
                    WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(oldTccl);
                }
            } finally {
                serviceContainer.shutdown();
            }
        }
    });
    thread.start();
    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {

        @Override
        public void run() {
            if (serviceContainer != null) {
                serviceContainer.shutdown();
            }
        }
    }));
}
Also used : ServiceContainer(org.jboss.msc.service.ServiceContainer) SetupAction(org.jboss.as.server.deployment.SetupAction) StartException(org.jboss.msc.service.StartException)

Example 3 with ServiceContainer

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

the class AbstractDataSourceService method start.

public synchronized void start(StartContext startContext) throws StartException {
    try {
        final ServiceContainer container = startContext.getController().getServiceContainer();
        deploymentMD = getDeployer().deploy(container);
        if (deploymentMD.getCfs().length != 1) {
            throw ConnectorLogger.ROOT_LOGGER.cannotStartDs();
        }
        sqlDataSource = new WildFlyDataSource((javax.sql.DataSource) deploymentMD.getCfs()[0], jndiName.getAbsoluteJndiName());
        DS_DEPLOYER_LOGGER.debugf("Adding datasource: %s", deploymentMD.getCfJndiNames()[0]);
        CommonDeploymentService cdService = new CommonDeploymentService(deploymentMD);
        final ServiceName cdServiceName = CommonDeploymentService.getServiceName(jndiName);
        startContext.getController().getServiceContainer().addService(cdServiceName, cdService).addDependency(getServiceName(jndiName)).setInitialMode(ServiceController.Mode.ACTIVE).install();
    } catch (Throwable t) {
        throw ConnectorLogger.ROOT_LOGGER.deploymentError(t, dsName);
    }
}
Also used : ServiceContainer(org.jboss.msc.service.ServiceContainer) ServiceName(org.jboss.msc.service.ServiceName) XaDataSource(org.jboss.jca.common.api.metadata.ds.XaDataSource) DataSource(javax.sql.DataSource) CommonDataSource(org.jboss.jca.common.api.metadata.ds.CommonDataSource)

Example 4 with ServiceContainer

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

the class ServiceTransactionSetupProvider method readObject.

private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    in.defaultReadObject();
    // resolve from msc
    final ServiceContainer currentServiceContainer = System.getSecurityManager() == null ? CurrentServiceContainer.getServiceContainer() : AccessController.doPrivileged(CurrentServiceContainer.GET_ACTION);
    final ServiceController<?> serviceController = currentServiceContainer.getService(serviceName);
    if (serviceController == null) {
        throw EeLogger.ROOT_LOGGER.transactionSetupProviderServiceNotInstalled();
    }
    transactionSetupProvider = (TransactionSetupProvider) serviceController.getValue();
}
Also used : ServiceContainer(org.jboss.msc.service.ServiceContainer) CurrentServiceContainer(org.jboss.as.server.CurrentServiceContainer)

Example 5 with ServiceContainer

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

the class SSLSocketFactory method setORB.

@Override
public void setORB(ORB orb) {
    super.setORB(orb);
    ServiceContainer container = this.currentServiceContainer();
    final ServiceName serverContextServiceName = SSL_CONTEXT_RUNTIME_CAPABILITY.getCapabilityServiceName(serverSSLContextName);
    this.serverSSLContext = (SSLContext) container.getRequiredService(serverContextServiceName).getValue();
    final ServiceName clientContextServiceName = SSL_CONTEXT_RUNTIME_CAPABILITY.getCapabilityServiceName(clientSSLContextName);
    this.clientSSLContext = (SSLContext) container.getRequiredService(clientContextServiceName).getValue();
}
Also used : ServiceContainer(org.jboss.msc.service.ServiceContainer) CurrentServiceContainer(org.jboss.as.server.CurrentServiceContainer) ServiceName(org.jboss.msc.service.ServiceName)

Aggregations

ServiceContainer (org.jboss.msc.service.ServiceContainer)9 CurrentServiceContainer (org.jboss.as.server.CurrentServiceContainer)6 ServiceName (org.jboss.msc.service.ServiceName)5 StartException (org.jboss.msc.service.StartException)2 CountDownLatch (java.util.concurrent.CountDownLatch)1 Subject (javax.security.auth.Subject)1 DataSource (javax.sql.DataSource)1 ActiveMQPrincipal (org.apache.activemq.artemis.core.security.ActiveMQPrincipal)1 ActivateCallback (org.apache.activemq.artemis.core.server.ActivateCallback)1 JMSServerManagerImpl (org.apache.activemq.artemis.jms.server.impl.JMSServerManagerImpl)1 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)1 SetupAction (org.jboss.as.server.deployment.SetupAction)1 CommonDataSource (org.jboss.jca.common.api.metadata.ds.CommonDataSource)1 XaDataSource (org.jboss.jca.common.api.metadata.ds.XaDataSource)1 AbstractServiceListener (org.jboss.msc.service.AbstractServiceListener)1 ServiceController (org.jboss.msc.service.ServiceController)1 ServiceRegistry (org.jboss.msc.service.ServiceRegistry)1 AliasServiceBuilder (org.wildfly.clustering.service.AliasServiceBuilder)1 ActiveMQActivationService (org.wildfly.extension.messaging.activemq.ActiveMQActivationService)1 AuthenticationContext (org.wildfly.security.auth.client.AuthenticationContext)1