use of org.jboss.msc.service.ServiceController in project wildfly by wildfly.
the class EEJndiViewExtension method execute.
public void execute(final JndiViewExtensionContext context) throws OperationFailedException {
final ModelNode applicationsNode = context.getResult().get("applications");
final ServiceRegistry serviceRegistry = context.getOperationContext().getServiceRegistry(false);
final Set<Resource.ResourceEntry> deploymentResource = context.getOperationContext().readResourceFromRoot(PathAddress.EMPTY_ADDRESS, false).getChildren(DEPLOYMENT);
for (final Resource.ResourceEntry entry : deploymentResource) {
final ServiceController<?> deploymentUnitServiceController = serviceRegistry.getService(ServiceName.JBOSS.append("deployment", "unit", entry.getName()));
if (deploymentUnitServiceController != null) {
final ModelNode deploymentNode = applicationsNode.get(entry.getName());
final DeploymentUnit deploymentUnit = DeploymentUnit.class.cast(deploymentUnitServiceController.getValue());
final String appName = cleanName(deploymentUnit.getName());
final ServiceName appContextName = ContextNames.contextServiceNameOfApplication(appName);
final ServiceController<?> appContextController = serviceRegistry.getService(appContextName);
if (appContextController != null) {
final NamingStore appStore = NamingStore.class.cast(appContextController.getValue());
try {
context.addEntries(deploymentNode.get("java:app"), new NamingContext(appStore, null));
} catch (NamingException e) {
throw new OperationFailedException(e, new ModelNode().set(EeLogger.ROOT_LOGGER.failedToRead("java:app", appName)));
}
}
if (DeploymentTypeMarker.isType(DeploymentType.EAR, deploymentUnit)) {
final List<ResourceRoot> roots = deploymentUnit.getAttachmentList(org.jboss.as.server.deployment.Attachments.RESOURCE_ROOTS);
if (roots != null)
for (ResourceRoot root : roots) {
if (SubDeploymentMarker.isSubDeployment(root)) {
final ResourceRoot parentRoot = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.DEPLOYMENT_ROOT);
final String relativePath = root.getRoot().getPathNameRelativeTo(parentRoot.getRoot());
final ServiceName subDeploymentServiceName = Services.deploymentUnitName(deploymentUnit.getName(), relativePath);
final ServiceController<?> subDeploymentController = serviceRegistry.getService(subDeploymentServiceName);
if (subDeploymentController != null) {
final DeploymentUnit subDeploymentUnit = DeploymentUnit.class.cast(subDeploymentController.getValue());
handleModule(context, subDeploymentUnit, deploymentNode.get("modules"), serviceRegistry);
}
}
}
} else {
handleModule(context, deploymentUnit, deploymentNode.get("modules"), serviceRegistry);
}
}
}
}
use of org.jboss.msc.service.ServiceController in project wildfly by wildfly.
the class SingletonComponent method instantiateComponentInstance.
@Override
protected BasicComponentInstance instantiateComponentInstance(Interceptor preDestroyInterceptor, Map<Method, Interceptor> methodInterceptors, Map<Object, Object> context) {
// synchronized from getComponentInstance
assert Thread.holdsLock(creationLock);
if (dependsOn != null) {
for (ServiceName serviceName : dependsOn) {
final ServiceController<Component> service = (ServiceController<Component>) currentServiceContainer().getRequiredService(serviceName);
final Component component = service.getValue();
if (component instanceof SingletonComponent) {
((SingletonComponent) component).getComponentInstance();
}
}
}
return new SingletonComponentInstance(this, preDestroyInterceptor, methodInterceptors);
}
use of org.jboss.msc.service.ServiceController in project wildfly by wildfly.
the class ExceptionLoggingWriteHandler method updateOrCreateDefaultExceptionLoggingEnabledService.
void updateOrCreateDefaultExceptionLoggingEnabledService(final OperationContext context, final ModelNode model) throws OperationFailedException {
final boolean enabled = EJB3SubsystemRootResourceDefinition.LOG_EJB_EXCEPTIONS.resolveModelAttribute(context, model).asBoolean();
final ServiceName serviceName = LoggingInterceptor.LOGGING_ENABLED_SERVICE_NAME;
final ServiceRegistry registry = context.getServiceRegistry(true);
final ServiceController sc = registry.getService(serviceName);
if (sc != null) {
final AtomicBoolean value = (AtomicBoolean) sc.getValue();
value.set(enabled);
} else {
// create and install the service
final ValueService<AtomicBoolean> service = new ValueService<>(new ImmediateValue<>(new AtomicBoolean(enabled)));
context.getServiceTarget().addService(serviceName, service).install();
}
}
use of org.jboss.msc.service.ServiceController in project wildfly by wildfly.
the class NamingBindingResourceDefinition method registerOperations.
@Override
public void registerOperations(ManagementResourceRegistration resourceRegistration) {
super.registerOperations(resourceRegistration);
SimpleOperationDefinitionBuilder builder = new SimpleOperationDefinitionBuilder(NamingSubsystemModel.REBIND, getResourceDescriptionResolver()).addParameter(BINDING_TYPE).addParameter(TYPE).addParameter(VALUE).addParameter(CLASS).addParameter(MODULE).addParameter(LOOKUP).addParameter(ENVIRONMENT);
resourceRegistration.registerOperationHandler(builder.build(), new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
context.addStep(new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
validateResourceModel(operation, false);
Resource resource = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS);
ModelNode model = resource.getModel();
for (AttributeDefinition attr : ATTRIBUTES) {
attr.validateAndSet(operation, model);
}
context.addStep(new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
final String name = context.getCurrentAddressValue();
final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(name);
ServiceController<ManagedReferenceFactory> service = (ServiceController<ManagedReferenceFactory>) context.getServiceRegistry(false).getService(bindInfo.getBinderServiceName());
if (service == null) {
context.reloadRequired();
return;
}
NamingBindingAdd.INSTANCE.doRebind(context, operation, (BinderService) service.getService());
}
}, OperationContext.Stage.RUNTIME);
}
}, OperationContext.Stage.MODEL);
}
});
}
use of org.jboss.msc.service.ServiceController in project wildfly by wildfly.
the class WeldStartService method start.
@Override
public void start(final StartContext context) throws StartException {
/*
* Weld service restarts are not supported. Therefore, if we detect that Weld is being restarted we
* trigger restart of the entire deployment.
*/
if (runOnce.get()) {
ServiceController<?> controller = context.getController().getServiceContainer().getService(deploymentServiceName);
controller.addListener(new AbstractServiceListener<Object>() {
@Override
public void transition(final ServiceController<?> controller, final ServiceController.Transition transition) {
if (transition.getAfter().equals(ServiceController.Substate.DOWN)) {
controller.setMode(Mode.ACTIVE);
controller.removeListener(this);
}
}
});
controller.setMode(Mode.NEVER);
return;
}
runOnce.set(true);
ClassLoader oldTccl = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
try {
for (SetupAction action : setupActions) {
action.setup(null);
}
WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(classLoader);
bootstrap.getValue().getBootstrap().startInitialization();
bootstrap.getValue().getBootstrap().deployBeans();
bootstrap.getValue().getBootstrap().validateBeans();
bootstrap.getValue().getBootstrap().endInitialization();
} finally {
for (SetupAction action : setupActions) {
try {
action.teardown(null);
} catch (Exception e) {
WeldLogger.DEPLOYMENT_LOGGER.exceptionClearingThreadState(e);
}
}
WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(oldTccl);
}
}
Aggregations