Search in sources :

Example 1 with ActiveMQActivationService

use of org.wildfly.extension.messaging.activemq.ActiveMQActivationService 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())) {

            @Override
            public void stop(ActiveMQServer server) {
            // Suppress ARTEMIS-2438
            }
        };
        activeMQServer.getValue().registerActivationFailureListener(e -> {
            StartException se = new StartException(e);
            context.failed(se);
        });
        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 && !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 LifecycleListener() {

                        @Override
                        public void handleEvent(ServiceController<?> controller, LifecycleEvent event) {
                            if (event == LifecycleEvent.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 new StartException(t);
    } finally {
        WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(oldTccl);
    }
}
Also used : ActiveMQPrincipal(org.apache.activemq.artemis.core.security.ActiveMQPrincipal) LifecycleListener(org.jboss.msc.service.LifecycleListener) CountDownLatch(java.util.concurrent.CountDownLatch) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ServiceContainer(org.jboss.msc.service.ServiceContainer) ActiveMQActivationService(org.wildfly.extension.messaging.activemq.ActiveMQActivationService) JMSServerManagerImpl(org.apache.activemq.artemis.jms.server.impl.JMSServerManagerImpl) LifecycleEvent(org.jboss.msc.service.LifecycleEvent) StartException(org.jboss.msc.service.StartException) ServiceController(org.jboss.msc.service.ServiceController) ActivateCallback(org.apache.activemq.artemis.core.server.ActivateCallback)

Aggregations

CountDownLatch (java.util.concurrent.CountDownLatch)1 ActiveMQPrincipal (org.apache.activemq.artemis.core.security.ActiveMQPrincipal)1 ActivateCallback (org.apache.activemq.artemis.core.server.ActivateCallback)1 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)1 JMSServerManagerImpl (org.apache.activemq.artemis.jms.server.impl.JMSServerManagerImpl)1 LifecycleEvent (org.jboss.msc.service.LifecycleEvent)1 LifecycleListener (org.jboss.msc.service.LifecycleListener)1 ServiceContainer (org.jboss.msc.service.ServiceContainer)1 ServiceController (org.jboss.msc.service.ServiceController)1 StartException (org.jboss.msc.service.StartException)1 ActiveMQActivationService (org.wildfly.extension.messaging.activemq.ActiveMQActivationService)1