format source with scalafmt
This commit is contained in:
parent
0f40491d42
commit
ce404e4f53
1669 changed files with 43208 additions and 35404 deletions
|
|
@ -60,15 +60,17 @@ class MessageSerializer(val system: ExtendedActorSystem) extends BaseSerializer
|
|||
*/
|
||||
def fromBinary(bytes: Array[Byte], manifest: Option[Class[_]]): Message = manifest match {
|
||||
case None => persistent(mf.PersistentMessage.parseFrom(bytes))
|
||||
case Some(c) => c match {
|
||||
case PersistentImplClass => persistent(mf.PersistentMessage.parseFrom(bytes))
|
||||
case PersistentReprClass => persistent(mf.PersistentMessage.parseFrom(bytes))
|
||||
case AtomicWriteClass => atomicWrite(mf.AtomicWrite.parseFrom(bytes))
|
||||
case AtLeastOnceDeliverySnapshotClass => atLeastOnceDeliverySnapshot(mf.AtLeastOnceDeliverySnapshot.parseFrom(bytes))
|
||||
case PersistentStateChangeEventClass => stateChange(mf.PersistentStateChangeEvent.parseFrom(bytes))
|
||||
case PersistentFSMSnapshotClass => persistentFSMSnapshot(mf.PersistentFSMSnapshot.parseFrom(bytes))
|
||||
case _ => throw new NotSerializableException(s"Can't deserialize object of type ${c}")
|
||||
}
|
||||
case Some(c) =>
|
||||
c match {
|
||||
case PersistentImplClass => persistent(mf.PersistentMessage.parseFrom(bytes))
|
||||
case PersistentReprClass => persistent(mf.PersistentMessage.parseFrom(bytes))
|
||||
case AtomicWriteClass => atomicWrite(mf.AtomicWrite.parseFrom(bytes))
|
||||
case AtLeastOnceDeliverySnapshotClass =>
|
||||
atLeastOnceDeliverySnapshot(mf.AtLeastOnceDeliverySnapshot.parseFrom(bytes))
|
||||
case PersistentStateChangeEventClass => stateChange(mf.PersistentStateChangeEvent.parseFrom(bytes))
|
||||
case PersistentFSMSnapshotClass => persistentFSMSnapshot(mf.PersistentFSMSnapshot.parseFrom(bytes))
|
||||
case _ => throw new NotSerializableException(s"Can't deserialize object of type ${c}")
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
|
@ -80,10 +82,10 @@ class MessageSerializer(val system: ExtendedActorSystem) extends BaseSerializer
|
|||
builder.setCurrentDeliveryId(snap.currentDeliveryId)
|
||||
snap.unconfirmedDeliveries.foreach { unconfirmed =>
|
||||
val unconfirmedBuilder =
|
||||
mf.AtLeastOnceDeliverySnapshot.UnconfirmedDelivery.newBuilder.
|
||||
setDeliveryId(unconfirmed.deliveryId).
|
||||
setDestination(unconfirmed.destination.toString).
|
||||
setPayload(persistentPayloadBuilder(unconfirmed.message.asInstanceOf[AnyRef]))
|
||||
mf.AtLeastOnceDeliverySnapshot.UnconfirmedDelivery.newBuilder
|
||||
.setDeliveryId(unconfirmed.deliveryId)
|
||||
.setDestination(unconfirmed.destination.toString)
|
||||
.setPayload(persistentPayloadBuilder(unconfirmed.message.asInstanceOf[AnyRef]))
|
||||
builder.addUnconfirmedDeliveries(unconfirmedBuilder)
|
||||
}
|
||||
builder
|
||||
|
|
@ -97,7 +99,8 @@ class MessageSerializer(val system: ExtendedActorSystem) extends BaseSerializer
|
|||
}
|
||||
}
|
||||
|
||||
private[persistence] def persistentFSMSnapshotBuilder(persistentFSMSnapshot: PersistentFSMSnapshot[Any]): mf.PersistentFSMSnapshot.Builder = {
|
||||
private[persistence] def persistentFSMSnapshotBuilder(
|
||||
persistentFSMSnapshot: PersistentFSMSnapshot[Any]): mf.PersistentFSMSnapshot.Builder = {
|
||||
val builder = mf.PersistentFSMSnapshot.newBuilder
|
||||
.setStateIdentifier(persistentFSMSnapshot.stateIdentifier)
|
||||
.setData(persistentPayloadBuilder(persistentFSMSnapshot.data.asInstanceOf[AnyRef]))
|
||||
|
|
@ -107,33 +110,35 @@ class MessageSerializer(val system: ExtendedActorSystem) extends BaseSerializer
|
|||
}
|
||||
}
|
||||
|
||||
def atLeastOnceDeliverySnapshot(atLeastOnceDeliverySnapshot: mf.AtLeastOnceDeliverySnapshot): AtLeastOnceDeliverySnapshot = {
|
||||
def atLeastOnceDeliverySnapshot(
|
||||
atLeastOnceDeliverySnapshot: mf.AtLeastOnceDeliverySnapshot): AtLeastOnceDeliverySnapshot = {
|
||||
import scala.collection.JavaConverters._
|
||||
val unconfirmedDeliveries = new VectorBuilder[UnconfirmedDelivery]()
|
||||
atLeastOnceDeliverySnapshot.getUnconfirmedDeliveriesList().iterator().asScala foreach { next =>
|
||||
unconfirmedDeliveries += UnconfirmedDelivery(next.getDeliveryId, ActorPath.fromString(next.getDestination),
|
||||
payload(next.getPayload))
|
||||
atLeastOnceDeliverySnapshot.getUnconfirmedDeliveriesList().iterator().asScala.foreach { next =>
|
||||
unconfirmedDeliveries += UnconfirmedDelivery(next.getDeliveryId,
|
||||
ActorPath.fromString(next.getDestination),
|
||||
payload(next.getPayload))
|
||||
}
|
||||
|
||||
AtLeastOnceDeliverySnapshot(
|
||||
atLeastOnceDeliverySnapshot.getCurrentDeliveryId,
|
||||
unconfirmedDeliveries.result())
|
||||
AtLeastOnceDeliverySnapshot(atLeastOnceDeliverySnapshot.getCurrentDeliveryId, unconfirmedDeliveries.result())
|
||||
}
|
||||
|
||||
def stateChange(persistentStateChange: mf.PersistentStateChangeEvent): StateChangeEvent = {
|
||||
StateChangeEvent(
|
||||
persistentStateChange.getStateIdentifier,
|
||||
// timeout field is deprecated, left for backward compatibility. timeoutNanos is used instead.
|
||||
if (persistentStateChange.hasTimeoutNanos) Some(Duration.fromNanos(persistentStateChange.getTimeoutNanos))
|
||||
else if (persistentStateChange.hasTimeout) Some(Duration(persistentStateChange.getTimeout).asInstanceOf[duration.FiniteDuration])
|
||||
else None)
|
||||
StateChangeEvent(persistentStateChange.getStateIdentifier,
|
||||
// timeout field is deprecated, left for backward compatibility. timeoutNanos is used instead.
|
||||
if (persistentStateChange.hasTimeoutNanos)
|
||||
Some(Duration.fromNanos(persistentStateChange.getTimeoutNanos))
|
||||
else if (persistentStateChange.hasTimeout)
|
||||
Some(Duration(persistentStateChange.getTimeout).asInstanceOf[duration.FiniteDuration])
|
||||
else None)
|
||||
}
|
||||
|
||||
def persistentFSMSnapshot(persistentFSMSnapshot: mf.PersistentFSMSnapshot): PersistentFSMSnapshot[Any] = {
|
||||
PersistentFSMSnapshot(
|
||||
persistentFSMSnapshot.getStateIdentifier,
|
||||
payload(persistentFSMSnapshot.getData),
|
||||
if (persistentFSMSnapshot.hasTimeoutNanos) Some(Duration.fromNanos(persistentFSMSnapshot.getTimeoutNanos)) else None)
|
||||
PersistentFSMSnapshot(persistentFSMSnapshot.getStateIdentifier,
|
||||
payload(persistentFSMSnapshot.getData),
|
||||
if (persistentFSMSnapshot.hasTimeoutNanos)
|
||||
Some(Duration.fromNanos(persistentFSMSnapshot.getTimeoutNanos))
|
||||
else None)
|
||||
}
|
||||
|
||||
private def atomicWriteBuilder(a: AtomicWrite) = {
|
||||
|
|
@ -184,14 +189,14 @@ class MessageSerializer(val system: ExtendedActorSystem) extends BaseSerializer
|
|||
//
|
||||
|
||||
private def persistent(persistentMessage: mf.PersistentMessage): PersistentRepr = {
|
||||
PersistentRepr(
|
||||
payload(persistentMessage.getPayload),
|
||||
persistentMessage.getSequenceNr,
|
||||
if (persistentMessage.hasPersistenceId) persistentMessage.getPersistenceId else Undefined,
|
||||
if (persistentMessage.hasManifest) persistentMessage.getManifest else Undefined,
|
||||
if (persistentMessage.hasDeleted) persistentMessage.getDeleted else false,
|
||||
if (persistentMessage.hasSender) system.provider.resolveActorRef(persistentMessage.getSender) else Actor.noSender,
|
||||
if (persistentMessage.hasWriterUuid) persistentMessage.getWriterUuid else Undefined)
|
||||
PersistentRepr(payload(persistentMessage.getPayload),
|
||||
persistentMessage.getSequenceNr,
|
||||
if (persistentMessage.hasPersistenceId) persistentMessage.getPersistenceId else Undefined,
|
||||
if (persistentMessage.hasManifest) persistentMessage.getManifest else Undefined,
|
||||
if (persistentMessage.hasDeleted) persistentMessage.getDeleted else false,
|
||||
if (persistentMessage.hasSender) system.provider.resolveActorRef(persistentMessage.getSender)
|
||||
else Actor.noSender,
|
||||
if (persistentMessage.hasWriterUuid) persistentMessage.getWriterUuid else Undefined)
|
||||
}
|
||||
|
||||
private def atomicWrite(atomicWrite: mf.AtomicWrite): AtomicWrite = {
|
||||
|
|
@ -200,13 +205,12 @@ class MessageSerializer(val system: ExtendedActorSystem) extends BaseSerializer
|
|||
}
|
||||
|
||||
private def payload(persistentPayload: mf.PersistentPayload): Any = {
|
||||
val manifest = if (persistentPayload.hasPayloadManifest)
|
||||
persistentPayload.getPayloadManifest.toStringUtf8 else ""
|
||||
val manifest =
|
||||
if (persistentPayload.hasPayloadManifest)
|
||||
persistentPayload.getPayloadManifest.toStringUtf8
|
||||
else ""
|
||||
|
||||
serialization.deserialize(
|
||||
persistentPayload.getPayload.toByteArray,
|
||||
persistentPayload.getSerializerId,
|
||||
manifest).get
|
||||
serialization.deserialize(persistentPayload.getPayload.toByteArray, persistentPayload.getSerializerId, manifest).get
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue