Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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.
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;
}
}
}
@SerialCoderer

This comment has been minimized.

Copy link

SerialCoderer commented May 22, 2014

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.