2011-06-07 06:36:21 +05:30
|
|
|
package akka.serialization
|
|
|
|
|
|
|
|
|
|
/**
|
2013-01-09 01:47:48 +01:00
|
|
|
* Copyright (C) 2009-2013 Typesafe Inc. <http://www.typesafe.com>
|
2011-06-07 06:36:21 +05:30
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import java.io.{ ObjectOutputStream, ByteArrayOutputStream, ObjectInputStream, ByteArrayInputStream }
|
2012-12-18 01:25:21 +01:00
|
|
|
import java.util.concurrent.Callable
|
2011-06-07 06:36:21 +05:30
|
|
|
import akka.util.ClassLoaderObjectInputStream
|
Bye-bye ReflectiveAccess, introducing PropertyMaster, see #1750
- PropertyMaster is the only place in Akka which calls
ClassLoader.getClass (apart from kernel, which might be special)
- all PropertyMaster methods (there are only three) take a ClassManifest
of what is to be constructed, and they verify that the obtained object
is actually compatible with the required type
Other stuff:
- noticed that I had forgotten to change to ExtendedActorSystem when
constructing Extensions by ExtensionKey (damn you, reflection!)
- moved Serializer.currentSystem into JavaSerializer, because that’s the
only one needing it (it’s only used in readResolve() methods)
- Serializers are constructed now with one-arg constructor taking
ExtendedActorSystem (if that exists, otherwise no-arg as before), to
allow JavaSerializer to do its magic; possibly necessary for others as
well
- Removed all Option[ClassLoader] signatures
- made it so that the ActorSystem will try context class loader, then
the class loader which loaded the class actually calling into
ActorSystem.apply, then the loader which loaded ActorSystemImpl
- for the second of the above I added a (reflectively accessed hopefully
safe) facility for getting caller Class[_] objects by using
sun.reflect.Reflection; this is optional an defaults to None, e.g. on
Android, which means that getting the caller’s classloader is done on
a best effort basis (there’s nothing we can do because a StackTrace
does not contain actual Class[_] objects).
- refactored DurableMailbox to contain the owner val and use that
instead of declaring that in all subclasses
2012-02-09 11:56:43 +01:00
|
|
|
import akka.actor.ExtendedActorSystem
|
|
|
|
|
import scala.util.DynamicVariable
|
2012-12-18 01:25:21 +01:00
|
|
|
import akka.serialization.JavaSerializer.CurrentSystem
|
2011-07-19 14:20:18 +02:00
|
|
|
|
2011-07-19 19:28:17 +02:00
|
|
|
/**
|
Bye-bye ReflectiveAccess, introducing PropertyMaster, see #1750
- PropertyMaster is the only place in Akka which calls
ClassLoader.getClass (apart from kernel, which might be special)
- all PropertyMaster methods (there are only three) take a ClassManifest
of what is to be constructed, and they verify that the obtained object
is actually compatible with the required type
Other stuff:
- noticed that I had forgotten to change to ExtendedActorSystem when
constructing Extensions by ExtensionKey (damn you, reflection!)
- moved Serializer.currentSystem into JavaSerializer, because that’s the
only one needing it (it’s only used in readResolve() methods)
- Serializers are constructed now with one-arg constructor taking
ExtendedActorSystem (if that exists, otherwise no-arg as before), to
allow JavaSerializer to do its magic; possibly necessary for others as
well
- Removed all Option[ClassLoader] signatures
- made it so that the ActorSystem will try context class loader, then
the class loader which loaded the class actually calling into
ActorSystem.apply, then the loader which loaded ActorSystemImpl
- for the second of the above I added a (reflectively accessed hopefully
safe) facility for getting caller Class[_] objects by using
sun.reflect.Reflection; this is optional an defaults to None, e.g. on
Android, which means that getting the caller’s classloader is done on
a best effort basis (there’s nothing we can do because a StackTrace
does not contain actual Class[_] objects).
- refactored DurableMailbox to contain the owner val and use that
instead of declaring that in all subclasses
2012-02-09 11:56:43 +01:00
|
|
|
* A Serializer represents a bimap between an object and an array of bytes representing that object.
|
|
|
|
|
*
|
|
|
|
|
* Serializers are loaded using reflection during [[akka.actor.ActorSystem]]
|
|
|
|
|
* start-up, where two constructors are tried in order:
|
|
|
|
|
*
|
|
|
|
|
* <ul>
|
|
|
|
|
* <li>taking exactly one argument of type [[akka.actor.ExtendedActorSystem]];
|
|
|
|
|
* this should be the preferred one because all reflective loading of classes
|
2012-02-10 11:36:23 +01:00
|
|
|
* during deserialization should use ExtendedActorSystem.dynamicAccess (see
|
|
|
|
|
* [[akka.actor.DynamicAccess]]), and</li>
|
Bye-bye ReflectiveAccess, introducing PropertyMaster, see #1750
- PropertyMaster is the only place in Akka which calls
ClassLoader.getClass (apart from kernel, which might be special)
- all PropertyMaster methods (there are only three) take a ClassManifest
of what is to be constructed, and they verify that the obtained object
is actually compatible with the required type
Other stuff:
- noticed that I had forgotten to change to ExtendedActorSystem when
constructing Extensions by ExtensionKey (damn you, reflection!)
- moved Serializer.currentSystem into JavaSerializer, because that’s the
only one needing it (it’s only used in readResolve() methods)
- Serializers are constructed now with one-arg constructor taking
ExtendedActorSystem (if that exists, otherwise no-arg as before), to
allow JavaSerializer to do its magic; possibly necessary for others as
well
- Removed all Option[ClassLoader] signatures
- made it so that the ActorSystem will try context class loader, then
the class loader which loaded the class actually calling into
ActorSystem.apply, then the loader which loaded ActorSystemImpl
- for the second of the above I added a (reflectively accessed hopefully
safe) facility for getting caller Class[_] objects by using
sun.reflect.Reflection; this is optional an defaults to None, e.g. on
Android, which means that getting the caller’s classloader is done on
a best effort basis (there’s nothing we can do because a StackTrace
does not contain actual Class[_] objects).
- refactored DurableMailbox to contain the owner val and use that
instead of declaring that in all subclasses
2012-02-09 11:56:43 +01:00
|
|
|
* <li>without arguments, which is only an option if the serializer does not
|
|
|
|
|
* load classes using reflection.</li>
|
|
|
|
|
* </ul>
|
|
|
|
|
*
|
2012-02-09 19:26:02 +01:00
|
|
|
* <b>Be sure to always use the PropertyManager for loading classes!</b> This is necessary to
|
|
|
|
|
* avoid strange match errors and inequalities which arise from different class loaders loading
|
|
|
|
|
* the same class.
|
2011-07-19 19:28:17 +02:00
|
|
|
*/
|
2012-02-06 14:19:59 +01:00
|
|
|
trait Serializer {
|
Bye-bye ReflectiveAccess, introducing PropertyMaster, see #1750
- PropertyMaster is the only place in Akka which calls
ClassLoader.getClass (apart from kernel, which might be special)
- all PropertyMaster methods (there are only three) take a ClassManifest
of what is to be constructed, and they verify that the obtained object
is actually compatible with the required type
Other stuff:
- noticed that I had forgotten to change to ExtendedActorSystem when
constructing Extensions by ExtensionKey (damn you, reflection!)
- moved Serializer.currentSystem into JavaSerializer, because that’s the
only one needing it (it’s only used in readResolve() methods)
- Serializers are constructed now with one-arg constructor taking
ExtendedActorSystem (if that exists, otherwise no-arg as before), to
allow JavaSerializer to do its magic; possibly necessary for others as
well
- Removed all Option[ClassLoader] signatures
- made it so that the ActorSystem will try context class loader, then
the class loader which loaded the class actually calling into
ActorSystem.apply, then the loader which loaded ActorSystemImpl
- for the second of the above I added a (reflectively accessed hopefully
safe) facility for getting caller Class[_] objects by using
sun.reflect.Reflection; this is optional an defaults to None, e.g. on
Android, which means that getting the caller’s classloader is done on
a best effort basis (there’s nothing we can do because a StackTrace
does not contain actual Class[_] objects).
- refactored DurableMailbox to contain the owner val and use that
instead of declaring that in all subclasses
2012-02-09 11:56:43 +01:00
|
|
|
|
2011-07-19 14:20:18 +02:00
|
|
|
/**
|
2011-12-29 16:11:56 +01:00
|
|
|
* Completely unique value to identify this implementation of Serializer, used to optimize network traffic
|
2011-07-19 14:20:18 +02:00
|
|
|
* Values from 0 to 16 is reserved for Akka internal usage
|
|
|
|
|
*/
|
2011-12-30 22:00:49 +01:00
|
|
|
def identifier: Int
|
2011-07-19 19:28:17 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Serializes the given object into an Array of Byte
|
|
|
|
|
*/
|
2011-06-07 06:36:21 +05:30
|
|
|
def toBinary(o: AnyRef): Array[Byte]
|
2011-07-19 19:28:17 +02:00
|
|
|
|
2011-12-29 16:11:56 +01:00
|
|
|
/**
|
|
|
|
|
* Returns whether this serializer needs a manifest in the fromBinary method
|
|
|
|
|
*/
|
|
|
|
|
def includeManifest: Boolean
|
|
|
|
|
|
2011-12-30 22:00:49 +01:00
|
|
|
/**
|
Bye-bye ReflectiveAccess, introducing PropertyMaster, see #1750
- PropertyMaster is the only place in Akka which calls
ClassLoader.getClass (apart from kernel, which might be special)
- all PropertyMaster methods (there are only three) take a ClassManifest
of what is to be constructed, and they verify that the obtained object
is actually compatible with the required type
Other stuff:
- noticed that I had forgotten to change to ExtendedActorSystem when
constructing Extensions by ExtensionKey (damn you, reflection!)
- moved Serializer.currentSystem into JavaSerializer, because that’s the
only one needing it (it’s only used in readResolve() methods)
- Serializers are constructed now with one-arg constructor taking
ExtendedActorSystem (if that exists, otherwise no-arg as before), to
allow JavaSerializer to do its magic; possibly necessary for others as
well
- Removed all Option[ClassLoader] signatures
- made it so that the ActorSystem will try context class loader, then
the class loader which loaded the class actually calling into
ActorSystem.apply, then the loader which loaded ActorSystemImpl
- for the second of the above I added a (reflectively accessed hopefully
safe) facility for getting caller Class[_] objects by using
sun.reflect.Reflection; this is optional an defaults to None, e.g. on
Android, which means that getting the caller’s classloader is done on
a best effort basis (there’s nothing we can do because a StackTrace
does not contain actual Class[_] objects).
- refactored DurableMailbox to contain the owner val and use that
instead of declaring that in all subclasses
2012-02-09 11:56:43 +01:00
|
|
|
* Produces an object from an array of bytes, with an optional type-hint;
|
2012-02-10 11:36:23 +01:00
|
|
|
* the class should be loaded using ActorSystem.dynamicAccess.
|
2011-07-19 19:28:17 +02:00
|
|
|
*/
|
Bye-bye ReflectiveAccess, introducing PropertyMaster, see #1750
- PropertyMaster is the only place in Akka which calls
ClassLoader.getClass (apart from kernel, which might be special)
- all PropertyMaster methods (there are only three) take a ClassManifest
of what is to be constructed, and they verify that the obtained object
is actually compatible with the required type
Other stuff:
- noticed that I had forgotten to change to ExtendedActorSystem when
constructing Extensions by ExtensionKey (damn you, reflection!)
- moved Serializer.currentSystem into JavaSerializer, because that’s the
only one needing it (it’s only used in readResolve() methods)
- Serializers are constructed now with one-arg constructor taking
ExtendedActorSystem (if that exists, otherwise no-arg as before), to
allow JavaSerializer to do its magic; possibly necessary for others as
well
- Removed all Option[ClassLoader] signatures
- made it so that the ActorSystem will try context class loader, then
the class loader which loaded the class actually calling into
ActorSystem.apply, then the loader which loaded ActorSystemImpl
- for the second of the above I added a (reflectively accessed hopefully
safe) facility for getting caller Class[_] objects by using
sun.reflect.Reflection; this is optional an defaults to None, e.g. on
Android, which means that getting the caller’s classloader is done on
a best effort basis (there’s nothing we can do because a StackTrace
does not contain actual Class[_] objects).
- refactored DurableMailbox to contain the owner val and use that
instead of declaring that in all subclasses
2012-02-09 11:56:43 +01:00
|
|
|
def fromBinary(bytes: Array[Byte], manifest: Option[Class[_]]): AnyRef
|
2012-02-10 12:45:22 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Java API: deserialize without type hint
|
|
|
|
|
*/
|
|
|
|
|
final def fromBinary(bytes: Array[Byte]): AnyRef = fromBinary(bytes, None)
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Java API: deserialize with type hint
|
|
|
|
|
*/
|
|
|
|
|
final def fromBinary(bytes: Array[Byte], clazz: Class[_]): AnyRef = fromBinary(bytes, Option(clazz))
|
2011-12-30 22:00:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
Bye-bye ReflectiveAccess, introducing PropertyMaster, see #1750
- PropertyMaster is the only place in Akka which calls
ClassLoader.getClass (apart from kernel, which might be special)
- all PropertyMaster methods (there are only three) take a ClassManifest
of what is to be constructed, and they verify that the obtained object
is actually compatible with the required type
Other stuff:
- noticed that I had forgotten to change to ExtendedActorSystem when
constructing Extensions by ExtensionKey (damn you, reflection!)
- moved Serializer.currentSystem into JavaSerializer, because that’s the
only one needing it (it’s only used in readResolve() methods)
- Serializers are constructed now with one-arg constructor taking
ExtendedActorSystem (if that exists, otherwise no-arg as before), to
allow JavaSerializer to do its magic; possibly necessary for others as
well
- Removed all Option[ClassLoader] signatures
- made it so that the ActorSystem will try context class loader, then
the class loader which loaded the class actually calling into
ActorSystem.apply, then the loader which loaded ActorSystemImpl
- for the second of the above I added a (reflectively accessed hopefully
safe) facility for getting caller Class[_] objects by using
sun.reflect.Reflection; this is optional an defaults to None, e.g. on
Android, which means that getting the caller’s classloader is done on
a best effort basis (there’s nothing we can do because a StackTrace
does not contain actual Class[_] objects).
- refactored DurableMailbox to contain the owner val and use that
instead of declaring that in all subclasses
2012-02-09 11:56:43 +01:00
|
|
|
* Java API for creating a Serializer: make sure to include a constructor which
|
|
|
|
|
* takes exactly one argument of type [[akka.actor.ExtendedActorSystem]], because
|
|
|
|
|
* that is the preferred constructor which will be invoked when reflectively instantiating
|
|
|
|
|
* the JSerializer (also possible with empty constructor).
|
2011-12-30 22:00:49 +01:00
|
|
|
*/
|
|
|
|
|
abstract class JSerializer extends Serializer {
|
2012-02-10 12:45:22 +01:00
|
|
|
final def fromBinary(bytes: Array[Byte], manifest: Option[Class[_]]): AnyRef =
|
|
|
|
|
fromBinaryJava(bytes, manifest.orNull)
|
2011-12-30 22:00:49 +01:00
|
|
|
|
|
|
|
|
/**
|
2012-02-10 12:45:22 +01:00
|
|
|
* This method must be implemented, manifest may be null.
|
2011-12-30 22:00:49 +01:00
|
|
|
*/
|
2012-02-10 12:45:22 +01:00
|
|
|
protected def fromBinaryJava(bytes: Array[Byte], manifest: Class[_]): AnyRef
|
2011-06-07 06:36:21 +05:30
|
|
|
}
|
|
|
|
|
|
2011-07-19 14:20:18 +02:00
|
|
|
object NullSerializer extends NullSerializer
|
|
|
|
|
|
Bye-bye ReflectiveAccess, introducing PropertyMaster, see #1750
- PropertyMaster is the only place in Akka which calls
ClassLoader.getClass (apart from kernel, which might be special)
- all PropertyMaster methods (there are only three) take a ClassManifest
of what is to be constructed, and they verify that the obtained object
is actually compatible with the required type
Other stuff:
- noticed that I had forgotten to change to ExtendedActorSystem when
constructing Extensions by ExtensionKey (damn you, reflection!)
- moved Serializer.currentSystem into JavaSerializer, because that’s the
only one needing it (it’s only used in readResolve() methods)
- Serializers are constructed now with one-arg constructor taking
ExtendedActorSystem (if that exists, otherwise no-arg as before), to
allow JavaSerializer to do its magic; possibly necessary for others as
well
- Removed all Option[ClassLoader] signatures
- made it so that the ActorSystem will try context class loader, then
the class loader which loaded the class actually calling into
ActorSystem.apply, then the loader which loaded ActorSystemImpl
- for the second of the above I added a (reflectively accessed hopefully
safe) facility for getting caller Class[_] objects by using
sun.reflect.Reflection; this is optional an defaults to None, e.g. on
Android, which means that getting the caller’s classloader is done on
a best effort basis (there’s nothing we can do because a StackTrace
does not contain actual Class[_] objects).
- refactored DurableMailbox to contain the owner val and use that
instead of declaring that in all subclasses
2012-02-09 11:56:43 +01:00
|
|
|
object JavaSerializer {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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...
|
|
|
|
|
* }
|
2012-12-18 01:25:21 +01:00
|
|
|
*
|
|
|
|
|
* or
|
|
|
|
|
*
|
|
|
|
|
* currentSystem.withValue(system, callable)
|
Bye-bye ReflectiveAccess, introducing PropertyMaster, see #1750
- PropertyMaster is the only place in Akka which calls
ClassLoader.getClass (apart from kernel, which might be special)
- all PropertyMaster methods (there are only three) take a ClassManifest
of what is to be constructed, and they verify that the obtained object
is actually compatible with the required type
Other stuff:
- noticed that I had forgotten to change to ExtendedActorSystem when
constructing Extensions by ExtensionKey (damn you, reflection!)
- moved Serializer.currentSystem into JavaSerializer, because that’s the
only one needing it (it’s only used in readResolve() methods)
- Serializers are constructed now with one-arg constructor taking
ExtendedActorSystem (if that exists, otherwise no-arg as before), to
allow JavaSerializer to do its magic; possibly necessary for others as
well
- Removed all Option[ClassLoader] signatures
- made it so that the ActorSystem will try context class loader, then
the class loader which loaded the class actually calling into
ActorSystem.apply, then the loader which loaded ActorSystemImpl
- for the second of the above I added a (reflectively accessed hopefully
safe) facility for getting caller Class[_] objects by using
sun.reflect.Reflection; this is optional an defaults to None, e.g. on
Android, which means that getting the caller’s classloader is done on
a best effort basis (there’s nothing we can do because a StackTrace
does not contain actual Class[_] objects).
- refactored DurableMailbox to contain the owner val and use that
instead of declaring that in all subclasses
2012-02-09 11:56:43 +01:00
|
|
|
*/
|
2012-12-18 01:25:21 +01:00
|
|
|
val currentSystem = new CurrentSystem
|
|
|
|
|
final class CurrentSystem extends DynamicVariable[ExtendedActorSystem](null) {
|
|
|
|
|
/**
|
|
|
|
|
* Java API
|
|
|
|
|
* @param value - the current value under the call to callable.call()
|
|
|
|
|
* @param callable - the operation to be performed
|
|
|
|
|
* @tparam S - the return type
|
|
|
|
|
* @return the result of callable.call()
|
|
|
|
|
*/
|
|
|
|
|
def withValue[S](value: ExtendedActorSystem, callable: Callable[S]): S = super.withValue[S](value)(callable.call)
|
|
|
|
|
}
|
Bye-bye ReflectiveAccess, introducing PropertyMaster, see #1750
- PropertyMaster is the only place in Akka which calls
ClassLoader.getClass (apart from kernel, which might be special)
- all PropertyMaster methods (there are only three) take a ClassManifest
of what is to be constructed, and they verify that the obtained object
is actually compatible with the required type
Other stuff:
- noticed that I had forgotten to change to ExtendedActorSystem when
constructing Extensions by ExtensionKey (damn you, reflection!)
- moved Serializer.currentSystem into JavaSerializer, because that’s the
only one needing it (it’s only used in readResolve() methods)
- Serializers are constructed now with one-arg constructor taking
ExtendedActorSystem (if that exists, otherwise no-arg as before), to
allow JavaSerializer to do its magic; possibly necessary for others as
well
- Removed all Option[ClassLoader] signatures
- made it so that the ActorSystem will try context class loader, then
the class loader which loaded the class actually calling into
ActorSystem.apply, then the loader which loaded ActorSystemImpl
- for the second of the above I added a (reflectively accessed hopefully
safe) facility for getting caller Class[_] objects by using
sun.reflect.Reflection; this is optional an defaults to None, e.g. on
Android, which means that getting the caller’s classloader is done on
a best effort basis (there’s nothing we can do because a StackTrace
does not contain actual Class[_] objects).
- refactored DurableMailbox to contain the owner val and use that
instead of declaring that in all subclasses
2012-02-09 11:56:43 +01:00
|
|
|
}
|
|
|
|
|
|
2011-12-29 16:17:19 +01:00
|
|
|
/**
|
|
|
|
|
* This Serializer uses standard Java Serialization
|
|
|
|
|
*/
|
Bye-bye ReflectiveAccess, introducing PropertyMaster, see #1750
- PropertyMaster is the only place in Akka which calls
ClassLoader.getClass (apart from kernel, which might be special)
- all PropertyMaster methods (there are only three) take a ClassManifest
of what is to be constructed, and they verify that the obtained object
is actually compatible with the required type
Other stuff:
- noticed that I had forgotten to change to ExtendedActorSystem when
constructing Extensions by ExtensionKey (damn you, reflection!)
- moved Serializer.currentSystem into JavaSerializer, because that’s the
only one needing it (it’s only used in readResolve() methods)
- Serializers are constructed now with one-arg constructor taking
ExtendedActorSystem (if that exists, otherwise no-arg as before), to
allow JavaSerializer to do its magic; possibly necessary for others as
well
- Removed all Option[ClassLoader] signatures
- made it so that the ActorSystem will try context class loader, then
the class loader which loaded the class actually calling into
ActorSystem.apply, then the loader which loaded ActorSystemImpl
- for the second of the above I added a (reflectively accessed hopefully
safe) facility for getting caller Class[_] objects by using
sun.reflect.Reflection; this is optional an defaults to None, e.g. on
Android, which means that getting the caller’s classloader is done on
a best effort basis (there’s nothing we can do because a StackTrace
does not contain actual Class[_] objects).
- refactored DurableMailbox to contain the owner val and use that
instead of declaring that in all subclasses
2012-02-09 11:56:43 +01:00
|
|
|
class JavaSerializer(val system: ExtendedActorSystem) extends Serializer {
|
2011-07-19 14:20:18 +02:00
|
|
|
|
2011-12-29 16:11:56 +01:00
|
|
|
def includeManifest: Boolean = false
|
|
|
|
|
|
2011-12-30 22:00:49 +01:00
|
|
|
def identifier = 1
|
2011-07-19 14:20:18 +02:00
|
|
|
|
2011-06-07 06:36:21 +05:30
|
|
|
def toBinary(o: AnyRef): Array[Byte] = {
|
|
|
|
|
val bos = new ByteArrayOutputStream
|
|
|
|
|
val out = new ObjectOutputStream(bos)
|
2012-02-20 11:06:12 +01:00
|
|
|
JavaSerializer.currentSystem.withValue(system) { out.writeObject(o) }
|
2011-06-07 06:36:21 +05:30
|
|
|
out.close()
|
|
|
|
|
bos.toByteArray
|
|
|
|
|
}
|
|
|
|
|
|
Bye-bye ReflectiveAccess, introducing PropertyMaster, see #1750
- PropertyMaster is the only place in Akka which calls
ClassLoader.getClass (apart from kernel, which might be special)
- all PropertyMaster methods (there are only three) take a ClassManifest
of what is to be constructed, and they verify that the obtained object
is actually compatible with the required type
Other stuff:
- noticed that I had forgotten to change to ExtendedActorSystem when
constructing Extensions by ExtensionKey (damn you, reflection!)
- moved Serializer.currentSystem into JavaSerializer, because that’s the
only one needing it (it’s only used in readResolve() methods)
- Serializers are constructed now with one-arg constructor taking
ExtendedActorSystem (if that exists, otherwise no-arg as before), to
allow JavaSerializer to do its magic; possibly necessary for others as
well
- Removed all Option[ClassLoader] signatures
- made it so that the ActorSystem will try context class loader, then
the class loader which loaded the class actually calling into
ActorSystem.apply, then the loader which loaded ActorSystemImpl
- for the second of the above I added a (reflectively accessed hopefully
safe) facility for getting caller Class[_] objects by using
sun.reflect.Reflection; this is optional an defaults to None, e.g. on
Android, which means that getting the caller’s classloader is done on
a best effort basis (there’s nothing we can do because a StackTrace
does not contain actual Class[_] objects).
- refactored DurableMailbox to contain the owner val and use that
instead of declaring that in all subclasses
2012-02-09 11:56:43 +01:00
|
|
|
def fromBinary(bytes: Array[Byte], clazz: Option[Class[_]]): AnyRef = {
|
2012-02-10 11:36:23 +01:00
|
|
|
val in = new ClassLoaderObjectInputStream(system.dynamicAccess.classLoader, new ByteArrayInputStream(bytes))
|
2012-02-20 11:06:12 +01:00
|
|
|
val obj = JavaSerializer.currentSystem.withValue(system) { in.readObject }
|
2011-06-07 06:36:21 +05:30
|
|
|
in.close()
|
|
|
|
|
obj
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-29 16:17:19 +01:00
|
|
|
/**
|
|
|
|
|
* This is a special Serializer that Serializes and deserializes nulls only
|
|
|
|
|
*/
|
2011-07-19 14:20:18 +02:00
|
|
|
class NullSerializer extends Serializer {
|
|
|
|
|
val nullAsBytes = Array[Byte]()
|
2011-12-29 16:11:56 +01:00
|
|
|
def includeManifest: Boolean = false
|
2011-12-30 22:00:49 +01:00
|
|
|
def identifier = 0
|
2011-07-19 14:20:18 +02:00
|
|
|
def toBinary(o: AnyRef) = nullAsBytes
|
Bye-bye ReflectiveAccess, introducing PropertyMaster, see #1750
- PropertyMaster is the only place in Akka which calls
ClassLoader.getClass (apart from kernel, which might be special)
- all PropertyMaster methods (there are only three) take a ClassManifest
of what is to be constructed, and they verify that the obtained object
is actually compatible with the required type
Other stuff:
- noticed that I had forgotten to change to ExtendedActorSystem when
constructing Extensions by ExtensionKey (damn you, reflection!)
- moved Serializer.currentSystem into JavaSerializer, because that’s the
only one needing it (it’s only used in readResolve() methods)
- Serializers are constructed now with one-arg constructor taking
ExtendedActorSystem (if that exists, otherwise no-arg as before), to
allow JavaSerializer to do its magic; possibly necessary for others as
well
- Removed all Option[ClassLoader] signatures
- made it so that the ActorSystem will try context class loader, then
the class loader which loaded the class actually calling into
ActorSystem.apply, then the loader which loaded ActorSystemImpl
- for the second of the above I added a (reflectively accessed hopefully
safe) facility for getting caller Class[_] objects by using
sun.reflect.Reflection; this is optional an defaults to None, e.g. on
Android, which means that getting the caller’s classloader is done on
a best effort basis (there’s nothing we can do because a StackTrace
does not contain actual Class[_] objects).
- refactored DurableMailbox to contain the owner val and use that
instead of declaring that in all subclasses
2012-02-09 11:56:43 +01:00
|
|
|
def fromBinary(bytes: Array[Byte], clazz: Option[Class[_]]): AnyRef = null
|
2011-06-07 06:36:21 +05:30
|
|
|
}
|
2012-09-27 00:59:33 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This is a special Serializer that Serializes and deserializes byte arrays only,
|
|
|
|
|
* (just returns the byte array unchanged/uncopied)
|
|
|
|
|
*/
|
|
|
|
|
class ByteArraySerializer extends Serializer {
|
|
|
|
|
def includeManifest: Boolean = false
|
|
|
|
|
def identifier = 4
|
|
|
|
|
def toBinary(o: AnyRef) = o match {
|
|
|
|
|
case null ⇒ null
|
|
|
|
|
case o: Array[Byte] ⇒ o
|
|
|
|
|
case other ⇒ throw new IllegalArgumentException("ByteArraySerializer only serializes byte arrays, not [" + other + "]")
|
|
|
|
|
}
|
|
|
|
|
def fromBinary(bytes: Array[Byte], clazz: Option[Class[_]]): AnyRef = bytes
|
|
|
|
|
}
|