Skip to content

Commit

Permalink
Made Format serializers serializable
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonas Bonér committed Oct 21, 2010
1 parent 1c96a11 commit bb1338a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 27 deletions.
46 changes: 22 additions & 24 deletions akka-actor/src/main/scala/actor/Actor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]]
Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion akka-remote/src/main/scala/serialization/Serializer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import sjson.json.{Serializer => SJSONSerializer}
/**
* @author <a href="http://jonasboner.com">Jonas Bon&#233;r</a>
*/
trait Serializer {
@serializable trait Serializer {
var classLoader: Option[ClassLoader] = None
def deepClone(obj: AnyRef): AnyRef = fromBinary(toBinary(obj), Some(obj.getClass))

Expand Down

0 comments on commit bb1338a

Please sign in to comment.