Adding more docs to Serialization and making sure that the Protobuf stuff gets its manifests
This commit is contained in:
parent
cffe60bf43
commit
e78739f7e5
5 changed files with 29 additions and 13 deletions
|
|
@ -16,7 +16,7 @@ import com.google.protobuf.Message
|
|||
|
||||
class ProtobufSerializer extends Serializer {
|
||||
val ARRAY_OF_BYTE_ARRAY = Array[Class[_]](classOf[Array[Byte]])
|
||||
def includeManifest: Boolean = false
|
||||
def includeManifest: Boolean = true
|
||||
def identifier = 2: Serializer.Identifier
|
||||
|
||||
def toBinary(obj: AnyRef): Array[Byte] = {
|
||||
|
|
|
|||
|
|
@ -184,7 +184,7 @@ object TypedActor extends ExtensionId[TypedActorExtension] with ExtensionIdProvi
|
|||
* @throws the underlying exception if there's an InvocationTargetException thrown on the invocation
|
||||
*/
|
||||
def apply(instance: AnyRef): AnyRef = try {
|
||||
parameters match { //TODO: We do not yet obey Actor.SERIALIZE_MESSAGES
|
||||
parameters match {
|
||||
case null ⇒ method.invoke(instance)
|
||||
case args if args.length == 0 ⇒ method.invoke(instance)
|
||||
case args ⇒ method.invoke(instance, args: _*)
|
||||
|
|
|
|||
|
|
@ -14,8 +14,18 @@ import akka.actor.{ Extension, ActorSystem, ActorSystemImpl }
|
|||
case class NoSerializerFoundException(m: String) extends AkkaException(m)
|
||||
|
||||
object Serialization {
|
||||
// TODO ensure that these are always set (i.e. withValue()) when doing deserialization
|
||||
val currentSystem = new DynamicVariable[ActorSystemImpl](null)
|
||||
/**
|
||||
* This holds a reference to the current ActorSystem (the surrounding context)
|
||||
* during serialization and deserialization.
|
||||
*
|
||||
* If you are using Serializers yourself, outside of SerializationExtension,
|
||||
* you'll need to surround the serialization/deserialization with:
|
||||
*
|
||||
* currentSystem.withValue(system) {
|
||||
* ...code...
|
||||
* }
|
||||
*/
|
||||
val currentSystem = new DynamicVariable[ActorSystem](null)
|
||||
|
||||
class Settings(val config: Config) {
|
||||
|
||||
|
|
@ -139,14 +149,11 @@ class Serialization(val system: ActorSystemImpl) extends Extension {
|
|||
* bindings is a Map whose keys = FQN of class that is serializable and values = the alias of the serializer to be used
|
||||
*/
|
||||
lazy val bindings: Map[String, String] = {
|
||||
val configBindings = settings.SerializationBindings
|
||||
configBindings.foldLeft(Map[String, String]()) {
|
||||
case (result, (k: String, vs: Seq[_])) ⇒
|
||||
settings.SerializationBindings.foldLeft(Map[String, String]()) {
|
||||
//All keys which are lists, take the Strings from them and Map them
|
||||
result ++ (vs collect { case v: String ⇒ (v, k) })
|
||||
case (result, x) ⇒
|
||||
case (result, (k: String, vs: Seq[_])) ⇒ result ++ (vs collect { case v: String ⇒ (v, k) })
|
||||
//For any other values, just skip them
|
||||
result
|
||||
case (result, _) ⇒ result
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -40,6 +40,9 @@ trait Serializer extends scala.Serializable {
|
|||
object JavaSerializer extends JavaSerializer
|
||||
object NullSerializer extends NullSerializer
|
||||
|
||||
/**
|
||||
* This Serializer uses standard Java Serialization
|
||||
*/
|
||||
class JavaSerializer extends Serializer {
|
||||
|
||||
def includeManifest: Boolean = false
|
||||
|
|
@ -65,6 +68,9 @@ class JavaSerializer extends Serializer {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a special Serializer that Serializes and deserializes nulls only
|
||||
*/
|
||||
class NullSerializer extends Serializer {
|
||||
val nullAsBytes = Array[Byte]()
|
||||
def includeManifest: Boolean = false
|
||||
|
|
|
|||
|
|
@ -7,9 +7,12 @@ package akka.serialization
|
|||
import akka.serialization.Serializer
|
||||
import com.google.protobuf.Message
|
||||
|
||||
/**
|
||||
* This Serializer serializes `com.google.protobuf.Message`s
|
||||
*/
|
||||
class ProtobufSerializer extends Serializer {
|
||||
val ARRAY_OF_BYTE_ARRAY = Array[Class[_]](classOf[Array[Byte]])
|
||||
def includeManifest: Boolean = false
|
||||
def includeManifest: Boolean = true
|
||||
def identifier = 2: Serializer.Identifier
|
||||
|
||||
def toBinary(obj: AnyRef): Array[Byte] = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue