Preparing mailbox-commons for bin compat
This commit is contained in:
parent
96c5c9392b
commit
ee4a7ce76a
1 changed files with 16 additions and 6 deletions
|
|
@ -3,12 +3,11 @@
|
|||
*/
|
||||
package akka.actor.mailbox
|
||||
|
||||
import akka.actor.{ ActorContext, ActorRef, ExtendedActorSystem }
|
||||
import akka.dispatch.{ Envelope, MessageQueue }
|
||||
import akka.remote.MessageSerializer
|
||||
import akka.remote.RemoteProtocol.{ ActorRefProtocol, RemoteMessageProtocol }
|
||||
import com.typesafe.config.Config
|
||||
import akka.actor.ActorSystem
|
||||
import akka.actor._
|
||||
|
||||
private[akka] object DurableExecutableMailboxConfig {
|
||||
val Name = "[\\.\\/\\$\\s]".r
|
||||
|
|
@ -18,14 +17,21 @@ abstract class DurableMessageQueue(val owner: ActorContext) extends MessageQueue
|
|||
import DurableExecutableMailboxConfig._
|
||||
|
||||
def system: ExtendedActorSystem = owner.system.asInstanceOf[ExtendedActorSystem]
|
||||
def ownerPath = owner.self.path
|
||||
val ownerPathString = ownerPath.elements.mkString("/")
|
||||
val name = "mailbox_" + Name.replaceAllIn(ownerPathString, "_")
|
||||
def ownerPath: ActorPath = owner.self.path
|
||||
val ownerPathString: String = ownerPath.elements.mkString("/")
|
||||
val name: String = "mailbox_" + Name.replaceAllIn(ownerPathString, "_")
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* DurableMessageSerialization can be mixed into a DurableMessageQueue and adds functionality
|
||||
* to serialize and deserialize Envelopes (messages)
|
||||
*/
|
||||
trait DurableMessageSerialization { this: DurableMessageQueue ⇒
|
||||
|
||||
/**
|
||||
* Serializes the given Envelope into an Array of Bytes using an efficient serialization/deserialization strategy
|
||||
*/
|
||||
def serialize(durableMessage: Envelope): Array[Byte] = {
|
||||
|
||||
// It's alright to use ref.path.toString here
|
||||
|
|
@ -42,6 +48,10 @@ trait DurableMessageSerialization { this: DurableMessageQueue ⇒
|
|||
builder.build.toByteArray
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes an array of Bytes that were serialized using the DurableMessageSerialization.serialize method,
|
||||
* into an Envelope.
|
||||
*/
|
||||
def deserialize(bytes: Array[Byte]): Envelope = {
|
||||
|
||||
def deserializeActorRef(refProtocol: ActorRefProtocol): ActorRef = system.actorFor(refProtocol.getPath)
|
||||
|
|
@ -50,7 +60,7 @@ trait DurableMessageSerialization { this: DurableMessageQueue ⇒
|
|||
val message = MessageSerializer.deserialize(system, durableMessage.getMessage)
|
||||
val sender = deserializeActorRef(durableMessage.getSender)
|
||||
|
||||
new Envelope(message, sender)(system)
|
||||
Envelope(message, sender)(system)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue