Added serialize-messages description to scala typed actors doc
This commit is contained in:
parent
89b1814d1c
commit
054403325d
1 changed files with 12 additions and 0 deletions
|
|
@ -173,3 +173,15 @@ Messages and immutability
|
|||
-------------------------
|
||||
|
||||
**IMPORTANT**: Messages can be any kind of object but have to be immutable (there is a workaround, see next section). Java or Scala can’t enforce immutability (yet) so this has to be by convention. Primitives like String, int, Long are always immutable. Apart from these you have to create your own immutable objects to send as messages. If you pass on a reference to an instance that is mutable then this instance can be modified concurrently by two different Typed Actors and the Actor model is broken leaving you with NO guarantees and most likely corrupt data.
|
||||
|
||||
Akka can help you in this regard. It allows you to turn on an option for serializing all messages, e.g. all parameters to the Typed Actor effectively making a deep clone/copy of the parameters. This will make sending mutable messages completely safe. This option is turned on in the ‘$AKKA_HOME/config/akka.conf’ config file like this:
|
||||
|
||||
.. code-block:: ruby
|
||||
|
||||
akka {
|
||||
actor {
|
||||
serialize-messages = on # does a deep clone of messages to ensure immutability
|
||||
}
|
||||
}
|
||||
|
||||
This will make a deep clone (using Java serialization) of all parameters.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue