Merge pull request #142 from jboner/wip-1447-actor-context-not-serializable-√
Making sure that ActorCell isn't serializable
This commit is contained in:
commit
b4f486667f
3 changed files with 22 additions and 4 deletions
|
|
@ -7,10 +7,9 @@ package akka.serialization
|
|||
import akka.serialization.Serialization._
|
||||
import scala.reflect._
|
||||
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 akka.actor._
|
||||
import java.io._
|
||||
|
||||
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 {
|
||||
val outbuf = new ByteArrayOutputStream()
|
||||
val out = new ObjectOutputStream(outbuf)
|
||||
|
|
|
|||
|
|
@ -185,7 +185,6 @@ trait Actor {
|
|||
* [[akka.actor.UntypedActorContext]], which is the Java API of the actor
|
||||
* context.
|
||||
*/
|
||||
@transient
|
||||
protected[akka] implicit val context: ActorContext = {
|
||||
val contextStack = ActorCell.contextStack.get
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import java.util.concurrent.TimeUnit.MILLISECONDS
|
|||
import akka.event.Logging.{ Debug, Warning, Error }
|
||||
import akka.util.{ Duration, Helpers }
|
||||
import akka.japi.Procedure
|
||||
import java.io.{ NotSerializableException, ObjectOutputStream }
|
||||
|
||||
/**
|
||||
* The actor context - the view of the actor cell from the actor.
|
||||
|
|
@ -111,6 +112,9 @@ trait ActorContext extends ActorRefFactory {
|
|||
* @return the provided ActorRef
|
||||
*/
|
||||
def unwatch(subject: ActorRef): ActorRef
|
||||
|
||||
final protected def writeObject(o: ObjectOutputStream): Unit =
|
||||
throw new NotSerializableException("ActorContext is not serializable!")
|
||||
}
|
||||
|
||||
trait UntypedActorContext extends ActorContext {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue