// Go through the states in reverse order
List<ControllerState> states = controller.getStates();
for (int i = states.size()-1; i >= 0; --i)
{
ControllerState state = states.get(i);
for (DeploymentControllerContext deploymentControllerContext : toUndeploy)
{
ControllerState current = deploymentControllerContext.getState();
int currentIdx = states.indexOf(current);
DeploymentContext context = deploymentControllerContext.getDeploymentContext();
if (currentIdx != -1 && currentIdx > i)
{
try
{
controller.change(deploymentControllerContext, state);
}
catch (Throwable t)
{
log.warn("Error during undeploy", t);
context.setState(DeploymentState.ERROR);
context.setProblem(t);
}
}
else
{
if (trace)
log.trace("Not moving " + deploymentControllerContext + " to state " + state + " it is at " + current);
}
}
}
// Uninstall the contexts
for (DeploymentControllerContext deploymentControllerContext : toUndeploy)
{
DeploymentContext context = deploymentControllerContext.getDeploymentContext();
context.getTransientAttachments().removeAttachment(ControllerContext.class);
try
{
controller.uninstall(deploymentControllerContext.getName());
setState(context, DeploymentState.UNDEPLOYED, null);
// This is now in the abstract classloader deployer.undeploy,
// but left here in case somebody isn't using that.
removeClassLoader(context);
cleanup(context);
log.debug("Fully Undeployed " + context.getName());
}
catch (Throwable t)
{
log.warn("Error during uninstall", t);
context.setState(DeploymentState.ERROR);
context.setProblem(t);
}
}
}
// There is something to deploy
if (deploy != null && deploy.isEmpty() == false)
{
// Create the controller contexts
for (DeploymentContext context : deploy)
{
checkShutdown();
DeploymentControllerContext deploymentControllerContext = new DeploymentControllerContext(context, this);
try
{
controller.install(deploymentControllerContext);
context.setState(DeploymentState.DEPLOYING);
log.debug("Deploying " + context.getName());
context.getTransientAttachments().addAttachment(ControllerContext.class, deploymentControllerContext);
if (scopeBuilder != null)
context.getTransientAttachments().addAttachment(ScopeBuilder.class, scopeBuilder);
if (repository != null)
context.getTransientAttachments().addAttachment(MutableMetaDataRepository.class, repository);
}
catch (Throwable t)
{
// Set the error on the parent
context.setState(DeploymentState.ERROR);
context.setProblem(t);
// Set the children to not deployed
setState(context, DeploymentState.UNDEPLOYED, DeploymentState.DEPLOYING);
}
}
// Go through the states in order
List<ControllerState> states = controller.getStates();
for (int i = 0; i < states.size(); ++i)
{
ControllerState state = states.get(i);
for (DeploymentContext context : deploy)
{
DeploymentControllerContext deploymentControllerContext = context.getTransientAttachments().getAttachment(ControllerContext.class.getName(), DeploymentControllerContext.class);
ControllerState current = deploymentControllerContext.getState();
int currentIdx = states.indexOf(current);
if (currentIdx != -1 && currentIdx < i)
{
checkShutdown();
try