Re: [akka-user] Akka Persistence and avoiding var in favor of context.become

2018-02-13 Thread Christopher Hunt


> On 13 Feb 2018, at 20:50, Christopher Hunt  wrote:
> 
> While receiveRecover is executing though, I presume that I’m going to have to 
> store the current state in a var…? Here’s what I’ve started with:
> override def receiveRecover: Receive = {
>   case e: Event => context.become(unauthenticated(state(e)))
> }
> …but of course, there is no existing state…
Just to tie this off for me, I’m going to use a var to build initial state 
during receiveRecover as there is no way to become a new receiveRecover. 

Cheers 
C

-- 
>>  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 https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.


Re: [akka-user] Akka Persistence and avoiding var in favor of context.become

2018-02-13 Thread Christopher Hunt


> On 13 Feb 2018, at 8:26 pm, Patrik Nordwall  wrote:
> 
> You have to do the right become transitions in the replay of the events, and 
> when consuming snapshots. Especially the latter is very easy to get wrong.
> 
Thanks Patrik, that shouldn’t be an issue for my use case. My states are 
unauthenticated/authenticated… and that’s it. The actor only becomes 
authenticated after receiving a message from the outside along with some 
validation. So, I’m comfortable moving into the unauthenticated state until 
receiveRecover is finished.

While receiveRecover is executing though, I presume that I’m going to have to 
store the current state in a var…? Here’s what I’ve started with:
override def receiveRecover: Receive = {
  case e: Event => context.become(unauthenticated(state(e)))
}
…but of course, there is no existing state…

receiveCommand will present a similar challenge.

Any advice?

Cheers,
-C

-- 
>>  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 https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.


Re: [akka-user] Akka Persistence and avoiding var in favor of context.become

2018-02-13 Thread Patrik Nordwall
You have to do the right become transitions in the replay of the events,
and when consuming snapshots. Especially the latter is very easy to get
wrong.

On Tue, Feb 13, 2018 at 10:23 AM, Christopher Hunt 
wrote:

> On Friday, 15 September 2017 16:41:42 UTC+10, Konrad Malawski wrote:
>>
>> I would recommend avoiding become with PersistentActors in general, it
>> gets very complex.
>>
>
> The Akka doc (1) suggests that the use of become should be fine. Are you
> able to expand on the complexity statement above?
>
> I'd also like to continue using become with an existing actor that I'm
> attempting to make persistent. Unfortunately, Akka Typed isn't an option
> for me at present.
>
> Thanks for any guidance.
>
> Kind regards,
> Christopher
>
> (1) https://doc.akka.io/docs/akka/2.5.9/persistence.html?language=scala
>
> --
> >> 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 https://groups.google.com/group/akka-user.
> For more options, visit https://groups.google.com/d/optout.
>



-- 

Patrik Nordwall
Akka Tech Lead
Lightbend  -  Reactive apps on the JVM
Twitter: @patriknw

-- 
>>  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 https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.


Re: [akka-user] Akka Persistence and avoiding var in favor of context.become

2018-02-13 Thread Christopher Hunt
On Friday, 15 September 2017 16:41:42 UTC+10, Konrad Malawski wrote:
>
> I would recommend avoiding become with PersistentActors in general, it 
> gets very complex.
>

The Akka doc (1) suggests that the use of become should be fine. Are you 
able to expand on the complexity statement above?

I'd also like to continue using become with an existing actor that I'm 
attempting to make persistent. Unfortunately, Akka Typed isn't an option 
for me at present.

Thanks for any guidance.

Kind regards,
Christopher

(1) https://doc.akka.io/docs/akka/2.5.9/persistence.html?language=scala

-- 
>>  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 https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.


Re: [akka-user] Akka Persistence and avoiding var in favor of context.become

2017-09-15 Thread Konrad “ktoso” Malawski
Become “should" work AFAIR, though I’d recommend using Akka 2.5 (it’s
binary compatible with 2.4, so you can just upgrade it).
I could not find if we fixed anything about become in persistent Actors,
there were fixes but a very long time ago in 2.3..

I would recommend avoiding become with PersistentActors in general, it gets
very complex.

In the Akka Typed API we’re working on for Akka Persistence become will be
*the* way to handle things and it will not be as confusing in its inner
workings as it is now.

—
Konrad `kto.so` Malawski
Akka  @ Lightbend 

On 15 September 2017 at 05:11:07, Curt Siffert (c...@keenworks.com) wrote:

Learning akka persistence, I was initially reluctant to use vars to capture
state since we generally try to avoid vars when possible.

But when experimenting with context.become(receiveBlock(stateParam)) inside
a receiveRecover implementation, it appeared to interfere with its ability
to stash other messages. (akka 2.4.20) It tried to handle normal messages
that it didn't try to handle when I wasn't using context.become.

Is it possible and reasonable to use context.become instead of var to
capture state using Akka Persistence? At first glance, it seems like the
interplay between receiveCommand and receiveRecover could get rather
tricky, especially if your actor has initialization behavior that changes
its receiveCommand behavior - for instance, initializing receiveCommand
with an empty collection to start, i.e.

def receiveCommand: Receive = initialReceive(List.empty)

Thanks,
Curt Siffert

--
>> 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 https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

-- 
>>  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 https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.


[akka-user] Akka Persistence and avoiding var in favor of context.become

2017-09-14 Thread Curt Siffert
Learning akka persistence, I was initially reluctant to use vars to capture 
state since we generally try to avoid vars when possible. 

But when experimenting with context.become(receiveBlock(stateParam)) inside 
a receiveRecover implementation, it appeared to interfere with its ability 
to stash other messages. (akka 2.4.20) It tried to handle normal messages 
that it didn't try to handle when I wasn't using context.become.

Is it possible and reasonable to use context.become instead of var to 
capture state using Akka Persistence? At first glance, it seems like the 
interplay between receiveCommand and receiveRecover could get rather 
tricky, especially if your actor has initialization behavior that changes 
its receiveCommand behavior - for instance, initializing receiveCommand 
with an empty collection to start, i.e. 

def receiveCommand: Receive = initialReceive(List.empty)

Thanks,
Curt Siffert

-- 
>>  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 https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.