2012-12-08 11:27:07 +01:00
|
|
|
package docs.pattern;
|
|
|
|
|
|
2012-12-09 12:13:22 +01:00
|
|
|
import scala.concurrent.Await;
|
|
|
|
|
import scala.concurrent.Future;
|
2012-12-08 15:13:58 +01:00
|
|
|
import akka.actor.ActorRef;
|
|
|
|
|
import akka.actor.ActorRefFactory;
|
|
|
|
|
import akka.actor.Props;
|
|
|
|
|
import akka.actor.UntypedActor;
|
|
|
|
|
import akka.util.Timeout;
|
2012-12-08 11:27:07 +01:00
|
|
|
|
|
|
|
|
public class SupervisedAskSpec {
|
|
|
|
|
|
2012-12-08 15:13:58 +01:00
|
|
|
public Object execute(Class<? extends UntypedActor> someActor,
|
|
|
|
|
Object message, Timeout timeout, ActorRefFactory actorSystem)
|
|
|
|
|
throws Exception {
|
2012-12-08 11:27:07 +01:00
|
|
|
// example usage
|
|
|
|
|
try {
|
|
|
|
|
ActorRef supervisorCreator = SupervisedAsk
|
|
|
|
|
.createSupervisorCreator(actorSystem);
|
|
|
|
|
Future<Object> finished = SupervisedAsk.askOf(supervisorCreator,
|
2012-12-08 15:13:58 +01:00
|
|
|
Props.apply(someActor), message, timeout);
|
|
|
|
|
return Await.result(finished, timeout.duration());
|
2012-12-08 11:27:07 +01:00
|
|
|
} catch (Exception e) {
|
|
|
|
|
// exception propagated by supervision
|
2012-12-08 15:13:58 +01:00
|
|
|
throw e;
|
2012-12-08 11:27:07 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|