@Override
public void execute() {
final Set<ServerIdentity> outstanding = new HashSet<ServerIdentity>();
final ServerTaskExecutor.ServerOperationListener listener = new ServerTaskExecutor.ServerOperationListener();
for(final ServerUpdateTask task : tasks) {
final ServerIdentity identity = task.getServerIdentity();
if(updatePolicy.canUpdateServer(identity)) {
// Execute the task
if(executor.executeTask(listener, task)) {
outstanding.add(task.getServerIdentity());
}
} else {
sendCancelledResponse(identity);
}
}
boolean interrupted = false;
while(! outstanding.isEmpty()) {
try {
// Wait for all prepared results
final TransactionalProtocolClient.PreparedOperation<ServerTaskExecutor.ServerOperation> prepared = listener.retrievePreparedOperation();
final ServerIdentity identity = prepared.getOperation().getIdentity();
recordPreparedOperation(identity, prepared);
outstanding.remove(identity);
} catch (InterruptedException e) {
interrupted = true;
}