}
resource.setStateUnderLock(stateToSet, wexc);
throw wexc;
}
WorkspaceRequest req;
boolean fallback = false;
final boolean propstartOK = resource.isPropagateStartOK();
if (target == STATE_STARTED) {
if (propstartOK) {
req = this.reqFactory.propagateAndStart();
if (req == null) {
if (this.trace) {
logger.trace("\n\n ***** ST--propagate " + idStr +
": could use propagateToStart, " +
"but not implemented\n");
}
fallback = true;
}
} else {
req = reqFactory.propagate();
if (req == null) {
final String errMsg = "propagate functionality " +
"needed but it is not implemented";
final ManageException wexc =
new ManageException(errMsg);
resource.setStateUnderLock(
STATE_CORRUPTED + STATE_PROPAGATING, wexc);
throw wexc;
}
// just change local var, not real resource target
target = STATE_PROPAGATED;
if (this.trace) {
logger.trace("\n\n ***** ST--propagate " + idStr +
": propagateToStart not OK for this resource, doing" +
" propagate-only\n");
}
}
} else if (target == STATE_PAUSED) {
if (propstartOK) {
req = this.reqFactory.propagateAndPause();
if (req == null) {
if (this.trace) {
logger.trace("\n\n ***** ST--propagate " + idStr +
": could use propagateToPause, but not implemented\n");
}
fallback = true;
}
} else {
req = reqFactory.propagate();
if (req == null) {
final String errMsg = "propagate functionality " +
"needed but it is not implemented";
final ManageException wexc =
new ManageException(errMsg);
resource.setStateUnderLock(
STATE_CORRUPTED + STATE_PROPAGATING, wexc);
throw wexc;
}
// just change local var, not real resource target
// todo: comment why
target = STATE_PROPAGATED;
if (this.trace) {
logger.trace("\n\n ***** ST--propagate " + idStr +
": propagateToPause not OK for this resource, doing" +
" propagate-only\n");
}
}
} else if (target == STATE_PROPAGATED) {
req = this.reqFactory.propagate();
if (req == null) {
final String errMsg = "propagate functionality " +
"needed but it is not implemented";
final ManageException wexc =
new ManageException(errMsg);
resource.setStateUnderLock(
STATE_CORRUPTED + STATE_PROPAGATING, wexc);
throw wexc;
}
} else {
// handlers before propagate handler should not
// let this happen
throw new ManageException("Current state is " +
this.dataConvert.stateName(current) + ", " +
"propagate is needed but not" +
" achieved, but target state is not " +
this.dataConvert.stateName(STATE_STARTED) + ", " +
this.dataConvert.stateName(STATE_PAUSED) + ", or" +
this.dataConvert.stateName(STATE_PROPAGATED) + ", it is " +
this.dataConvert.stateName(target));
}
if (fallback) {
if (this.trace) {
logger.trace("\n\n ***** ST--propagate " + idStr +
": falling back to propagate-only\n");
}
req = reqFactory.propagate();
if (req == null) {
final String errMsg = "propagate functionality " +
"needed but it is not implemented";
final ManageException wexc =
new ManageException(errMsg);
resource.setStateUnderLock(
STATE_CORRUPTED + STATE_PROPAGATING, wexc);
throw wexc;
}
// just change local var, not real resource target
target = STATE_PROPAGATED;
}
final WorkspaceRequestContext requestContext =
new WorkspaceRequestContext(id, resource.getName(),
this.locator, this.lager);
requestContext.setVm(resource.getVM());
requestContext.setGroupID(resource.getGroupId());
requestContext.setGroupSize(resource.getGroupSize());
if (resource.isLastInGroup()) {
requestContext.setLastInGroup(true);
resource.setLastInGroup(false);
}
requestContext.setPartOfGroupRequest(resource.isPartOfGroupRequest());
// req cannot be null here
if (target == STATE_PROPAGATED) {
requestContext.setNotify(STATE_PROPAGATED);
req.setRequestContext(requestContext);
resource.setStateUnderLock(STATE_PROPAGATING, null);
if (this.trace) {
logger.trace("\n\n ***** ST--propagate " + idStr +
": adding propagate request: " + req + "\n");
}
RequestDispatch.addRequest(req, id);
return true;
} else if (target == STATE_STARTED) {
requestContext.setNotify(STATE_STARTED);
req.setRequestContext(requestContext);
resource.setStateUnderLock(STATE_PROPAGATING_TO_START, null);
if (this.trace) {
logger.trace("\n\n ***** ST--propagate " + idStr +
": adding propagate-to-start request: " + req + "\n");
}
RequestDispatch.addRequest(req, id);
return true;
} else {
requestContext.setNotify(STATE_PAUSED);
req.setRequestContext(requestContext);
resource.setStateUnderLock(STATE_PROPAGATING_TO_PAUSE, null);
if (this.trace) {
logger.trace("\n\n ***** ST--propagate " + idStr +