format source with scalafmt
This commit is contained in:
parent
0f40491d42
commit
ce404e4f53
1669 changed files with 43208 additions and 35404 deletions
|
|
@ -16,6 +16,7 @@ object ORMap {
|
|||
private val _empty: ORMap[Any, ReplicatedData] = new ORMap(ORSet.empty, Map.empty, VanillaORMapTag)
|
||||
def empty[A, B <: ReplicatedData]: ORMap[A, B] = _empty.asInstanceOf[ORMap[A, B]]
|
||||
def apply(): ORMap[Any, ReplicatedData] = _empty
|
||||
|
||||
/**
|
||||
* Java API
|
||||
*/
|
||||
|
|
@ -52,7 +53,9 @@ object ORMap {
|
|||
/**
|
||||
* INTERNAL API
|
||||
*/
|
||||
@InternalApi private[akka] sealed abstract class AtomicDeltaOp[A, B <: ReplicatedData] extends DeltaOp with ReplicatedDeltaSize {
|
||||
@InternalApi private[akka] sealed abstract class AtomicDeltaOp[A, B <: ReplicatedData]
|
||||
extends DeltaOp
|
||||
with ReplicatedDeltaSize {
|
||||
def underlying: ORSet.DeltaOp
|
||||
def zeroTag: ZeroTag
|
||||
override def zero: DeltaReplicatedData = zeroTag.zero
|
||||
|
|
@ -65,7 +68,10 @@ object ORMap {
|
|||
|
||||
// PutDeltaOp contains ORSet delta and full value
|
||||
/** INTERNAL API */
|
||||
@InternalApi private[akka] final case class PutDeltaOp[A, B <: ReplicatedData](underlying: ORSet.DeltaOp, value: (A, B), zeroTag: ZeroTag) extends AtomicDeltaOp[A, B] {
|
||||
@InternalApi private[akka] final case class PutDeltaOp[A, B <: ReplicatedData](underlying: ORSet.DeltaOp,
|
||||
value: (A, B),
|
||||
zeroTag: ZeroTag)
|
||||
extends AtomicDeltaOp[A, B] {
|
||||
override def merge(that: DeltaOp): DeltaOp = that match {
|
||||
case put: PutDeltaOp[A, B] if this.value._1 == put.value._1 =>
|
||||
new PutDeltaOp[A, B](this.underlying.merge(put.underlying), put.value, zeroTag)
|
||||
|
|
@ -87,21 +93,21 @@ object ORMap {
|
|||
|
||||
// UpdateDeltaOp contains ORSet delta and either delta of value (in case where underlying type supports deltas) or full value
|
||||
/** INTERNAL API */
|
||||
@InternalApi private[akka] final case class UpdateDeltaOp[A, B <: ReplicatedData](underlying: ORSet.DeltaOp, values: Map[A, B], zeroTag: ZeroTag) extends AtomicDeltaOp[A, B] {
|
||||
@InternalApi private[akka] final case class UpdateDeltaOp[A, B <: ReplicatedData](underlying: ORSet.DeltaOp,
|
||||
values: Map[A, B],
|
||||
zeroTag: ZeroTag)
|
||||
extends AtomicDeltaOp[A, B] {
|
||||
override def merge(that: DeltaOp): DeltaOp = that match {
|
||||
case update: UpdateDeltaOp[A, B] =>
|
||||
new UpdateDeltaOp[A, B](
|
||||
this.underlying.merge(update.underlying),
|
||||
update.values.foldLeft(this.values) {
|
||||
(map, pair) =>
|
||||
val (key, value) = pair
|
||||
if (this.values.contains(key)) {
|
||||
val elem1 = this.values(key)
|
||||
val elem2 = value.asInstanceOf[elem1.T]
|
||||
map + (key -> elem1.merge(elem2).asInstanceOf[B])
|
||||
} else map + pair
|
||||
},
|
||||
zeroTag)
|
||||
new UpdateDeltaOp[A, B](this.underlying.merge(update.underlying), update.values.foldLeft(this.values) {
|
||||
(map, pair) =>
|
||||
val (key, value) = pair
|
||||
if (this.values.contains(key)) {
|
||||
val elem1 = this.values(key)
|
||||
val elem2 = value.asInstanceOf[elem1.T]
|
||||
map + (key -> elem1.merge(elem2).asInstanceOf[B])
|
||||
} else map + pair
|
||||
}, zeroTag)
|
||||
case put: PutDeltaOp[A, B] if this.values.size == 1 && this.values.contains(put.value._1) =>
|
||||
new PutDeltaOp[A, B](this.underlying.merge(put.underlying), put.value, zeroTag)
|
||||
case other: AtomicDeltaOp[A, B] => DeltaGroup(Vector(this, other))
|
||||
|
|
@ -111,16 +117,22 @@ object ORMap {
|
|||
|
||||
// RemoveDeltaOp does not contain any value at all - the propagated 'value' map would be empty
|
||||
/** INTERNAL API */
|
||||
@InternalApi private[akka] final case class RemoveDeltaOp[A, B <: ReplicatedData](underlying: ORSet.DeltaOp, zeroTag: ZeroTag) extends AtomicDeltaOp[A, B]
|
||||
@InternalApi private[akka] final case class RemoveDeltaOp[A, B <: ReplicatedData](underlying: ORSet.DeltaOp,
|
||||
zeroTag: ZeroTag)
|
||||
extends AtomicDeltaOp[A, B]
|
||||
|
||||
// RemoveKeyDeltaOp contains a single value - to provide the recipient with the removed key for value map
|
||||
/** INTERNAL API */
|
||||
@InternalApi private[akka] final case class RemoveKeyDeltaOp[A, B <: ReplicatedData](underlying: ORSet.DeltaOp, removedKey: A, zeroTag: ZeroTag) extends AtomicDeltaOp[A, B]
|
||||
@InternalApi private[akka] final case class RemoveKeyDeltaOp[A, B <: ReplicatedData](underlying: ORSet.DeltaOp,
|
||||
removedKey: A,
|
||||
zeroTag: ZeroTag)
|
||||
extends AtomicDeltaOp[A, B]
|
||||
|
||||
// DeltaGroup is effectively a causally ordered list of individual deltas
|
||||
/** INTERNAL API */
|
||||
@InternalApi private[akka] final case class DeltaGroup[A, B <: ReplicatedData](ops: immutable.IndexedSeq[DeltaOp])
|
||||
extends DeltaOp with ReplicatedDeltaSize {
|
||||
extends DeltaOp
|
||||
with ReplicatedDeltaSize {
|
||||
override def merge(that: DeltaOp): DeltaOp = that match {
|
||||
case that: AtomicDeltaOp[A, B] =>
|
||||
ops.last match {
|
||||
|
|
@ -141,7 +153,8 @@ object ORMap {
|
|||
case DeltaGroup(thatOps) => DeltaGroup(ops ++ thatOps)
|
||||
}
|
||||
|
||||
override def zero: DeltaReplicatedData = ops.headOption.fold(ORMap.empty[A, B].asInstanceOf[DeltaReplicatedData])(_.zero)
|
||||
override def zero: DeltaReplicatedData =
|
||||
ops.headOption.fold(ORMap.empty[A, B].asInstanceOf[DeltaReplicatedData])(_.zero)
|
||||
|
||||
override def deltaSize: Int = ops.size
|
||||
}
|
||||
|
|
@ -156,14 +169,15 @@ object ORMap {
|
|||
* This class is immutable, i.e. "modifying" methods return a new instance.
|
||||
*/
|
||||
@SerialVersionUID(1L)
|
||||
final class ORMap[A, B <: ReplicatedData] private[akka] (
|
||||
private[akka] val keys: ORSet[A],
|
||||
private[akka] val values: Map[A, B],
|
||||
private[akka] val zeroTag: ZeroTag,
|
||||
override val delta: Option[ORMap.DeltaOp] = None)
|
||||
extends DeltaReplicatedData with ReplicatedDataSerialization with RemovedNodePruning {
|
||||
final class ORMap[A, B <: ReplicatedData] private[akka] (private[akka] val keys: ORSet[A],
|
||||
private[akka] val values: Map[A, B],
|
||||
private[akka] val zeroTag: ZeroTag,
|
||||
override val delta: Option[ORMap.DeltaOp] = None)
|
||||
extends DeltaReplicatedData
|
||||
with ReplicatedDataSerialization
|
||||
with RemovedNodePruning {
|
||||
|
||||
import ORMap.{ PutDeltaOp, UpdateDeltaOp, RemoveDeltaOp, RemoveKeyDeltaOp }
|
||||
import ORMap.{ PutDeltaOp, RemoveDeltaOp, RemoveKeyDeltaOp, UpdateDeltaOp }
|
||||
|
||||
type T = ORMap[A, B]
|
||||
type D = ORMap.DeltaOp
|
||||
|
|
@ -235,8 +249,8 @@ final class ORMap[A, B <: ReplicatedData] private[akka] (
|
|||
if (value.isInstanceOf[ORSet[_]] && values.contains(key))
|
||||
throw new IllegalArgumentException(
|
||||
"`ORMap.put` must not be used to replace an existing `ORSet` " +
|
||||
"value, because important history can be lost when replacing the `ORSet` and " +
|
||||
"undesired effects of merging will occur. Use `ORMultiMap` or `ORMap.updated` instead.")
|
||||
"value, because important history can be lost when replacing the `ORSet` and " +
|
||||
"undesired effects of merging will occur. Use `ORMultiMap` or `ORMap.updated` instead.")
|
||||
else {
|
||||
val newKeys = keys.resetDelta.add(node, key)
|
||||
val putDeltaOp = PutDeltaOp(newKeys.delta.get, key -> value, zeroTag)
|
||||
|
|
@ -285,7 +299,8 @@ final class ORMap[A, B <: ReplicatedData] private[akka] (
|
|||
/**
|
||||
* INTERNAL API
|
||||
*/
|
||||
@InternalApi private[akka] def updated(node: UniqueAddress, key: A, initial: B, valueDeltas: Boolean = false)(modify: B => B): ORMap[A, B] = {
|
||||
@InternalApi private[akka] def updated(node: UniqueAddress, key: A, initial: B, valueDeltas: Boolean = false)(
|
||||
modify: B => B): ORMap[A, B] = {
|
||||
val (oldValue, hasOldValue) = values.get(key) match {
|
||||
case Some(old) => (old, true)
|
||||
case _ => (initial, false)
|
||||
|
|
@ -411,7 +426,9 @@ final class ORMap[A, B <: ReplicatedData] private[akka] (
|
|||
}
|
||||
|
||||
var mergedKeys: ORSet[A] = this.keys
|
||||
var (mergedValues, tombstonedVals): (Map[A, B], Map[A, B]) = this.values.partition { case (k, _) => this.keys.contains(k) }
|
||||
var (mergedValues, tombstonedVals): (Map[A, B], Map[A, B]) = this.values.partition {
|
||||
case (k, _) => this.keys.contains(k)
|
||||
}
|
||||
|
||||
val processDelta: PartialFunction[ORMap.DeltaOp, Unit] = {
|
||||
case putOp: PutDeltaOp[A, B] =>
|
||||
|
|
@ -466,7 +483,7 @@ final class ORMap[A, B <: ReplicatedData] private[akka] (
|
|||
}
|
||||
}
|
||||
|
||||
(processDelta orElse processNestedDelta)(thatDelta)
|
||||
processDelta.orElse(processNestedDelta)(thatDelta)
|
||||
|
||||
if (withValueDeltas)
|
||||
new ORMap[A, B](mergedKeys, tombstonedVals ++ mergedValues, zeroTag = zeroTag)
|
||||
|
|
@ -497,10 +514,10 @@ final class ORMap[A, B <: ReplicatedData] private[akka] (
|
|||
}
|
||||
|
||||
override def modifiedByNodes: Set[UniqueAddress] = {
|
||||
keys.modifiedByNodes union values.foldLeft(Set.empty[UniqueAddress]) {
|
||||
case (acc, (_, data: RemovedNodePruning)) => acc union data.modifiedByNodes
|
||||
keys.modifiedByNodes.union(values.foldLeft(Set.empty[UniqueAddress]) {
|
||||
case (acc, (_, data: RemovedNodePruning)) => acc.union(data.modifiedByNodes)
|
||||
case (acc, _) => acc
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
override def needPruningFrom(removedNode: UniqueAddress): Boolean = {
|
||||
|
|
@ -553,4 +570,6 @@ object ORMapKey {
|
|||
}
|
||||
|
||||
@SerialVersionUID(1L)
|
||||
final case class ORMapKey[A, B <: ReplicatedData](_id: String) extends Key[ORMap[A, B]](_id) with ReplicatedDataSerialization
|
||||
final case class ORMapKey[A, B <: ReplicatedData](_id: String)
|
||||
extends Key[ORMap[A, B]](_id)
|
||||
with ReplicatedDataSerialization
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue