if (services) {
final String path = getPathValue(context, PATH_SPECIFIED, model);
final String relativeTo = getPathValue(context, RELATIVE_TO, model);
final PathEventContextImpl pathEventContext = pathManager.checkRestartRequired(context, name, Event.ADDED);
if (pathEventContext.isInstallServices()) {
//Add service to the path manager
pathManager.addPathEntry(name, path, relativeTo, false);
}
context.addStep(new OperationStepHandler() {
public void execute(final OperationContext context, final ModelNode operation) throws OperationFailedException {
final ServiceController<?> legacyService;
if (pathEventContext.isInstallServices()) {
//Add the legacy services
final ServiceVerificationHandler verificationHandler = new ServiceVerificationHandler();
final ServiceTarget target = context.getServiceTarget();
if (relativeTo == null) {
legacyService = pathManager.addAbsolutePathService(target, name, path, verificationHandler);
} else {
legacyService = pathManager.addRelativePathService(target, name, path, false, relativeTo, verificationHandler);
}
//This is a change from the original version
context.addStep(verificationHandler, OperationContext.Stage.VERIFY);
} else {
legacyService = null;
}
context.completeStep(new OperationContext.RollbackHandler() {
public void handleRollback(OperationContext context, ModelNode operation) {
pathManager.removePathService(context, name);
if (pathEventContext.isInstallServices()) {
if (legacyService != null) {
context.removeService(legacyService.getName());
}
} else {
pathEventContext.revert();
}
}
});
}
}, OperationContext.Stage.RUNTIME);
context.completeStep(new OperationContext.RollbackHandler() {
public void handleRollback(OperationContext context, ModelNode operation) {
if (pathEventContext.isInstallServices()) {
try {
pathManager.removePathEntry(name, false);
} catch (OperationFailedException e) {
//Should not happen since 'false' passed in for the check parameter
throw new RuntimeException(e);