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;
}
}
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();
}
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);
}
Aggregations