Created
March 5, 2012 17:01
-
-
Save iocanel/1979295 to your computer and use it in GitHub Desktop.
Sending commands and getting a result back via Hazelcast
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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