Merge pull request #1842 from akka/wip-props-docs-name-∂π
fix misleading Recommended Practices
This commit is contained in:
commit
115d7831b4
2 changed files with 17 additions and 16 deletions
|
|
@ -528,23 +528,24 @@ public class UntypedActorDocTest {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static
|
||||||
//#props-factory
|
//#props-factory
|
||||||
public static class DemoActor extends UntypedActor {
|
public class DemoActor extends UntypedActor {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create Props for an actor of this type.
|
* Create Props for an actor of this type.
|
||||||
* @param name The name to be passed to this actor’s constructor.
|
* @param magicNumber The magic number to be passed to this actor’s constructor.
|
||||||
* @return a Props for creating this actor, which can then be further configured
|
* @return a Props for creating this actor, which can then be further configured
|
||||||
* (e.g. calling `.withDispatcher()` on it)
|
* (e.g. calling `.withDispatcher()` on it)
|
||||||
*/
|
*/
|
||||||
public static Props mkProps(String name) {
|
public static Props props(int magicNumber) {
|
||||||
return Props.create(DemoActor.class, name);
|
return Props.create(DemoActor.class, magicNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
final String name;
|
final int magicNumber;
|
||||||
|
|
||||||
public DemoActor(String name) {
|
public DemoActor(int magicNumber) {
|
||||||
this.name = name;
|
this.magicNumber = magicNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -555,10 +556,10 @@ public class UntypedActorDocTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
//#props-factory
|
//#props-factory
|
||||||
{
|
@Test
|
||||||
if (system != null)
|
public void demoActor() {
|
||||||
//#props-factory
|
//#props-factory
|
||||||
system.actorOf(DemoActor.mkProps("hello"));
|
system.actorOf(DemoActor.props(42), "demo");
|
||||||
//#props-factory
|
//#props-factory
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -55,22 +55,22 @@ class DemoActorWrapper extends Actor {
|
||||||
object DemoActor {
|
object DemoActor {
|
||||||
/**
|
/**
|
||||||
* Create Props for an actor of this type.
|
* Create Props for an actor of this type.
|
||||||
* @param name The name to be passed to this actor’s constructor.
|
* @param magciNumber The magic number to be passed to this actor’s constructor.
|
||||||
* @return a Props for creating this actor, which can then be further configured
|
* @return a Props for creating this actor, which can then be further configured
|
||||||
* (e.g. calling `.withDispatcher()` on it)
|
* (e.g. calling `.withDispatcher()` on it)
|
||||||
*/
|
*/
|
||||||
def props(name: String): Props = Props(classOf[DemoActor], name)
|
def props(magicNumber: Int): Props = Props(classOf[DemoActor], magicNumber)
|
||||||
}
|
}
|
||||||
|
|
||||||
class DemoActor(name: String) extends Actor {
|
class DemoActor(magicNumber: Int) extends Actor {
|
||||||
def receive = {
|
def receive = {
|
||||||
case x ⇒ // some behavior
|
case x: Int ⇒ sender ! (x + magicNumber)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ...
|
// ...
|
||||||
|
|
||||||
context.actorOf(DemoActor.props("hello"))
|
context.actorOf(DemoActor.props(42), "demo")
|
||||||
//#props-factory
|
//#props-factory
|
||||||
|
|
||||||
def receive = Actor.emptyBehavior
|
def receive = Actor.emptyBehavior
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue