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