Hi,
The reason is that your code checks directly if the Future has completed (which
it most probably hasn't).
You should either Await the completion of the Future, or do something on
completion like this.
actorRefFuture.onComplete(new OnComplete<ActorRef>() {
@Override
public void onComplete(Throwable failure, ActorRef result) {
if (failure == null) {
IActorDummy actor2 = TypedActor.get(actorSystem).typedActorOf(
new TypedProps<IActorDummy>(IActorDummy.class), result);
System.out.println("Indirect selection got " + actor2.method());
} else {
System.out.println("Timed out");
}
}}, actorSystem.dispatcher());
B/
On 25 June 2014 at 05:19:35, Jax Gibb ([email protected]) wrote:
If you create a simple interface IActorDummy, with a "String method()"
definition, & an implementation of ActorDummy, which simply returns something,
then the following test will produce output for actor1, but a timeout for
actor2.
@Test
public void quiteSimpleTest() {
// create context
ActorSystem actorSystem = ActorSystem.create("example");
// start an actor
IActorDummy dummy = TypedActor.get(actorSystem).typedActorOf(
new TypedProps<ActorDummy>(IActorDummy.class,
ActorDummy.class), "dummyService");
// direct lookup
ActorRef eventRef =
actorSystem.actorFor("akka://example/user/dummyService");
IActorDummy actor1 = TypedActor.get(actorSystem).typedActorOf(new
TypedProps<IActorDummy>(
IActorDummy.class), eventRef);
System.out.println("Direct ref got " + actor1.method());
// indirect lookup
ActorSelection eventSel =
actorSystem.actorSelection("akka://example/user/dummyService");
Future<ActorRef> actorRefFuture = eventSel.resolveOne(new Timeout(10,
TimeUnit.SECONDS));
if (actorRefFuture.isCompleted()) {
ActorRef actorRef = actorRefFuture.value().get().get();
IActorDummy actor2 = TypedActor.get(actorSystem).typedActorOf(
new TypedProps<IActorDummy>(IActorDummy.class), actorRef);
System.out.println("Indirect selection got " + actor2.method());
} else {
System.out.println("Timed out");
}
}
On Tuesday, 24 June 2014 00:25:58 UTC+10, Björn Antonsson wrote:
Hi Jax,
That sounds strange. Are you sure that the "target actor" has been started
before you try to resolve it via the ActorSelection?
If you continue to have problems, a small reproducer would be very helpful in
trying to figure out what is wrong.
B/
On 23 June 2014 at 07:53:22, Jax Gibb ([email protected]) wrote:
I have a similar inconsistency. Everything works fine using actorFor(), but if
I simply replace with actorSelection(), then the Future<ActorRef> from
resolveOne() takes a highly variable amount of time (with repeated attempts),
or doesn't resolve at all. I am using strictly Java, & I'm still within the one
JVM (until I sort this out).
Jax
--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ:
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.
--
Björn Antonsson
Typesafe – Reactive Apps on the JVM
twitter: @bantonsson
--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ:
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.
--
Björn Antonsson
Typesafe – Reactive Apps on the JVM
twitter: @bantonsson
--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ:
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.