Created
December 27, 2013 23:51
-
-
Save jconwell/8154233 to your computer and use it in GitHub Desktop.
Another utility actor used in unit testing. Use this when you need to refer to the actor being tested by its path, but don't want to create all the actor parent actors.
This file contains 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
package com.turbo.akka; | |
import akka.actor.ActorRef; | |
import akka.actor.Props; | |
import akka.actor.UntypedActor; | |
import akka.event.Logging; | |
import akka.event.LoggingAdapter; | |
/** | |
* Utility actor that does nothing but take a Props and create | |
* whatever actor the Props points to | |
*/ | |
public class ChildCreationActor extends UntypedActor { | |
private final LoggingAdapter LOG = Logging.getLogger(getContext().system(), this); | |
@Override | |
public void onReceive(Object o) throws Exception { | |
if (o instanceof ChildArgs) { | |
ChildArgs childArgs = (ChildArgs)o; | |
ActorRef child = getContext().actorOf(childArgs.props, childArgs.actorName); | |
LOG.info("Created child actor: " + child.path().toString()); | |
} | |
else { | |
unhandled(o); | |
} | |
} | |
/** | |
* The only usable msg to ChildCreationActor. Defines the child actor to create | |
*/ | |
public static class ChildArgs { | |
public final String actorName; | |
public final Props props; | |
public ChildArgs(Props props, String actorName) { | |
this.actorName = actorName; | |
this.props = props; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you!