Skip to content

Instantly share code, notes, and snippets.

@skuenzli
Last active January 20, 2016 04:40
Show Gist options
  • Select an option

  • Save skuenzli/d4744a654170203bc3b7 to your computer and use it in GitHub Desktop.

Select an option

Save skuenzli/d4744a654170203bc3b7 to your computer and use it in GitHub Desktop.
// 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