Merge pull request #142 from jboner/wip-1447-actor-context-not-serializable-√

Making sure that ActorCell isn't serializable
This commit is contained in:
viktorklang 2011-12-08 08:45:34 -08:00
commit b4f486667f
3 changed files with 22 additions and 4 deletions

View file

@ -7,10 +7,9 @@ package akka.serialization
import akka.serialization.Serialization._ import akka.serialization.Serialization._
import scala.reflect._ import scala.reflect._
import akka.testkit.AkkaSpec import akka.testkit.AkkaSpec
import akka.actor.{ ActorSystem, ActorSystemImpl }
import java.io.{ ObjectInputStream, ByteArrayInputStream, ByteArrayOutputStream, ObjectOutputStream }
import akka.actor.DeadLetterActorRef
import com.typesafe.config.ConfigFactory import com.typesafe.config.ConfigFactory
import akka.actor._
import java.io._
object SerializeSpec { object SerializeSpec {
@ -94,6 +93,22 @@ class SerializeSpec extends AkkaSpec(SerializeSpec.serializationConf) {
} }
} }
"not serialize ActorCell" in {
val a = system.actorOf(Props(new Actor {
def receive = {
case o: ObjectOutputStream
try {
o.writeObject(this)
} catch {
case _: NotSerializableException testActor ! "pass"
}
}
}))
a ! new ObjectOutputStream(new ByteArrayOutputStream())
expectMsg("pass")
a.stop()
}
"serialize DeadLetterActorRef" in { "serialize DeadLetterActorRef" in {
val outbuf = new ByteArrayOutputStream() val outbuf = new ByteArrayOutputStream()
val out = new ObjectOutputStream(outbuf) val out = new ObjectOutputStream(outbuf)

View file

@ -185,7 +185,6 @@ trait Actor {
* [[akka.actor.UntypedActorContext]], which is the Java API of the actor * [[akka.actor.UntypedActorContext]], which is the Java API of the actor
* context. * context.
*/ */
@transient
protected[akka] implicit val context: ActorContext = { protected[akka] implicit val context: ActorContext = {
val contextStack = ActorCell.contextStack.get val contextStack = ActorCell.contextStack.get

View file

@ -12,6 +12,7 @@ import java.util.concurrent.TimeUnit.MILLISECONDS
import akka.event.Logging.{ Debug, Warning, Error } import akka.event.Logging.{ Debug, Warning, Error }
import akka.util.{ Duration, Helpers } import akka.util.{ Duration, Helpers }
import akka.japi.Procedure import akka.japi.Procedure
import java.io.{ NotSerializableException, ObjectOutputStream }
/** /**
* The actor context - the view of the actor cell from the actor. * The actor context - the view of the actor cell from the actor.
@ -111,6 +112,9 @@ trait ActorContext extends ActorRefFactory {
* @return the provided ActorRef * @return the provided ActorRef
*/ */
def unwatch(subject: ActorRef): ActorRef def unwatch(subject: ActorRef): ActorRef
final protected def writeObject(o: ObjectOutputStream): Unit =
throw new NotSerializableException("ActorContext is not serializable!")
} }
trait UntypedActorContext extends ActorContext { trait UntypedActorContext extends ActorContext {