use of org.jboss.msc.service.ServiceController in project wildfly by wildfly.
the class AbstractUpdateJndiHandler method execute.
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
JNDI_BINDING.validateOperation(operation);
final String jndiName = JNDI_BINDING.resolveModelAttribute(context, operation).asString();
final ModelNode entries = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS).getModel().get(CommonAttributes.DESTINATION_ENTRIES.getName());
if (addOperation) {
for (ModelNode entry : entries.asList()) {
if (jndiName.equals(entry.asString())) {
throw new OperationFailedException(ROOT_LOGGER.jndiNameAlreadyRegistered(jndiName));
}
}
entries.add(jndiName);
} else {
ModelNode updatedEntries = new ModelNode();
boolean updated = false;
for (ModelNode entry : entries.asList()) {
if (jndiName.equals(entry.asString())) {
if (entries.asList().size() == 1) {
throw new OperationFailedException(ROOT_LOGGER.canNotRemoveLastJNDIName(jndiName));
}
updated = true;
} else {
updatedEntries.add(entry);
}
}
if (!updated) {
throw MessagingLogger.ROOT_LOGGER.canNotRemoveUnknownEntry(jndiName);
}
context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS).getModel().get(CommonAttributes.DESTINATION_ENTRIES.getName()).set(updatedEntries);
}
if (context.isNormalServer()) {
if (rollbackOperationIfServerNotActive(context, operation)) {
return;
}
context.addStep(new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
final String resourceName = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR)).getLastElement().getValue();
final ServiceName serviceName = MessagingServices.getActiveMQServiceName(PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)));
final ServiceName jmsManagerServiceName = JMSServices.getJmsManagerBaseServiceName(serviceName);
final ServiceController<?> jmsServerService = context.getServiceRegistry(false).getService(jmsManagerServiceName);
if (jmsServerService != null) {
JMSServerManager jmsServerManager = JMSServerManager.class.cast(jmsServerService.getValue());
if (jmsServerManager == null) {
PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
throw ControllerLogger.ROOT_LOGGER.managementResourceNotFound(address);
}
try {
if (addOperation) {
addJndiName(jmsServerManager, resourceName, jndiName);
} else {
removeJndiName(jmsServerManager, resourceName, jndiName);
}
} catch (Exception e) {
context.getFailureDescription().set(e.getLocalizedMessage());
}
}
if (!context.hasFailureDescription()) {
context.getResult();
}
context.completeStep(new OperationContext.RollbackHandler() {
@Override
public void handleRollback(OperationContext context, ModelNode operation) {
if (jmsServerService != null) {
JMSServerManager jmsServerManager = JMSServerManager.class.cast(jmsServerService.getValue());
try {
if (addOperation) {
removeJndiName(jmsServerManager, resourceName, jndiName);
} else {
addJndiName(jmsServerManager, resourceName, jndiName);
}
} catch (Exception e) {
context.getFailureDescription().set(e.getLocalizedMessage());
}
}
}
});
}
}, OperationContext.Stage.RUNTIME);
}
}
use of org.jboss.msc.service.ServiceController in project wildfly by wildfly.
the class StackOperationExecutor method execute.
@Override
public ModelNode execute(OperationContext context, Operation<ChannelFactory> operation) throws OperationFailedException {
String stackName = context.getCurrentAddressValue();
ServiceRegistry registry = context.getServiceRegistry(false);
ServiceName serviceName = JGroupsRequirement.CHANNEL_FACTORY.getServiceName(context, stackName);
try {
ServiceController<ChannelFactory> controller = ServiceContainerHelper.getService(registry, serviceName);
ServiceController.Mode mode = controller.getMode();
controller.setMode(ServiceController.Mode.ACTIVE);
try {
return operation.execute(controller.awaitValue());
} finally {
controller.setMode(mode);
}
} catch (InterruptedException e) {
throw new OperationFailedException(e.getLocalizedMessage(), e);
}
}
use of org.jboss.msc.service.ServiceController in project wildfly by wildfly.
the class JMSDestinationDefinitionInjectionSource method inject.
private <D extends Destination> void inject(ServiceBuilder<?> serviceBuilder, Injector<ManagedReferenceFactory> injector, Service<D> destinationService) {
final ContextListAndJndiViewManagedReferenceFactory referenceFactoryService = new MessagingJMSDestinationManagedReferenceFactory(destinationService);
serviceBuilder.addInjection(injector, referenceFactoryService).addListener(new AbstractServiceListener<Object>() {
public void transition(final ServiceController<? extends Object> controller, final ServiceController.Transition transition) {
switch(transition) {
case STARTING_to_UP:
{
ROOT_LOGGER.boundJndiName(jndiName);
break;
}
case START_REQUESTED_to_DOWN:
{
ROOT_LOGGER.unboundJndiName(jndiName);
break;
}
case REMOVING_to_REMOVED:
{
ROOT_LOGGER.debugf("Removed messaging object [%s]", jndiName);
break;
}
}
}
});
}
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);
}
}
use of org.jboss.msc.service.ServiceController in project wildfly by wildfly.
the class AdministeredObjectDefinitionInjectionSource method getResourceValue.
public void getResourceValue(final ResolutionContext context, final ServiceBuilder<?> serviceBuilder, final DeploymentPhaseContext phaseContext, final Injector<ManagedReferenceFactory> injector) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
String raId = resourceAdapter;
if (resourceAdapter.startsWith("#")) {
raId = deploymentUnit.getParent().getName() + raId;
}
String deployerServiceName = raId;
if (!raId.endsWith(".rar")) {
deployerServiceName = deployerServiceName + ".rar";
raId = deployerServiceName;
}
SUBSYSTEM_RA_LOGGER.debugf("@AdministeredObjectDefinition: %s for %s binding to %s ", className, resourceAdapter, jndiName);
ContextNames.BindInfo bindInfo = ContextNames.bindInfoForEnvEntry(context.getApplicationName(), context.getModuleName(), context.getComponentName(), !context.isCompUsesModule(), jndiName);
DirectAdminObjectActivatorService service = new DirectAdminObjectActivatorService(jndiName, className, resourceAdapter, raId, properties, module, bindInfo);
ServiceName serviceName = DirectAdminObjectActivatorService.SERVICE_NAME_BASE.append(jndiName);
phaseContext.getServiceTarget().addService(serviceName, service).addDependency(ConnectorServices.IRONJACAMAR_MDR, AS7MetadataRepository.class, service.getMdrInjector()).addDependency(ConnectorServices.RESOURCE_ADAPTER_DEPLOYER_SERVICE_PREFIX.append(deployerServiceName)).setInitialMode(ServiceController.Mode.ACTIVE).install();
serviceBuilder.addDependency(AdminObjectReferenceFactoryService.SERVICE_NAME_BASE.append(bindInfo.getBinderServiceName()), ManagedReferenceFactory.class, injector);
serviceBuilder.addListener(new AbstractServiceListener<Object>() {
public void transition(final ServiceController<? extends Object> controller, final ServiceController.Transition transition) {
switch(transition) {
case STARTING_to_UP:
{
DEPLOYMENT_CONNECTOR_LOGGER.adminObjectAnnotation(jndiName);
break;
}
case STOPPING_to_DOWN:
{
DEPLOYMENT_CONNECTOR_LOGGER.unboundJca("AdminObject", jndiName);
break;
}
case REMOVING_to_REMOVED:
{
DEPLOYMENT_CONNECTOR_LOGGER.debugf("Removed JCA AdminObject [%s]", jndiName);
}
}
}
});
}
Aggregations