Technically it may be safe in that case, you're in an Actor after all.
However I'd argue it's bad style as it mixes an API designed for immutable data 
passing (the data param of FSM),
in a mutable way, which can/will lead to confusion when someone else reads your 
code.

If you want to have (or are forced to by some API that exposes such) mutable 
state, just keel a variable in the Actor's body.

Also remember that in general:
"mutable reference to immutable data" is better than "immutable reference to 
mutable data",
since the danger of leaking the object in a message is not an issue in the 
first case.

-- 
Cheers,
Konrad 'ktoso’ Malawski
Akka @ Typesafe

On 30 January 2016 at 04:47:27, James P (jsp0...@gmail.com) wrote:

Hi folks,

Good day. I'm just starting with Akka (Java with Lambda) and I have a question 
regarding AbstractFSM. 

When using "akka.actor.FSM.State.using(Data)" does "Data" need to be immutable?

Example:
when(State.Idle,
matchEvent(Event.class, StateData.class,
(event, stateData) ->
stay().using(new StateData())));

when(State.Active,
matchEvent(Event.class, StateData.class,
(event, stateData) -> goTo(State.Idle).using(stateData.mutate())));


                .......
               public class StateData{
public StateData mutate(){
//mutate myself
return this;
}
             
 Is it safe to mutate the data this way? I'm uncertain since I saw that 
"akka.actor.AbstractFSM.onTransition(PartialFunction<Tuple2<BatchingState, 
BatchingState>, BoxedUnit>)" allows you to access both the current stateData 
and the nextStateData. 

 
Any help would be much appreciated. Thanks and have a great day.
--
>>>>>>>>>> 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.

Reply via email to