!per #3707 Channel enhancements
- Persistent channel - ConfirmablePersistent message type delivered by channel - Sender resolution performance improvements * unstash() instead of unstashAll() These enhancements required the following changes - Unified implementation of processor stash and user stash - Persistence message plugin API separated from implementation - Physical deletion of messages
This commit is contained in:
parent
8fb59a0bc6
commit
ba9fc4da46
41 changed files with 2167 additions and 722 deletions
|
|
@ -12,43 +12,56 @@ import akka.actor.ExtendedActorSystem
|
|||
import akka.japi.Util.immutableSeq
|
||||
import akka.persistence._
|
||||
import akka.persistence.serialization.MessageFormats._
|
||||
import akka.persistence.serialization.MessageFormats.DeliverMessage.ResolveStrategy
|
||||
import akka.serialization._
|
||||
|
||||
/**
|
||||
* Protobuf serializer for [[Persistent]] and `Confirm` messages.
|
||||
* Marker trait for all protobuf-serializable messages in `akka.persistence`.
|
||||
*/
|
||||
trait Message extends Serializable
|
||||
|
||||
/**
|
||||
* Protobuf serializer for [[PersistentBatch]], [[PersistentRepr]] and [[Deliver]] messages.
|
||||
*/
|
||||
class MessageSerializer(val system: ExtendedActorSystem) extends Serializer {
|
||||
import PersistentImpl.Undefined
|
||||
import PersistentRepr.Undefined
|
||||
|
||||
val PersistentBatchClass = classOf[PersistentBatch]
|
||||
val PersistentClass = classOf[PersistentImpl]
|
||||
val PersistentReprClass = classOf[PersistentRepr]
|
||||
val PersistentImplClass = classOf[PersistentImpl]
|
||||
val ConfirmablePersistentImplClass = classOf[ConfirmablePersistentImpl]
|
||||
val ConfirmClass = classOf[Confirm]
|
||||
val DeliverClass = classOf[Deliver]
|
||||
|
||||
def identifier: Int = 7
|
||||
def includeManifest: Boolean = true
|
||||
|
||||
/**
|
||||
* Serializes [[PersistentBatch]] and [[Persistent]]. Delegates serialization of a
|
||||
* persistent message's payload to a matching `akka.serialization.Serializer`.
|
||||
* Serializes [[PersistentBatch]], [[PersistentRepr]] and [[Deliver]] messages. Delegates
|
||||
* serialization of a persistent message's payload to a matching `akka.serialization.Serializer`.
|
||||
*/
|
||||
def toBinary(o: AnyRef): Array[Byte] = o match {
|
||||
case b: PersistentBatch ⇒ persistentMessageBatchBuilder(b).build().toByteArray
|
||||
case p: PersistentImpl ⇒ persistentMessageBuilder(p).build().toByteArray
|
||||
case p: PersistentRepr ⇒ persistentMessageBuilder(p).build().toByteArray
|
||||
case c: Confirm ⇒ confirmMessageBuilder(c).build().toByteArray
|
||||
case d: Deliver ⇒ deliverMessageBuilder(d).build.toByteArray
|
||||
case _ ⇒ throw new IllegalArgumentException(s"Can't serialize object of type ${o.getClass}")
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes [[PersistentBatch]] and [[Persistent]]. Delegates deserialization of a
|
||||
* persistent message's payload to a matching `akka.serialization.Serializer`.
|
||||
* Deserializes [[PersistentBatch]], [[PersistentRepr]] and [[Deliver]] messages. Delegates
|
||||
* deserialization of a persistent message's payload to a matching `akka.serialization.Serializer`.
|
||||
*/
|
||||
def fromBinary(bytes: Array[Byte], manifest: Option[Class[_]]): AnyRef = manifest match {
|
||||
def fromBinary(bytes: Array[Byte], manifest: Option[Class[_]]): Message = manifest match {
|
||||
case None ⇒ persistent(PersistentMessage.parseFrom(bytes))
|
||||
case Some(c) ⇒ c match {
|
||||
case PersistentBatchClass ⇒ persistentBatch(PersistentMessageBatch.parseFrom(bytes))
|
||||
case PersistentClass ⇒ persistent(PersistentMessage.parseFrom(bytes))
|
||||
case ConfirmClass ⇒ confirm(ConfirmMessage.parseFrom(bytes))
|
||||
case _ ⇒ throw new IllegalArgumentException(s"Can't deserialize object of type ${c}")
|
||||
case PersistentImplClass ⇒ persistent(PersistentMessage.parseFrom(bytes))
|
||||
case ConfirmablePersistentImplClass ⇒ persistent(PersistentMessage.parseFrom(bytes))
|
||||
case PersistentReprClass ⇒ persistent(PersistentMessage.parseFrom(bytes))
|
||||
case PersistentBatchClass ⇒ persistentBatch(PersistentMessageBatch.parseFrom(bytes))
|
||||
case ConfirmClass ⇒ confirm(ConfirmMessage.parseFrom(bytes))
|
||||
case DeliverClass ⇒ deliver(DeliverMessage.parseFrom(bytes))
|
||||
case _ ⇒ throw new IllegalArgumentException(s"Can't deserialize object of type ${c}")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -56,17 +69,27 @@ class MessageSerializer(val system: ExtendedActorSystem) extends Serializer {
|
|||
// toBinary helpers
|
||||
//
|
||||
|
||||
private def deliverMessageBuilder(deliver: Deliver) = {
|
||||
val builder = DeliverMessage.newBuilder
|
||||
builder.setPersistent(persistentMessageBuilder(deliver.persistent.asInstanceOf[PersistentRepr]))
|
||||
builder.setDestination(Serialization.serializedActorPath(deliver.destination))
|
||||
deliver.resolve match {
|
||||
case Resolve.Off ⇒ builder.setResolve(DeliverMessage.ResolveStrategy.Off)
|
||||
case Resolve.Sender ⇒ builder.setResolve(DeliverMessage.ResolveStrategy.Sender)
|
||||
case Resolve.Destination ⇒ builder.setResolve(DeliverMessage.ResolveStrategy.Destination)
|
||||
}
|
||||
}
|
||||
|
||||
private def persistentMessageBatchBuilder(persistentBatch: PersistentBatch) = {
|
||||
val builder = PersistentMessageBatch.newBuilder
|
||||
persistentBatch.persistentImplList.foreach(p ⇒ builder.addBatch(persistentMessageBuilder(p)))
|
||||
persistentBatch.persistentReprList.foreach(p ⇒ builder.addBatch(persistentMessageBuilder(p)))
|
||||
builder
|
||||
}
|
||||
|
||||
private def persistentMessageBuilder(persistent: PersistentImpl) = {
|
||||
private def persistentMessageBuilder(persistent: PersistentRepr) = {
|
||||
val builder = PersistentMessage.newBuilder
|
||||
|
||||
if (persistent.processorId != Undefined) builder.setProcessorId(persistent.processorId)
|
||||
if (persistent.channelId != Undefined) builder.setChannelId(persistent.channelId)
|
||||
if (persistent.confirmMessage != null) builder.setConfirmMessage(confirmMessageBuilder(persistent.confirmMessage))
|
||||
if (persistent.confirmTarget != null) builder.setConfirmTarget(Serialization.serializedActorPath(persistent.confirmTarget))
|
||||
if (persistent.sender != null) builder.setSender(Serialization.serializedActorPath(persistent.sender))
|
||||
|
|
@ -77,6 +100,7 @@ class MessageSerializer(val system: ExtendedActorSystem) extends Serializer {
|
|||
builder.setSequenceNr(persistent.sequenceNr)
|
||||
builder.setDeleted(persistent.deleted)
|
||||
builder.setResolved(persistent.resolved)
|
||||
builder.setConfirmable(persistent.confirmable)
|
||||
builder
|
||||
}
|
||||
|
||||
|
|
@ -102,18 +126,29 @@ class MessageSerializer(val system: ExtendedActorSystem) extends Serializer {
|
|||
// fromBinary helpers
|
||||
//
|
||||
|
||||
private def deliver(deliverMessage: DeliverMessage): Deliver = {
|
||||
Deliver(
|
||||
persistent(deliverMessage.getPersistent),
|
||||
system.provider.resolveActorRef(deliverMessage.getDestination),
|
||||
deliverMessage.getResolve match {
|
||||
case ResolveStrategy.Off ⇒ Resolve.Off
|
||||
case ResolveStrategy.Sender ⇒ Resolve.Sender
|
||||
case ResolveStrategy.Destination ⇒ Resolve.Destination
|
||||
})
|
||||
}
|
||||
|
||||
private def persistentBatch(persistentMessageBatch: PersistentMessageBatch): PersistentBatch =
|
||||
PersistentBatch(immutableSeq(persistentMessageBatch.getBatchList).map(persistent))
|
||||
|
||||
private def persistent(persistentMessage: PersistentMessage): PersistentImpl = {
|
||||
PersistentImpl(
|
||||
private def persistent(persistentMessage: PersistentMessage): PersistentRepr = {
|
||||
PersistentRepr(
|
||||
payload(persistentMessage.getPayload),
|
||||
persistentMessage.getSequenceNr,
|
||||
if (persistentMessage.hasProcessorId) persistentMessage.getProcessorId else Undefined,
|
||||
if (persistentMessage.hasChannelId) persistentMessage.getChannelId else Undefined,
|
||||
persistentMessage.getDeleted,
|
||||
persistentMessage.getResolved,
|
||||
immutableSeq(persistentMessage.getConfirmsList),
|
||||
persistentMessage.getConfirmable,
|
||||
if (persistentMessage.hasConfirmMessage) confirm(persistentMessage.getConfirmMessage) else null,
|
||||
if (persistentMessage.hasConfirmTarget) system.provider.resolveActorRef(persistentMessage.getConfirmTarget) else null,
|
||||
if (persistentMessage.hasSender) system.provider.resolveActorRef(persistentMessage.getSender) else null)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue