Merge pull request #1490 from akka/wip-3377-Props.create-∂π
improve safety of Props.create by allowing Creator<T>, see #3377
This commit is contained in:
commit
9c89f170d2
11 changed files with 222 additions and 45 deletions
|
|
@ -49,6 +49,7 @@ import akka.actor.IndirectActorProducer;
|
|||
import akka.actor.OneForOneStrategy;
|
||||
//#import-props
|
||||
import akka.actor.Props;
|
||||
import akka.japi.Creator;
|
||||
//#import-props
|
||||
import akka.actor.SupervisorStrategy;
|
||||
import akka.actor.SupervisorStrategy.Directive;
|
||||
|
|
@ -88,14 +89,35 @@ public class UntypedActorDocTest {
|
|||
|
||||
private final ActorSystem system = actorSystemResource.getSystem();
|
||||
|
||||
//#creating-props-config
|
||||
static class MyActorC implements Creator<MyActor> {
|
||||
@Override public MyActor create() {
|
||||
return new MyActor("...");
|
||||
}
|
||||
}
|
||||
|
||||
//#creating-props-config
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Test
|
||||
public void createProps() {
|
||||
//#creating-props-config
|
||||
Props props1 = Props.create(MyUntypedActor.class);
|
||||
Props props2 = Props.create(MyActor.class, "...");
|
||||
Props props3 = Props.create(new MyActorC());
|
||||
//#creating-props-config
|
||||
}
|
||||
|
||||
//#parametric-creator
|
||||
static class ParametricCreator<T extends MyActor> implements Creator<T> {
|
||||
@Override public T create() {
|
||||
// ... fabricate actor here
|
||||
//#parametric-creator
|
||||
return null;
|
||||
//#parametric-creator
|
||||
}
|
||||
}
|
||||
//#parametric-creator
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue