Search in sources :

Example 1 with UninterruptibleCountDownLatch

use of org.jboss.as.controller.UninterruptibleCountDownLatch 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)

Aggregations

UninterruptibleCountDownLatch (org.jboss.as.controller.UninterruptibleCountDownLatch)1 Activation (org.jboss.jca.common.api.metadata.resourceadapter.Activation)1 LifecycleEvent (org.jboss.msc.service.LifecycleEvent)1 LifecycleListener (org.jboss.msc.service.LifecycleListener)1 ServiceController (org.jboss.msc.service.ServiceController)1 ServiceName (org.jboss.msc.service.ServiceName)1 ServiceRegistry (org.jboss.msc.service.ServiceRegistry)1