// so we do it directly
transition(false);
return;
}
BatchBuilder batchBuilder = serviceContainer.batchBuilder();
UpdateContext updateContext = new SimpleUpdateContext(serviceContainer, batchBuilder);
for (ServerModelUpdateTuple<?,?> update : updates) {
logger.debugf("Applying update %s", update.getUpdate().toString());
if (status != Status.ACTIVE) {
// Don't execute this update; just notify any handler and
// count it as updated for overall completion tracking
update.handleCancellation();
continue;
}
boolean appliedToModel = false;
ServerModelUpdateTuple<Object, ?> rollbackTuple = null;
try {
rollbackTuple = update.getRollbackTuple(serverModel);
serverModel.update(update.getUpdate());
appliedToModel = true;
if (allowRuntimeUpdates) {
update.applyUpdate(updateContext);
}
else {
// We won't get a callback from a result handler, so
// directly record the completion for overall completion tracking
updateComplete();
}
// As the last thing in this try block, add the rollbackTuple
// to the rollback list. Do it last because if this update
// directly fails, we roll it back in catch block below.
// The 'rollbacks' list is for updates that succeeeded.
if (allowOverallRollback && rollbackTuple != null) {
// Add this latest update's rollback to the list
rollbacks.add(0, rollbackTuple);
}
}
catch (Exception e) {
update.handleFailure(e);
if (rollbackTuple != null) {
if (appliedToModel) {
try {
if (allowRuntimeUpdates) {
// FIXME this is likely incorrect given we are now
// using a batch!!!
rollbackTuple.applyUpdate(updateContext);
}
serverModel.update(rollbackTuple.getUpdate());
} catch (UpdateFailedException e1) {
rollbackTuple.handleFailure(e1);
}
}
}
// else there was no compensating update or creating the
// rollbackTuple failed at the beginning of 'try'
// and there is nothing else needing to be done here
}
}
if (status == Status.ACTIVE) {
try {
batchBuilder.install();
} catch (ServiceRegistryException e) {
handleRollback();
}
}