K
- the key typeV
- the value typejava.util.EventListener
, Oort.CometListener
OortLongMap
, OortStringMap
public abstract class OortMap<K,V> extends OortContainer<java.util.concurrent.ConcurrentMap<K,V>>
A specialized oort object whose entity is a ConcurrentMap
.
OortMap
specializes OortObject
and allows optimized replication of map entries
across the cluster: instead of replicating the whole map, that may be contain a lot of entries,
only entries that are modified are replicated.
Applications can use putAndShare(Object, Object, Result)
and removeAndShare(Object, Result)
to broadcast changes related to single entries, as well as OortObject.setAndShare(Object, Result)
to
change the whole map.
When a single entry is changed, OortMap.EntryListener
s are notified.
OortMap.DeltaListener
converts whole map updates triggered by OortObject.setAndShare(Object, Result)
into events for OortMap.EntryListener
s, giving applications a single listener type to implement
their business logic.
The type parameter for keys, K
, must be a String to be able to use this class as-is,
although usage of OortStringMap
is preferred.
This is due to the fact that a Map<Long,Object>
containing an entry {13:"foo"}
is serialized in JSON as {"13":"foo"}
because JSON field names must always be strings.
When deserialized, it is restored as a Map<String,Object>
, which is incompatible
with the original type parameter for keys.
To overcome this issue, subclasses may override OortObject.serialize(Object)
and
OortObject.deserialize(Object)
.
Method OortObject.serialize(Object)
should convert the entity object to a format that retains
enough type information for OortObject.deserialize(Object)
to convert the JSON-deserialized entity
object that has the wrong key type to an entity object that has the right key type, like
OortLongMap
does.
Modifier and Type | Class | Description |
---|---|---|
static class |
OortMap.DeltaListener<K,V> |
An implementation of
OortObject.Listener that converts whole map events into OortMap.EntryListener events. |
static class |
OortMap.Entry<K,V> |
A triple that holds the key, the previous value and the new value, used to notify entry updates:
|
static interface |
OortMap.EntryListener<K,V> |
Listener for entry events that update the entity map, either locally or remotely.
|
org.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListener
org.cometd.bayeux.server.ConfigurableServerChannel.Initializer.Persistent
Oort.CometListener.Adapter, Oort.CometListener.Event
OortObject.Data<T>, OortObject.Factory<T>, OortObject.Info<T>, OortObject.Listener<T>, OortObject.Merger<T,R>, OortObject.Result<R>
FAILED, RUNNING, STARTED, STARTING, STOP_ON_FAILURE, STOPPED, STOPPING
logger, OORT_OBJECTS_CHANNEL
Modifier | Constructor | Description |
---|---|---|
protected |
OortMap(Oort oort,
java.lang.String name,
OortObject.Factory<java.util.concurrent.ConcurrentMap<K,V>> factory) |
Modifier and Type | Method | Description |
---|---|---|
void |
addEntryListener(OortMap.EntryListener<K,V> listener) |
|
V |
find(K key) |
Returns the first non-null value mapped to the given key from the entity maps of all nodes.
|
OortObject.Info<java.util.concurrent.ConcurrentMap<K,V>> |
findInfo(K key) |
|
V |
get(K key) |
Returns the value mapped to the given key from the local entity map of this node.
|
protected boolean |
isItemUpdate(java.util.Map<java.lang.String,java.lang.Object> data) |
|
protected void |
onItem(OortObject.Info<java.util.concurrent.ConcurrentMap<K,V>> info,
java.util.Map<java.lang.String,java.lang.Object> data) |
|
V |
putAndShare(K key,
V value) |
Deprecated.
use
putAndShare(Object, Object, Result) instead |
void |
putAndShare(K key,
V value,
OortObject.Result<V> callback) |
Updates a single entry of the local entity map with the given
key and value ,
and broadcasts the operation to all nodes in the cluster. |
V |
putIfAbsentAndShare(K key,
V value) |
Deprecated.
use
putAndShare(Object, Object, Result) instead |
void |
putIfAbsentAndShare(K key,
V value,
OortObject.Result<V> callback) |
Updates a single entry of the local entity map with the given
key and value
if it does not exist yet, and broadcasts the operation to all nodes in the cluster. |
V |
removeAndShare(K key) |
Deprecated.
use
removeAndShare(Object, Result) instead |
void |
removeAndShare(K key,
OortObject.Result<V> callback) |
Removes the given
key from the local entity map,
and broadcasts the operation to all nodes in the cluster. |
void |
removeEntryListener(OortMap.EntryListener<K,V> listener) |
|
void |
removeEntryListeners() |
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, setStopTimeout, start, stop
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
cometLeft, doStop, onObject
addListener, cometJoined, configureChannel, deserialize, doStart, getChannelName, getFactory, getInfo, getInfoByObject, getInfos, getLocalSession, getName, getOort, iterator, merge, newInfo, notifyRemoved, notifyUpdated, pullInfo, pushInfo, removeListener, removeListeners, serialize, setAndShare, setAndShare, toString
protected OortMap(Oort oort, java.lang.String name, OortObject.Factory<java.util.concurrent.ConcurrentMap<K,V>> factory)
public void addEntryListener(OortMap.EntryListener<K,V> listener)
public void removeEntryListener(OortMap.EntryListener<K,V> listener)
public void removeEntryListeners()
@Deprecated public V putAndShare(K key, V value)
putAndShare(Object, Object, Result)
insteadBlocking version of putAndShare(Object, Object, Result)
, but deprecated.
This method will be removed in a future release.
key
- the key to associate the value tovalue
- the value associated with the keypublic void putAndShare(K key, V value, OortObject.Result<V> callback)
Updates a single entry of the local entity map with the given key
and value
,
and broadcasts the operation to all nodes in the cluster.
Calling this method triggers notifications OortMap.EntryListener
s, both on this node and on remote nodes.
The entry is guaranteed to be put not when this method returns,
but when the OortObject.Result
parameter is notified.
key
- the key to associate the value tovalue
- the value associated with the keycallback
- the callback invoked with the old value,
or null
if there is no interest in the old valueputIfAbsentAndShare(Object, Object, Result)
,
removeAndShare(Object, Result)
@Deprecated public V putIfAbsentAndShare(K key, V value)
putAndShare(Object, Object, Result)
insteadBlocking version of putIfAbsentAndShare(Object, Object, Result)
, but deprecated.
This method will be removed in a future release.
key
- the key to associate the value tovalue
- the value associated with the keypublic void putIfAbsentAndShare(K key, V value, OortObject.Result<V> callback)
Updates a single entry of the local entity map with the given key
and value
if it does not exist yet, and broadcasts the operation to all nodes in the cluster.
Calling this method triggers notifications OortMap.EntryListener
s, both on this node and on remote nodes,
only if the key did not exist.
The entry is guaranteed to be put not when this method returns,
but when the OortObject.Result
parameter is notified.
key
- the key to associate the value tovalue
- the value associated with the keycallback
- the callback invoked with the old value,
or null
if there is no interest in the old valueputAndShare(Object, Object, Result)
@Deprecated public V removeAndShare(K key)
removeAndShare(Object, Result)
insteadBlocking version of removeAndShare(Object, Result)
, but deprecated.
This method will be removed in a future release.
key
- the key to removepublic void removeAndShare(K key, OortObject.Result<V> callback)
Removes the given key
from the local entity map,
and broadcasts the operation to all nodes in the cluster.
Calling this method triggers notifications OortMap.EntryListener
s, both on this node and on remote nodes.
The entry is guaranteed to be removed not when this method returns,
but when the OortObject.Result
parameter is notified.
key
- the key to removecallback
- the callback invoked with the value,
or null
if there is no interest in the valueputAndShare(Object, Object, Result)
public V get(K key)
find(Object)
, only the local entity map is scanned.key
- the key mapped to the value to returnnull
if the local map does not contain the given keyfind(Object)
public V find(K key)
get(Object)
, entity maps of all nodes are scanned.key
- the key mapped to the value to returnnull
if the maps do not contain the given keypublic OortObject.Info<java.util.concurrent.ConcurrentMap<K,V>> findInfo(K key)
key
- the key to searchOortObject.Info
whose entity map contains the given key.protected boolean isItemUpdate(java.util.Map<java.lang.String,java.lang.Object> data)
isItemUpdate
in class OortContainer<java.util.concurrent.ConcurrentMap<K,V>>
protected void onItem(OortObject.Info<java.util.concurrent.ConcurrentMap<K,V>> info, java.util.Map<java.lang.String,java.lang.Object> data)
onItem
in class OortContainer<java.util.concurrent.ConcurrentMap<K,V>>
Copyright © 2008–2017 The CometD Project. All rights reserved.