Search in sources :

Example 21 with LifecycleListener

use of org.jboss.msc.service.LifecycleListener 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();
        final UninterruptibleCountDownLatch latch = new UninterruptibleCountDownLatch(1);
        raServiceController.addListener(new LifecycleListener() {

            @Override
            public void handleEvent(ServiceController controller, LifecycleEvent event) {
                latch.awaitUninterruptibly();
                if (event == LifecycleEvent.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);
                    }
                }
            }
        });
        try {
            raServiceController.setMode(ServiceController.Mode.NEVER);
        } finally {
            latch.countDown();
        }
        return raDeploymentServiceName;
    } else {
        return null;
    }
}
Also used : UninterruptibleCountDownLatch(org.jboss.as.controller.UninterruptibleCountDownLatch) ServiceName(org.jboss.msc.service.ServiceName) LifecycleEvent(org.jboss.msc.service.LifecycleEvent) ServiceController(org.jboss.msc.service.ServiceController) Activation(org.jboss.jca.common.api.metadata.resourceadapter.Activation) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) LifecycleListener(org.jboss.msc.service.LifecycleListener)

Example 22 with LifecycleListener

use of org.jboss.msc.service.LifecycleListener 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 LifecycleListener() {

        public void handleEvent(ServiceController<?> controller, LifecycleEvent event) {
            switch(event) {
                case UP:
                    {
                        latch2.countDown();
                        break;
                    }
                case 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) LifecycleEvent(org.jboss.msc.service.LifecycleEvent) ServiceController(org.jboss.msc.service.ServiceController) LifecycleListener(org.jboss.msc.service.LifecycleListener) CountDownLatch(java.util.concurrent.CountDownLatch) Before(org.junit.Before)

Example 23 with LifecycleListener

use of org.jboss.msc.service.LifecycleListener 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 LifecycleListener() {

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

Aggregations

LifecycleListener (org.jboss.msc.service.LifecycleListener)23 LifecycleEvent (org.jboss.msc.service.LifecycleEvent)22 ServiceName (org.jboss.msc.service.ServiceName)11 CountDownLatch (java.util.concurrent.CountDownLatch)9 ContextNames (org.jboss.as.naming.deployment.ContextNames)8 ServiceController (org.jboss.msc.service.ServiceController)7 BinderService (org.jboss.as.naming.service.BinderService)6 ServiceBasedNamingStore (org.jboss.as.naming.ServiceBasedNamingStore)5 ServiceBuilder (org.jboss.msc.service.ServiceBuilder)5 ServiceRegistry (org.jboss.msc.service.ServiceRegistry)3 ExecutorService (java.util.concurrent.ExecutorService)2 DataSourceStatisticsService (org.jboss.as.connector.services.datasources.statistics.DataSourceStatisticsService)2 DataSourceReferenceFactoryService (org.jboss.as.connector.subsystems.datasources.DataSourceReferenceFactoryService)2 ContextListAndJndiViewManagedReferenceFactory (org.jboss.as.naming.ContextListAndJndiViewManagedReferenceFactory)2 ManagedReferenceFactory (org.jboss.as.naming.ManagedReferenceFactory)2 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)2 Module (org.jboss.modules.Module)2 ServiceContainer (org.jboss.msc.service.ServiceContainer)2 StartException (org.jboss.msc.service.StartException)2 CompletableFuture (java.util.concurrent.CompletableFuture)1