Made Format serializers serializable
This commit is contained in:
parent
b929fd13e0
commit
50bb069885
3 changed files with 25 additions and 27 deletions
|
|
@ -107,21 +107,20 @@ object Actor extends Logging {
|
|||
def actorOf[T <: Actor : Manifest]: ActorRef = actorOf(manifest[T].erasure.asInstanceOf[Class[_ <: Actor]])
|
||||
|
||||
/**
|
||||
* Creates an ActorRef out of the Actor with type T.
|
||||
* <pre>
|
||||
* import Actor._
|
||||
* val actor = actorOf[MyActor]
|
||||
* actor.start
|
||||
* actor ! message
|
||||
* actor.stop
|
||||
* </pre>
|
||||
* You can create and start the actor in one statement like this:
|
||||
* <pre>
|
||||
* val actor = actorOf[MyActor].start
|
||||
* </pre>
|
||||
*/
|
||||
def actorOf(clazz: Class[_ <: Actor]): ActorRef = new LocalActorRef(clazz)
|
||||
|
||||
* Creates an ActorRef out of the Actor with type T.
|
||||
* <pre>
|
||||
* import Actor._
|
||||
* val actor = actorOf[MyActor]
|
||||
* actor.start
|
||||
* actor ! message
|
||||
* actor.stop
|
||||
* </pre>
|
||||
* You can create and start the actor in one statement like this:
|
||||
* <pre>
|
||||
* val actor = actorOf[MyActor].start
|
||||
* </pre>
|
||||
*/
|
||||
def actorOf(clazz: Class[_ <: Actor]): ActorRef = new LocalActorRef(clazz)
|
||||
|
||||
/**
|
||||
* Creates an ActorRef out of the Actor. Allows you to pass in a factory function
|
||||
|
|
@ -249,7 +248,6 @@ trait Actor extends Logging {
|
|||
"\n\t\t'val actor = Actor.actorOf[MyActor]', or" +
|
||||
"\n\t\t'val actor = Actor.actorOf(new MyActor(..))', or" +
|
||||
"\n\t\t'val actor = Actor.actor { case msg => .. } }'")
|
||||
|
||||
val ref = optRef.asInstanceOf[Some[ActorRef]].get
|
||||
ref.id = getClass.getName //FIXME: Is this needed?
|
||||
optRef.asInstanceOf[Some[ActorRef]]
|
||||
|
|
@ -368,17 +366,17 @@ trait Actor extends Logging {
|
|||
private lazy val processingBehavior: Receive = {
|
||||
lazy val defaultBehavior = receive
|
||||
val actorBehavior: Receive = {
|
||||
case HotSwap(code) => become(code)
|
||||
case RevertHotSwap => unbecome
|
||||
case Exit(dead, reason) => self.handleTrapExit(dead, reason)
|
||||
case Link(child) => self.link(child)
|
||||
case Unlink(child) => self.unlink(child)
|
||||
case UnlinkAndStop(child) => self.unlink(child); child.stop
|
||||
case Restart(reason) => throw reason
|
||||
case HotSwap(code) => become(code)
|
||||
case RevertHotSwap => unbecome
|
||||
case Exit(dead, reason) => self.handleTrapExit(dead, reason)
|
||||
case Link(child) => self.link(child)
|
||||
case Unlink(child) => self.unlink(child)
|
||||
case UnlinkAndStop(child) => self.unlink(child); child.stop
|
||||
case Restart(reason) => throw reason
|
||||
case msg if !self.hotswap.isEmpty &&
|
||||
self.hotswap.head.isDefinedAt(msg) => self.hotswap.head.apply(msg)
|
||||
case msg if self.hotswap.isEmpty &&
|
||||
defaultBehavior.isDefinedAt(msg) => defaultBehavior.apply(msg)
|
||||
defaultBehavior.isDefinedAt(msg) => defaultBehavior.apply(msg)
|
||||
}
|
||||
actorBehavior
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ trait Format[T <: Actor] extends FromBinary[T] with ToBinary[T]
|
|||
* }
|
||||
* </pre>
|
||||
*/
|
||||
trait StatelessActorFormat[T <: Actor] extends Format[T] {
|
||||
@serializable trait StatelessActorFormat[T <: Actor] extends Format[T] {
|
||||
def fromBinary(bytes: Array[Byte], act: T) = act
|
||||
|
||||
def toBinary(ac: T) = Array.empty[Byte]
|
||||
|
|
@ -65,7 +65,7 @@ trait StatelessActorFormat[T <: Actor] extends Format[T] {
|
|||
* }
|
||||
* </pre>
|
||||
*/
|
||||
trait SerializerBasedActorFormat[T <: Actor] extends Format[T] {
|
||||
@serializable trait SerializerBasedActorFormat[T <: Actor] extends Format[T] {
|
||||
val serializer: Serializer
|
||||
|
||||
def fromBinary(bytes: Array[Byte], act: T) = serializer.fromBinary(bytes, Some(act.self.actorClass)).asInstanceOf[T]
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ import sjson.json.{Serializer => SJSONSerializer}
|
|||
/**
|
||||
* @author <a href="http://jonasboner.com">Jonas Bonér</a>
|
||||
*/
|
||||
trait Serializer {
|
||||
@serializable trait Serializer {
|
||||
var classLoader: Option[ClassLoader] = None
|
||||
def deepClone(obj: AnyRef): AnyRef = fromBinary(toBinary(obj), Some(obj.getClass))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue