Search in sources :

Example 1 with AbstractServiceListener

use of org.jboss.msc.service.AbstractServiceListener 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 2 with AbstractServiceListener

use of org.jboss.msc.service.AbstractServiceListener 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 3 with AbstractServiceListener

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

the class WritableServiceBasedNamingStoreTestCase method setup.

@Before
public void setup() throws Exception {
    container = ServiceContainer.Factory.create();
    installOwnerService(OWNER_FOO);
    installOwnerService(OWNER_BAR);
    final CountDownLatch latch2 = new CountDownLatch(1);
    final NamingStoreService namingStoreService = new NamingStoreService();
    container.addService(ContextNames.JAVA_CONTEXT_SERVICE_NAME, namingStoreService).setInitialMode(ServiceController.Mode.ACTIVE).addListener(new AbstractServiceListener<NamingStore>() {

        public void transition(ServiceController<? extends NamingStore> controller, ServiceController.Transition transition) {
            switch(transition) {
                case STARTING_to_UP:
                    {
                        latch2.countDown();
                        break;
                    }
                case STARTING_to_START_FAILED:
                    {
                        latch2.countDown();
                        fail("Did not install store service - " + controller.getStartException().getMessage());
                        break;
                    }
                default:
                    break;
            }
        }
    }).install();
    latch2.await(10, TimeUnit.SECONDS);
    store = (WritableServiceBasedNamingStore) namingStoreService.getValue();
}
Also used : NamingStoreService(org.jboss.as.naming.service.NamingStoreService) AbstractServiceListener(org.jboss.msc.service.AbstractServiceListener) ServiceController(org.jboss.msc.service.ServiceController) CountDownLatch(java.util.concurrent.CountDownLatch) Before(org.junit.Before)

Example 4 with AbstractServiceListener

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

the class WritableServiceBasedNamingStoreTestCase method installOwnerService.

private void installOwnerService(ServiceName owner) throws InterruptedException {
    final CountDownLatch latch1 = new CountDownLatch(1);
    container.addService(JndiNamingDependencyProcessor.serviceName(owner), new RuntimeBindReleaseService()).setInitialMode(ServiceController.Mode.ACTIVE).addListener(new AbstractServiceListener<Object>() {

        public void transition(ServiceController<?> controller, ServiceController.Transition transition) {
            switch(transition) {
                case STARTING_to_UP:
                    {
                        latch1.countDown();
                        break;
                    }
                case STARTING_to_START_FAILED:
                    {
                        latch1.countDown();
                        fail("Did not install store service - " + controller.getStartException().getMessage());
                        break;
                    }
                default:
                    break;
            }
        }
    }).install();
    latch1.await(10, TimeUnit.SECONDS);
}
Also used : AbstractServiceListener(org.jboss.msc.service.AbstractServiceListener) ServiceController(org.jboss.msc.service.ServiceController) CountDownLatch(java.util.concurrent.CountDownLatch) RuntimeBindReleaseService(org.jboss.as.naming.deployment.RuntimeBindReleaseService)

Example 5 with AbstractServiceListener

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

the class RaOperationUtil method restartIfPresent.

public static ServiceName restartIfPresent(OperationContext context, final String raName, final String id) throws OperationFailedException {
    final ServiceName raDeploymentServiceName = ConnectorServices.getDeploymentServiceName(raName, id);
    final ServiceRegistry registry = context.getServiceRegistry(true);
    ServiceController raServiceController = registry.getService(raDeploymentServiceName);
    if (raServiceController != null) {
        final org.jboss.msc.service.ServiceController.Mode originalMode = raServiceController.getMode();
        raServiceController.addListener(new AbstractServiceListener() {

            @Override
            public void transition(ServiceController controller, ServiceController.Transition transition) {
                switch(transition) {
                    case STOPPING_to_DOWN:
                        try {
                            final ServiceController<?> RaxmlController = registry.getService(ServiceName.of(ConnectorServices.RA_SERVICE, id));
                            Activation raxml = (Activation) RaxmlController.getValue();
                            ((ResourceAdapterXmlDeploymentService) controller.getService()).setRaxml(raxml);
                            controller.compareAndSetMode(ServiceController.Mode.NEVER, originalMode);
                        } finally {
                            controller.removeListener(this);
                        }
                }
            }

            @Override
            public void listenerAdded(ServiceController controller) {
                controller.setMode(ServiceController.Mode.NEVER);
            }
        });
        return raDeploymentServiceName;
    } else {
        return null;
    }
}
Also used : ServiceName(org.jboss.msc.service.ServiceName) AbstractServiceListener(org.jboss.msc.service.AbstractServiceListener) ServiceController(org.jboss.msc.service.ServiceController) Activation(org.jboss.jca.common.api.metadata.resourceadapter.Activation) ServiceRegistry(org.jboss.msc.service.ServiceRegistry)

Aggregations

AbstractServiceListener (org.jboss.msc.service.AbstractServiceListener)5 ServiceController (org.jboss.msc.service.ServiceController)5 CountDownLatch (java.util.concurrent.CountDownLatch)3 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 ContextListAndJndiViewManagedReferenceFactory (org.jboss.as.naming.ContextListAndJndiViewManagedReferenceFactory)1 ContextListManagedReferenceFactory (org.jboss.as.naming.ContextListManagedReferenceFactory)1 ManagedReferenceFactory (org.jboss.as.naming.ManagedReferenceFactory)1 ServiceBasedNamingStore (org.jboss.as.naming.ServiceBasedNamingStore)1 ValueManagedReferenceFactory (org.jboss.as.naming.ValueManagedReferenceFactory)1 BindInfo (org.jboss.as.naming.deployment.ContextNames.BindInfo)1 RuntimeBindReleaseService (org.jboss.as.naming.deployment.RuntimeBindReleaseService)1 BinderService (org.jboss.as.naming.service.BinderService)1 NamingStoreService (org.jboss.as.naming.service.NamingStoreService)1 Activation (org.jboss.jca.common.api.metadata.resourceadapter.Activation)1 ServiceContainer (org.jboss.msc.service.ServiceContainer)1 ServiceName (org.jboss.msc.service.ServiceName)1 ServiceRegistry (org.jboss.msc.service.ServiceRegistry)1 StartException (org.jboss.msc.service.StartException)1