[akka-user] PoisonPill and message ordering

2015-04-16 Thread Anders Båtstrand
I am having some troubles understanding the finer details of the PoisonPill.

As I understand it, it is a normal message, and will be processed AFTER the 
persist-callback is executed.

I have the following code in my onReceiveCommand:

System.out.println(About to persist:  + message);
persist(message, o - System.out.println(Persisted:  + o));


When I run the following against this actor 8not using TestActorRef):

actorRef.tell(Test message, getTestActor());
Thread.sleep(1000L);
actorRef.tell(PoisonPill.getInstance(), getTestActor());

Thread.sleep(1000L);


I get the expected output:

About to persist: Test message
Persisted: Test message


If I remove the sleep between the messages, I sometimes get the following:

[INFO] [04/16/2015 15:50:11.183] [Test-System-akka.actor.default-dispatcher-
5] [akka://Test-System/user/my-actor] Message [akka.persistence.Recover] 
from Actor[akka://Test-System/user/my-actor#867538471] to 
Actor[akka://Test-System/user/my-actor#867538471] was not delivered. [1] 
dead letters encountered. [...]

How is this possible? It seems the PoisonPill arrived first... But message 
ordering should be guaranteed between sender (testActor) and my actor, 
right?

If I add a short sleep between the two tell, I sometimes get different 
(internal) messages in deadletters.

Best regards,

Anders



-- 
  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 akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.


Re: [akka-user] PoisonPill and message ordering

2015-04-16 Thread Roland Kuhn
Hi Anders,

the problem is that PoisonPill is an AutoReceiveMessage, meaning that the 
PersistentActor trait does neither see it nor can it do anything about it—it 
will be handled not matter whether persistence callbacks are outstanding or 
not. We will eventually remove this message since it is so special, my 
recommendation is to explicitly create a TerminatePlease message for your Actor 
which then is handled in the normal way (and at the expected times).

Regards,

Roland

 16 apr 2015 kl. 16:00 skrev Anders Båtstrand ander...@gmail.com:
 
 I am having some troubles understanding the finer details of the PoisonPill.
 
 As I understand it, it is a normal message, and will be processed AFTER the 
 persist-callback is executed.
 
 I have the following code in my onReceiveCommand:
 
 System.out.println(About to persist:  + message);
 persist(message, o - System.out.println(Persisted:  + o));
 
 When I run the following against this actor 8not using TestActorRef):
 
 actorRef.tell(Test message, getTestActor());
 Thread.sleep(1000L);
 actorRef.tell(PoisonPill.getInstance(), getTestActor());
 Thread.sleep(1000L);
 
 I get the expected output:
 
 About to persist: Test message
 Persisted: Test message
 
 
 If I remove the sleep between the messages, I sometimes get the following:
 
 [INFO] [04/16/2015 15:50:11.183] 
 [Test-System-akka.actor.default-dispatcher-5] 
 [akka://Test-System/user/my-actor] Message [akka.persistence.Recover] from 
 Actor[akka://Test-System/user/my-actor#867538471] to 
 Actor[akka://Test-System/user/my-actor#867538471] was not delivered. [1] dead 
 letters encountered. [...]
 
 How is this possible? It seems the PoisonPill arrived first... But message 
 ordering should be guaranteed between sender (testActor) and my actor, right?
 
 If I add a short sleep between the two tell, I sometimes get different 
 (internal) messages in deadletters.
 
 Best regards,
 
 Anders
 
 
 
 
 -- 
  Read the docs: http://akka.io/docs/ http://akka.io/docs/
  Check the FAQ: 
  http://doc.akka.io/docs/akka/current/additional/faq.html 
  http://doc.akka.io/docs/akka/current/additional/faq.html
  Search the archives: https://groups.google.com/group/akka-user 
  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 akka-user+unsubscr...@googlegroups.com 
 mailto:akka-user+unsubscr...@googlegroups.com.
 To post to this group, send email to akka-user@googlegroups.com 
 mailto:akka-user@googlegroups.com.
 Visit this group at http://groups.google.com/group/akka-user 
 http://groups.google.com/group/akka-user.
 For more options, visit https://groups.google.com/d/optout 
 https://groups.google.com/d/optout.



Dr. Roland Kuhn
Akka Tech Lead
Typesafe http://typesafe.com/ – Reactive apps on the JVM.
twitter: @rolandkuhn
 http://twitter.com/#!/rolandkuhn

-- 
  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 akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.