public final class LWWMap<A> extends java.lang.Object implements ReplicatedData, ReplicatedDataSerialization, RemovedNodePruning
ORMap
with LWWRegister
values.
LWWRegister
relies on synchronized clocks and should only be used when the choice of
value is not important for concurrent updates occurring within the clock skew.
Instead of using timestamps based on System.currentTimeMillis()
time it is possible to
use a timestamp value based on something else, for example an increasing version number
from a database record that is used for optimistic concurrency control.
The defaultClock
is using max value of System.currentTimeMillis()
and currentTimestamp + 1
.
This means that the timestamp is increased for changes on the same node that occurs within
the same millisecond. It also means that it is safe to use the LWWMap
without
synchronized clocks when there is only one active writer, e.g. a Cluster Singleton. Such a
single writer should then first read current value with ReadMajority
(or more) before
changing and writing the value with WriteMajority
(or more).
For first-write-wins semantics you can use the LWWRegister.reverseClock()
instead of the
LWWRegister.defaultClock()
This class is immutable, i.e. "modifying" methods return a new instance.
Constructor and Description |
---|
LWWMap(ORMap<LWWRegister<A>> underlying) |
Modifier and Type | Method and Description |
---|---|
static LWWMap<java.lang.Object> |
apply() |
boolean |
contains(java.lang.String key) |
static <A> LWWMap<A> |
create()
Java API
|
static <A> LWWMap<A> |
empty() |
scala.collection.immutable.Map<java.lang.String,A> |
entries()
Scala API: All entries of the map.
|
boolean |
equals(java.lang.Object o) |
scala.Option<A> |
get(java.lang.String key) |
java.util.Map<java.lang.String,A> |
getEntries()
Java API: All entries of the map.
|
int |
hashCode() |
boolean |
isEmpty() |
LWWMap<A> |
merge(LWWMap<A> that) |
boolean |
needPruningFrom(UniqueAddress removedNode)
Does it have any state changes from a specific node,
which has been removed from the cluster.
|
LWWMap<A> |
prune(UniqueAddress removedNode,
UniqueAddress collapseInto)
When the
removed node has been removed from the cluster the state
changes from that node will be pruned by collapsing the data entries
to another node. |
LWWMap<A> |
pruningCleanup(UniqueAddress removedNode)
Remove data entries from a node that has been removed from the cluster
and already been pruned.
|
LWWMap<A> |
put(Cluster node,
java.lang.String key,
A value)
Adds an entry to the map
|
LWWMap<A> |
put(Cluster node,
java.lang.String key,
A value,
LWWRegister.Clock<A> clock)
Adds an entry to the map.
|
LWWMap<A> |
put(java.lang.String key,
A value,
Cluster node,
LWWRegister.Clock<A> clock)
Adds an entry to the map.
|
LWWMap<A> |
put(UniqueAddress node,
java.lang.String key,
A value,
LWWRegister.Clock<A> clock)
INTERNAL API
|
LWWMap<A> |
remove(Cluster node,
java.lang.String key)
Removes an entry from the map.
|
LWWMap<A> |
remove(UniqueAddress node,
java.lang.String key)
INTERNAL API
|
int |
size() |
java.lang.String |
toString() |
static <A> scala.Option<scala.collection.immutable.Map<java.lang.String,A>> |
unapply(LWWMap<A> m)
Extract the
entries() . |
ORMap<LWWRegister<A>> |
underlying() |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
merge
public LWWMap(ORMap<LWWRegister<A>> underlying)
public static <A> LWWMap<A> empty()
public static LWWMap<java.lang.Object> apply()
public static <A> LWWMap<A> create()
public static <A> scala.Option<scala.collection.immutable.Map<java.lang.String,A>> unapply(LWWMap<A> m)
entries()
.m
- (undocumented)public ORMap<LWWRegister<A>> underlying()
public scala.collection.immutable.Map<java.lang.String,A> entries()
public java.util.Map<java.lang.String,A> getEntries()
public scala.Option<A> get(java.lang.String key)
public boolean contains(java.lang.String key)
public boolean isEmpty()
public int size()
public LWWMap<A> put(Cluster node, java.lang.String key, A value)
node
- (undocumented)key
- (undocumented)value
- (undocumented)public LWWMap<A> put(Cluster node, java.lang.String key, A value, LWWRegister.Clock<A> clock)
You can provide your clock
implementation instead of using timestamps based
on System.currentTimeMillis()
time. The timestamp can for example be an
increasing version number from a database record that is used for optimistic
concurrency control.
node
- (undocumented)key
- (undocumented)value
- (undocumented)clock
- (undocumented)public LWWMap<A> put(java.lang.String key, A value, Cluster node, LWWRegister.Clock<A> clock)
You can provide your clock
implementation instead of using timestamps based
on System.currentTimeMillis()
time. The timestamp can for example be an
increasing version number from a database record that is used for optimistic
concurrency control.
key
- (undocumented)value
- (undocumented)node
- (undocumented)clock
- (undocumented)public LWWMap<A> put(UniqueAddress node, java.lang.String key, A value, LWWRegister.Clock<A> clock)
node
- (undocumented)key
- (undocumented)value
- (undocumented)clock
- (undocumented)public LWWMap<A> remove(Cluster node, java.lang.String key)
node
- (undocumented)key
- (undocumented)public LWWMap<A> remove(UniqueAddress node, java.lang.String key)
node
- (undocumented)key
- (undocumented)public boolean needPruningFrom(UniqueAddress removedNode)
RemovedNodePruning
needPruningFrom
in interface RemovedNodePruning
removedNode
- (undocumented)public LWWMap<A> prune(UniqueAddress removedNode, UniqueAddress collapseInto)
RemovedNodePruning
removed
node has been removed from the cluster the state
changes from that node will be pruned by collapsing the data entries
to another node.prune
in interface RemovedNodePruning
removedNode
- (undocumented)collapseInto
- (undocumented)public LWWMap<A> pruningCleanup(UniqueAddress removedNode)
RemovedNodePruning
pruningCleanup
in interface RemovedNodePruning
removedNode
- (undocumented)public java.lang.String toString()
toString
in class java.lang.Object
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object