use of org.jboss.msc.service.ServiceContainer 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.ServiceContainer in project wildfly by wildfly.
the class ApplicationClientStartService method start.
@Override
public synchronized void start(final StartContext context) throws StartException {
final ServiceContainer serviceContainer = context.getController().getServiceContainer();
thread = new Thread(new Runnable() {
@Override
public void run() {
final ClassLoader oldTccl = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
try {
try {
WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(classLoader);
applicationClientDeploymentServiceInjectedValue.getValue().getDeploymentCompleteLatch().await();
NamespaceContextSelector.setDefault(namespaceContextSelectorInjectedValue);
try {
//perform any additional setup that may be needed
for (SetupAction action : setupActions) {
action.setup(Collections.<String, Object>emptyMap());
}
//do static injection etc
instance = applicationClientComponent.getValue().createInstance();
mainMethod.invoke(null, new Object[] { parameters });
} finally {
final ListIterator<SetupAction> iterator = setupActions.listIterator(setupActions.size());
Throwable error = null;
while (iterator.hasPrevious()) {
SetupAction action = iterator.previous();
try {
action.teardown(Collections.<String, Object>emptyMap());
} catch (Throwable e) {
error = e;
}
}
if (error != null) {
throw new RuntimeException(error);
}
}
} catch (Exception e) {
ROOT_LOGGER.exceptionRunningAppClient(e, e.getClass().getSimpleName());
} finally {
WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(oldTccl);
}
} finally {
serviceContainer.shutdown();
}
}
});
thread.start();
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
@Override
public void run() {
if (serviceContainer != null) {
serviceContainer.shutdown();
}
}
}));
}
use of org.jboss.msc.service.ServiceContainer in project wildfly by wildfly.
the class AbstractDataSourceService method start.
public synchronized void start(StartContext startContext) throws StartException {
try {
final ServiceContainer container = startContext.getController().getServiceContainer();
deploymentMD = getDeployer().deploy(container);
if (deploymentMD.getCfs().length != 1) {
throw ConnectorLogger.ROOT_LOGGER.cannotStartDs();
}
sqlDataSource = new WildFlyDataSource((javax.sql.DataSource) deploymentMD.getCfs()[0], jndiName.getAbsoluteJndiName());
DS_DEPLOYER_LOGGER.debugf("Adding datasource: %s", deploymentMD.getCfJndiNames()[0]);
CommonDeploymentService cdService = new CommonDeploymentService(deploymentMD);
final ServiceName cdServiceName = CommonDeploymentService.getServiceName(jndiName);
startContext.getController().getServiceContainer().addService(cdServiceName, cdService).addDependency(getServiceName(jndiName)).setInitialMode(ServiceController.Mode.ACTIVE).install();
} catch (Throwable t) {
throw ConnectorLogger.ROOT_LOGGER.deploymentError(t, dsName);
}
}
use of org.jboss.msc.service.ServiceContainer in project wildfly by wildfly.
the class ServiceTransactionSetupProvider method readObject.
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
// resolve from msc
final ServiceContainer currentServiceContainer = System.getSecurityManager() == null ? CurrentServiceContainer.getServiceContainer() : AccessController.doPrivileged(CurrentServiceContainer.GET_ACTION);
final ServiceController<?> serviceController = currentServiceContainer.getService(serviceName);
if (serviceController == null) {
throw EeLogger.ROOT_LOGGER.transactionSetupProviderServiceNotInstalled();
}
transactionSetupProvider = (TransactionSetupProvider) serviceController.getValue();
}
use of org.jboss.msc.service.ServiceContainer in project wildfly by wildfly.
the class SSLSocketFactory method setORB.
@Override
public void setORB(ORB orb) {
super.setORB(orb);
ServiceContainer container = this.currentServiceContainer();
final ServiceName serverContextServiceName = SSL_CONTEXT_RUNTIME_CAPABILITY.getCapabilityServiceName(serverSSLContextName);
this.serverSSLContext = (SSLContext) container.getRequiredService(serverContextServiceName).getValue();
final ServiceName clientContextServiceName = SSL_CONTEXT_RUNTIME_CAPABILITY.getCapabilityServiceName(clientSSLContextName);
this.clientSSLContext = (SSLContext) container.getRequiredService(clientContextServiceName).getValue();
}
Aggregations