import akka.actor.ActorSelection;
import akka.actor.ActorSystem;
import akka.actor.Identify;
+import akka.actor.InvalidActorNameException;
import akka.actor.PoisonPill;
import akka.actor.Props;
import akka.pattern.Patterns;
*/
public ActorRef createActor(Props props) {
ActorRef actorRef = system.actorOf(props);
- return addActor(actorRef);
+ return addActor(actorRef, true);
}
/**
*/
public ActorRef createActor(Props props, String actorId) {
ActorRef actorRef = system.actorOf(props, actorId);
- return addActor(actorRef);
+ return addActor(actorRef, true);
+ }
+
+ /**
+ * Create a normal actor with the passed in name w/o verifying that the actor is ready.
+ *
+ * @param props the actor Props
+ * @param actorId name of actor
+ * @return the ActorRef
+ */
+ public ActorRef createActorNoVerify(Props props, String actorId) {
+ ActorRef actorRef = system.actorOf(props, actorId);
+ return addActor(actorRef, false);
}
/**
*/
@SuppressWarnings("unchecked")
public <T extends Actor> TestActorRef<T> createTestActor(Props props, String actorId) {
- TestActorRef<T> actorRef = TestActorRef.create(system, props, actorId);
- return (TestActorRef<T>) addActor(actorRef);
+ InvalidActorNameException lastError = null;
+ for (int i = 0; i < 10; i++) {
+ try {
+ TestActorRef<T> actorRef = TestActorRef.create(system, props, actorId);
+ return (TestActorRef<T>) addActor(actorRef, true);
+ } catch (InvalidActorNameException e) {
+ lastError = e;
+ Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
+ }
+ }
+
+ throw lastError;
}
/**
@SuppressWarnings("unchecked")
public <T extends Actor> TestActorRef<T> createTestActor(Props props) {
TestActorRef<T> actorRef = TestActorRef.create(system, props);
- return (TestActorRef<T>) addActor(actorRef);
+ return (TestActorRef<T>) addActor(actorRef, true);
}
- private <T extends ActorRef> ActorRef addActor(T actorRef) {
+ private <T extends ActorRef> ActorRef addActor(T actorRef, boolean verify) {
createdActors.add(actorRef);
- verifyActorReady(actorRef);
+ if (verify) {
+ verifyActorReady(actorRef);
+ }
+
return actorRef;
}