Previously know as [patriknw/akka-data-replication](https://github.com/patriknw/akka-data-replication), which was originally inspired by [jboner/akka-crdt](https://github.com/jboner/akka-crdt). The functionality is very similar to akka-data-replication 0.11. Here is a list of the most important changes: * The package name changed to `akka.cluster.ddata` * The extension was renamed to `DistributedData` * The keys changed from strings to classes with unique identifiers and type information of the data values, e.g. `ORSetKey[Int]("set2")` * The optional read consistency parameter was removed from the `Update` message. If you need to read from other replicas before performing the update you have to first send a `Get` message and then continue with the ``Update`` when the ``GetSuccess`` is received. * `BigInt` is used in `GCounter` and `PNCounter` instead of `Long` * Improvements of java api * Better documentation
29 lines
776 B
Scala
29 lines
776 B
Scala
/**
|
|
* Copyright (C) 2015 Typesafe Inc. <http://www.typesafe.com>
|
|
*/
|
|
package docs.ddata
|
|
|
|
import akka.cluster.ddata.ReplicatedData
|
|
import akka.cluster.ddata.GSet
|
|
|
|
//#twophaseset
|
|
case class TwoPhaseSet(
|
|
adds: GSet[String] = GSet.empty,
|
|
removals: GSet[String] = GSet.empty)
|
|
extends ReplicatedData {
|
|
type T = TwoPhaseSet
|
|
|
|
def add(element: String): TwoPhaseSet =
|
|
copy(adds = adds.add(element))
|
|
|
|
def remove(element: String): TwoPhaseSet =
|
|
copy(removals = removals.add(element))
|
|
|
|
def elements: Set[String] = adds.elements -- removals.elements
|
|
|
|
override def merge(that: TwoPhaseSet): TwoPhaseSet =
|
|
copy(
|
|
adds = GSet(this.adds.elements ++ that.adds.elements),
|
|
removals = GSet(this.removals.elements ++ that.removals.elements))
|
|
}
|
|
//#twophaseset
|