Skip to content

Commit

Permalink
[JBAS-9010] Proper deployment state tracking part 2: Update operation…
Browse files Browse the repository at this point in the history
…s to rely on controller to discover the end of processing
  • Loading branch information
dmlloyd committed Apr 18, 2011
1 parent ba855c3 commit 96fb0f5
Show file tree
Hide file tree
Showing 61 changed files with 195 additions and 248 deletions.
Expand Up @@ -340,8 +340,8 @@ public void execute(RuntimeTaskContext context) throws OperationFailedException
for (Map.Entry<String, Injector<String>> injector: locationInjectors) {
builder.addDependency(AbstractPathService.pathNameOf(injector.getKey()), String.class, injector.getValue());
}
builder.addListener(new ResultHandler.ServiceStartListener(resultHandler));
builder.install();
resultHandler.handleResultComplete();
}

private CacheStoreConfig createCacheLoaderConfig(ModelNode store, List<Map.Entry<String, Injector<String>>> injectors) {
Expand Down
Expand Up @@ -64,10 +64,9 @@ public OperationResult execute(OperationContext context, ModelNode operation, fi
public void execute(RuntimeTaskContext context) throws OperationFailedException {
ServiceController<?> service = context.getServiceRegistry().getService(EmbeddedCacheManagerService.getServiceName(name));
if (service != null) {
service.addListener(new ResultHandler.ServiceRemoveListener(resultHandler));
} else {
resultHandler.handleResultComplete();
service.setMode(ServiceController.Mode.REMOVE);
}
resultHandler.handleResultComplete();
}
};
runtime.setRuntimeTask(task);
Expand Down
Expand Up @@ -88,16 +88,15 @@ public void execute(RuntimeTaskContext context) throws OperationFailedException
ValueService<EmbeddedCacheManager> service = new ValueService<EmbeddedCacheManager>(container);
context.getServiceTarget().addService(EmbeddedCacheManagerService.getServiceName(), service)
.addDependency(EmbeddedCacheManagerService.getServiceName(defaultContainer), EmbeddedCacheManager.class, container)
.addListener(new ResultHandler.ServiceStartListener(resultHandler))
.install();
}
};

runtime.setRuntimeTask(task);
} else {
resultHandler.handleResultComplete();
}

return new BasicOperationResult(Util.getResourceRemoveOperation(operation.require(ModelDescriptionConstants.OP_ADDR)));
BasicOperationResult operationResult = new BasicOperationResult(Util.getResourceRemoveOperation(operation.require(ModelDescriptionConstants.OP_ADDR)));
resultHandler.handleResultComplete();
return operationResult;
}
}
Expand Up @@ -88,16 +88,15 @@ public void execute(RuntimeTaskContext context) throws OperationFailedException
ValueService<ChannelFactory> service = new ValueService<ChannelFactory>(factory);
context.getServiceTarget().addService(ChannelFactoryService.getServiceName(), service)
.addDependency(ChannelFactoryService.getServiceName(stack), ChannelFactory.class, factory)
.addListener(new ResultHandler.ServiceStartListener(resultHandler))
.install();
}
};

runtime.setRuntimeTask(task);
} else {
resultHandler.handleResultComplete();
}

return new BasicOperationResult(Util.getResourceRemoveOperation(operation.require(ModelDescriptionConstants.OP_ADDR)));
BasicOperationResult operationResult = new BasicOperationResult(Util.getResourceRemoveOperation(operation.require(ModelDescriptionConstants.OP_ADDR)));
resultHandler.handleResultComplete();
return operationResult;
}
}
Expand Up @@ -142,8 +142,8 @@ public void execute(RuntimeTaskContext context) throws OperationFailedException
}
ServiceBuilder<ChannelFactory> builder = new ChannelFactoryService(name, stackConfig).build(context.getServiceTarget());
injections.addDependencies(builder);
builder.addListener(new ResultHandler.ServiceStartListener(resultHandler));
builder.install();
resultHandler.handleResultComplete();
}

private void process(ModelNode protocol, ProtocolConfigurationImpl protocolConfig, InjectionCollector injections) {
Expand Down
Expand Up @@ -63,10 +63,9 @@ public OperationResult execute(OperationContext context, ModelNode operation, fi
public void execute(RuntimeTaskContext context) throws OperationFailedException {
ServiceController<?> service = context.getServiceRegistry().getService(ChannelFactoryService.getServiceName(name));
if (service != null) {
service.addListener(new ResultHandler.ServiceRemoveListener(resultHandler));
} else {
resultHandler.handleResultComplete();
service.setMode(ServiceController.Mode.REMOVE);
}
resultHandler.handleResultComplete();
}
};
runtime.setRuntimeTask(task);
Expand Down
Expand Up @@ -65,10 +65,9 @@ public OperationResult execute(final OperationContext context, final ModelNode o
public void execute(RuntimeTaskContext context) throws OperationFailedException {
final ServiceController<?> controller = context.getServiceRegistry().getService(ConnectorServices.CONNECTOR_CONFIG_SERVICE);
if (controller != null) {
controller.addListener(new ResultHandler.ServiceRemoveListener(resultHandler));
} else {
resultHandler.handleResultComplete();
controller.setMode(ServiceController.Mode.REMOVE);
}
resultHandler.handleResultComplete();
}
});
} else {
Expand Down
Expand Up @@ -144,14 +144,13 @@ public void serviceRemoved(ServiceController<?> serviceController) {
if (enabled) {
dataSourceServiceBuilder.setInitialMode(ServiceController.Mode.ACTIVE).install();
referenceBuilder.setInitialMode(ServiceController.Mode.ACTIVE).install();
binderBuilder.setInitialMode(ServiceController.Mode.ACTIVE)
.addListener(new ResultHandler.ServiceStartListener(resultHandler)).install();
binderBuilder.setInitialMode(ServiceController.Mode.ACTIVE);
} else {
dataSourceServiceBuilder.setInitialMode(ServiceController.Mode.NEVER).install();
referenceBuilder.setInitialMode(ServiceController.Mode.NEVER).install();
binderBuilder.setInitialMode(ServiceController.Mode.NEVER).install();
resultHandler.handleResultComplete();
}
resultHandler.handleResultComplete();
}
});
} else {
Expand Down
Expand Up @@ -90,10 +90,9 @@ public void execute(RuntimeTaskContext context) throws OperationFailedException
final ServiceName dataSourceServiceName = AbstractDataSourceService.SERVICE_NAME_BASE.append(jndiName);
final ServiceController<?> dataSourceController = registry.getService(dataSourceServiceName);
if (dataSourceController != null) {
dataSourceController.addListener(new ResultHandler.ServiceRemoveListener(resultHandler));
} else {
resultHandler.handleResultComplete();
dataSourceController.setMode(ServiceController.Mode.REMOVE);
}
resultHandler.handleResultComplete();
}
});
} else {
Expand Down
Expand Up @@ -74,7 +74,6 @@ public void execute(final RuntimeTaskContext context) throws OperationFailedExce
if (dataSourceController != null) {
if (!ServiceController.State.UP.equals(dataSourceController.getState())) {
dataSourceController.setMode(ServiceController.Mode.ACTIVE);
dataSourceController.addListener(new ResultHandler.ServiceStartListener(resultHandler));
} else {
throw new OperationFailedException(new ModelNode().set("Data-source service [" + jndiName + "] is already started"));
}
Expand All @@ -93,6 +92,7 @@ public void execute(final RuntimeTaskContext context) throws OperationFailedExce
if (binderController != null && !ServiceController.State.UP.equals(binderController.getState())) {
binderController.setMode(ServiceController.Mode.ACTIVE);
}
resultHandler.handleResultComplete();
}
});
} else {
Expand Down
Expand Up @@ -85,7 +85,7 @@ public void execute(final RuntimeTaskContext context) throws OperationFailedExce
final ServiceName serviceName = ServiceName.JBOSS.append("jdbc-driver", driver.getClass().getName(), Integer.toString(majorVersion), Integer.toString(minorVersion));
final ServiceController<?> controller = registry.getService(serviceName);
if (controller != null) {
controller.addListener(new ResultHandler.ServiceRemoveListener(resultHandler));
controller.setMode(ServiceController.Mode.REMOVE);
}
}
resultHandler.handleResultComplete();
Expand Down
Expand Up @@ -23,9 +23,6 @@
package org.jboss.as.controller;

import org.jboss.dmr.ModelNode;
import org.jboss.msc.service.AbstractServiceListener;
import org.jboss.msc.service.ServiceController;
import org.jboss.msc.service.StartException;

/**
* @author <a href="mailto:david.lloyd@redhat.com">David M. Lloyd</a>
Expand Down Expand Up @@ -59,66 +56,4 @@ public interface ResultHandler {
* Signify that this operation was cancelled.
*/
void handleCancellation();

/**
* A listener which invokes a {@link ResultHandler} when the service it is attached to has been removed.
*
*/
class ServiceRemoveListener extends AbstractServiceListener<Object> {
private final ResultHandler resultHandler;

public ServiceRemoveListener(final ResultHandler resultHandler) {
this.resultHandler = resultHandler;
}

@Override
public void listenerAdded(final ServiceController<?> controller) {
controller.setMode(ServiceController.Mode.REMOVE);
}

@Override
public void serviceRemoved(final ServiceController<?> controller) {
resultHandler.handleResultComplete();
}
}

/**
* A listener which invokes a {@link ResultHandler} when the service it is attached to has been added and
* started successfully.
*
*/
class ServiceStartListener extends AbstractServiceListener<Object> {
private final ResultHandler resultHandler;

public ServiceStartListener(final ResultHandler resultHandler) {
this.resultHandler = resultHandler;
}

@Override
public void serviceStarted(final ServiceController<?> controller) {
try {
resultHandler.handleResultComplete();
} finally {
controller.removeListener(this);
}
}

@Override
public void serviceFailed(final ServiceController<?> controller, final StartException reason) {
try {
resultHandler.handleFailed(new ModelNode().set(reason.getLocalizedMessage()));
} finally {
controller.removeListener(this);
}
}

@Override
public void serviceRemoved(final ServiceController<?> controller) {
try {
resultHandler.handleCancellation();
} finally {
controller.removeListener(this);
}
}
}
}
Expand Up @@ -50,7 +50,7 @@ public void activate(ServiceActivatorContext serviceActivatorContext) throws Ser
final Injector<Context> injector = rebindService.getLookupContextInjector();

serviceTarget.addService(ServiceName.JBOSS.append("BeanWithSimpleInjected", "rebind"), rebindService)
.addDependency(ServiceName.JBOSS.append("deployment", "unit","managedbean-example.ear", "managedbean-example.jar", "component", "BeanWithSimpleInjected","START"))
.addDependency(ServiceName.JBOSS.append("deployment", "subunit","managedbean-example.ear", "managedbean-example.jar", "component", "BeanWithSimpleInjected","START"))
.addDependency(ContextNames.contextServiceNameOfModule("managedbean-example", "managedbean-example"), NamingStore.class, new Injector<NamingStore>() {
public void inject(final NamingStore value) throws InjectionException {
try {
Expand Down
Expand Up @@ -90,10 +90,9 @@ public void execute(RuntimeTaskContext context) throws OperationFailedException
final ServiceController<?> controller = context.getServiceRegistry()
.getService(DeploymentScannerService.getServiceName(name));
if (controller != null) {
controller.addListener(new ResultHandler.ServiceRemoveListener(resultHandler));
} else {
resultHandler.handleResultComplete();
controller.setMode(ServiceController.Mode.REMOVE);
}
resultHandler.handleResultComplete();
}
});
} else {
Expand Down
Expand Up @@ -26,6 +26,7 @@
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.as.server.deployment.Services;

import static org.jboss.as.server.deployment.Attachments.NEXT_PHASE_DEPS;
import static org.jboss.as.server.deployment.Attachments.SUB_DEPLOYMENTS;
Expand All @@ -42,7 +43,7 @@ public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentU
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
// Make sure the next phase of this EAR depends on this phase of not just the EAR but also all subdeployments
for (DeploymentUnit subdeployment : deploymentUnit.getAttachmentList(SUB_DEPLOYMENTS)) {
phaseContext.addToAttachmentList(NEXT_PHASE_DEPS, subdeployment.getServiceName().append(phaseContext.getPhase().name()));
phaseContext.addToAttachmentList(NEXT_PHASE_DEPS, Services.deploymentUnitName(deploymentUnit.getName(), subdeployment.getName(), phaseContext.getPhase()));
}
}
}
Expand Down
Expand Up @@ -26,6 +26,7 @@
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.as.server.deployment.Phase;
import org.jboss.as.server.deployment.Services;
import org.jboss.as.server.deployment.module.ResourceRoot;
import org.jboss.metadata.ear.spec.Ear6xMetaData;
import org.jboss.metadata.ear.spec.EarMetaData;
Expand Down Expand Up @@ -59,7 +60,7 @@ public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitPro
}
}
if(previous != null) {
final ServiceName serviceName = deploymentUnit.getParent().getServiceName().append(previous.getFileName());
final ServiceName serviceName = Services.deploymentUnitName(deploymentUnit.getParent().getName(), previous.getFileName());
phaseContext.addToAttachmentList(org.jboss.as.server.deployment.Attachments.NEXT_PHASE_DEPS,serviceName.append(Phase.INSTALL.name()));
}
}
Expand Down
@@ -1,6 +1,6 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2010, Red Hat, Inc., and individual contributors
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
Expand Down Expand Up @@ -103,14 +103,13 @@ public void execute(RuntimeTaskContext context) throws OperationFailedException
.addInjection(service.getPortInjector(), port)
.addInjection(service.getExecutorServiceInjector(), Executors.newCachedThreadPool(new JBossThreadFactory(new ThreadGroup("HttpManagementService-threads"), Boolean.FALSE, null, "%G - %t", null, null, AccessController.getContext())))
.setInitialMode(ServiceController.Mode.ACTIVE)
.addListener(new ResultHandler.ServiceStartListener(resultHandler))
.install();
}
});
} else {
resultHandler.handleResultComplete();
}
return new BasicOperationResult(compensatingOperation);
BasicOperationResult operationResult = new BasicOperationResult(compensatingOperation);
resultHandler.handleResultComplete();
return operationResult;
}

/** {@inheritDoc} */
Expand Down
Expand Up @@ -47,10 +47,9 @@ public void execute(RuntimeTaskContext context) throws OperationFailedException
final ServiceController<?> controller = context.getServiceRegistry()
.getService(NetworkInterfaceService.JBOSS_NETWORK_INTERFACE.append(name));
if (controller != null) {
controller.addListener(new ResultHandler.ServiceRemoveListener(resultHandler));
} else {
resultHandler.handleResultComplete();
controller.setMode(ServiceController.Mode.REMOVE);
}
resultHandler.handleResultComplete();
}
});
} else {
Expand Down
5 changes: 2 additions & 3 deletions jmx/src/main/java/org/jboss/as/jmx/JMXConnectorRemove.java
Expand Up @@ -69,10 +69,9 @@ public OperationResult execute(final OperationContext context, final ModelNode o
public void execute(RuntimeTaskContext context) throws OperationFailedException {
final ServiceController<?> service = context.getServiceRegistry().getService(JMXConnectorService.SERVICE_NAME);
if (service != null) {
service.addListener(new ResultHandler.ServiceRemoveListener(resultHandler));
} else {
resultHandler.handleResultComplete();
service.setMode(ServiceController.Mode.REMOVE);
}
resultHandler.handleResultComplete();
}
});
} else {
Expand Down
Expand Up @@ -106,11 +106,11 @@ public void execute(RuntimeTaskContext context) throws OperationFailedException
service.setLevel(Level.parse(operation.get(LEVEL).asString()));
service.setOverflowAction(OverflowAction.valueOf(operation.get(OVERFLOW_ACTION).asString()));
serviceBuilder.setInitialMode(ServiceController.Mode.ACTIVE);
serviceBuilder.addListener(new ResultHandler.ServiceStartListener(resultHandler));
serviceBuilder.install();
} catch (Throwable t) {
throw new OperationFailedException(new ModelNode().set(t.getLocalizedMessage()));
}
resultHandler.handleResultComplete();
}
});
} else {
Expand Down

0 comments on commit 96fb0f5

Please sign in to comment.