Last active
January 20, 2016 04:40
-
-
Save skuenzli/d4744a654170203bc3b7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // the service that will be automatically injected | |
| final NumberService numberService; | |
| @Inject | |
| public NumberActor(@Named("NumberService") NumberService numberService) { | |
| this.numberService = numberService; | |
| } | |
| @Override | |
| public void onReceive(Object message) throws Exception { | |
| if (message instanceof GetRandomInteger) { | |
| GetRandomInteger query = message | |
| Callable<Integer> op = new Callable<Integer>() { | |
| @Override | |
| Integer call() throws Exception { | |
| return numberService.nextInt(query.max) | |
| } | |
| } | |
| Future<Integer> futureOpResults = Futures.future(op, this.context.dispatcher()) | |
| Patterns.pipe(futureOpResults, context().dispatcher()).to(sender, self) | |
| } else { | |
| unhandled(message); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment