Skip to content

Instantly share code, notes, and snippets.

@iocanel
Created March 5, 2012 17:01
Show Gist options
  • Save iocanel/1979295 to your computer and use it in GitHub Desktop.
Save iocanel/1979295 to your computer and use it in GitHub Desktop.
Sending commands and getting a result back via Hazelcast
public Map<node,result> execute(Command command) throws Exception {
if (command == null) {
throw new Exception("Command store not found");
} else {
//store the command to correlate it with the result.
commandStore.getPending().put(command.getId(), command);
//I create a timeout task and schedule it
TimeoutTask timeoutTask = new TimeoutTask(command, commandStore);
ScheduledFuture timeoutFuture = timeoutScheduler.schedule(timeoutTask, command.getTimeout(), TimeUnit.MILLISECONDS);
}
if (producer != null) {
//send the command to the topic
producer.produce(command);
//retrieve the result list from the blocking queue.
return command.getResult();
}
throw new Exception("Command producer not found");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment