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
This commit is contained in:
Roland 2012-02-09 11:56:43 +01:00
parent 15fa414d46
commit 2ce47d6bb5
35 changed files with 322 additions and 300 deletions

View file

@ -3,6 +3,7 @@
*/
package akka.docs.serialization;
import akka.japi.Option;
import akka.serialization.JSerializer;
import akka.serialization.Serialization;
import akka.serialization.SerializationExtension;
@ -13,6 +14,7 @@ import static org.junit.Assert.*;
import akka.serialization.*;
import akka.actor.ActorSystem;
import akka.actor.PropertyMaster;
import com.typesafe.config.*;
//#imports
@ -45,8 +47,7 @@ public class SerializationDocTestBase {
// using the type hint (if any, see "includeManifest" above)
// into the optionally provided classLoader.
@Override public Object fromBinary(byte[] bytes,
Class clazz,
ClassLoader classLoader) {
Class clazz) {
// Put your code that deserializes here
//#...
return null;
@ -128,7 +129,7 @@ public class SerializationDocTestBase {
// Turn it back into an object,
// the nulls are for the class manifest and for the classloader
String back = (String)serializer.fromBinary(bytes);
String back = (String)serializer.fromBinary(bytes, Option.<Class<?>>none().asScala());
// Voilá!
assertEquals(original, back);