change serialization to strictly rely on subtyping

- when encountering new message type, check all bindings which map apply
- if multiple are found, choose the most specific one if that exists or
  verify that all mappings yield the same serializer
- in case of remaining ambiguity, throw exception
- also add special handling for “none” serializer mapping: turn off a
  default
This commit is contained in:
Roland 2012-02-07 15:11:16 +01:00
parent 50d107e150
commit 8b9f1caf67
6 changed files with 72 additions and 44 deletions

View file

@ -32,14 +32,26 @@ should be serialized using which ``Serializer``, this is done in the "akka.actor
.. includecode:: ../scala/code/akka/docs/serialization/SerializationDocSpec.scala#serialization-bindings-config
You only need to specify the name of an interface or abstract base class of the messages. In case of ambiguity,
i.e. the message implements several of the configured classes, it is primarily using the most specific
configured class, and secondly the entry configured first.
You only need to specify the name of an interface or abstract base class of the
messages. In case of ambiguity, i.e. the message implements several of the
configured classes, the most specific configured class will be used, i.e. the
one of which all other candidates are superclasses. If this condition cannot be
met, because e.g. ``java.io.Serializable`` and ``MyOwnSerializable`` both apply
and neither is a subtype of the other, an exception will be thrown during
serialization.
Akka provides serializers for ``java.io.Serializable`` and `protobuf <http://code.google.com/p/protobuf/>`_
``com.google.protobuf.Message`` by default, so normally you don't need to add configuration for that, but
it can be done to force a specific serializer in case messages implements both ``java.io.Serializable``
and ``com.google.protobuf.Message``.
Akka provides serializers for :class:`java.io.Serializable` and `protobuf
<http://code.google.com/p/protobuf/>`_
:class:`com.google.protobuf.GeneratedMessage` by default (the latter only if
depending on the akka-remote module), so normally you don't need to add
configuration for that; since :class:`com.google.protobuf.GeneratedMessage`
implements :class:`java.io.Serializable`, protobuf messages will always by
serialized using the protobuf protocol unless specifically overridden. In order
to disable a default serializer, map its marker type to “none”::
akka.actor.serialization-bindings {
"java.io.Serializable" = none
}
Verification
------------
@ -91,4 +103,4 @@ which is done by extending ``akka.serialization.JSerializer``, like this:
:exclude: ...
Then you only need to fill in the blanks, bind it to a name in your :ref:`configuration` and then
list which classes that should be serialized using it.
list which classes that should be serialized using it.