+ private void verifyActorReady(ActorRef actorRef) {
+ // Sometimes we see messages go to dead letters soon after creation - it seems the actor isn't quite
+ // in a state yet to receive messages or isn't actually created yet. This seems to happen with
+ // actorSelection so, to alleviate it, we use an actorSelection and call resolveOne with retries to
+ // ensure it's ready.
+
+ int tries = 1;
+ while(true) {
+ try {
+ Timeout timeout = new Timeout(100, TimeUnit.MILLISECONDS);
+ Future<ActorRef> future = system.actorSelection(actorRef.path()).resolveOne(timeout);
+ Await.ready(future, timeout.duration());
+ break;
+ } catch (Exception e) {
+ if(tries++ > 20) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+ }
+