Class OortMap<K,V>
- Type Parameters:
K- the key typeV- the value type
- All Implemented Interfaces:
Iterable<OortObject.Info<ConcurrentMap<K,,V>>> EventListener,org.cometd.bayeux.server.ConfigurableServerChannel.Initializer,Oort.CometListener,org.eclipse.jetty.util.component.Dumpable,org.eclipse.jetty.util.component.LifeCycle
- Direct Known Subclasses:
OortLongMap,OortStringMap
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.EntryListeners are notified.
OortMap.DeltaListener converts whole map updates triggered by OortObject.setAndShare(Object, Result)
into events for OortMap.EntryListeners, 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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classAn implementation ofOortObject.Listenerthat converts whole map events intoOortMap.EntryListenerevents.static classA triple that holds the key, the previous value and the new value, used to notify entry updates:static interfaceListener for entry events that update the entity map, either locally or remotely.Nested classes/interfaces inherited from class org.cometd.oort.OortObject
OortObject.Data<T>, OortObject.Factory<T>, OortObject.Info<T>, OortObject.Listener<T>, OortObject.Merger<T,R>, OortObject.Result<R> Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
org.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListener, org.eclipse.jetty.util.component.AbstractLifeCycle.StopExceptionNested classes/interfaces inherited from interface org.cometd.bayeux.server.ConfigurableServerChannel.Initializer
org.cometd.bayeux.server.ConfigurableServerChannel.Initializer.PersistentNested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Dumpable
org.eclipse.jetty.util.component.Dumpable.DumpableContainerNested classes/interfaces inherited from interface org.cometd.oort.Oort.CometListener
Oort.CometListener.Event -
Field Summary
Fields inherited from class org.cometd.oort.OortObject
OORT_OBJECTS_CHANNELFields inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
FAILED, STARTED, STARTING, STOPPED, STOPPINGFields inherited from interface org.eclipse.jetty.util.component.Dumpable
KEY -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedOortMap(Oort oort, String name, OortObject.Factory<ConcurrentMap<K, V>> factory) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddEntryListener(OortMap.EntryListener<K, V> listener) Returns the first non-null value mapped to the given key from the entity maps of all nodes.Returns the value mapped to the given key from the local entity map of this node.protected booleanisItemUpdate(Map<String, Object> data) protected voidonItem(OortObject.Info<ConcurrentMap<K, V>> info, Map<String, Object> data) voidputAndShare(K key, V value, OortObject.Result<V> callback) Updates a single entry of the local entity map with the givenkeyandvalue, and broadcasts the operation to all nodes in the cluster.voidputIfAbsentAndShare(K key, V value, OortObject.Result<V> callback) Updates a single entry of the local entity map with the givenkeyandvalueif it does not exist yet, and broadcasts the operation to all nodes in the cluster.voidremoveAndShare(K key, OortObject.Result<V> callback) Removes the givenkeyfrom the local entity map, and broadcasts the operation to all nodes in the cluster.voidremoveEntryListener(OortMap.EntryListener<K, V> listener) voidMethods inherited from class org.cometd.oort.OortContainer
cometLeft, doStop, onObjectMethods inherited from class org.cometd.oort.OortObject
addListener, cometJoined, configureChannel, deserialize, doStart, dump, getChannelName, getFactory, getInfo, getInfoByObject, getInfos, getLocalSession, getName, getOort, iterator, merge, newInfo, notifyRemoved, notifyUpdated, pullInfo, pushInfo, removeListener, removeListeners, serialize, setAndShare, toStringMethods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
addEventListener, getEventListeners, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeEventListener, setEventListeners, start, stopMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.eclipse.jetty.util.component.Dumpable
dump, dumpSelfMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
OortMap
-
-
Method Details
-
addEntryListener
-
removeEntryListener
-
removeEntryListeners
public void removeEntryListeners() -
get
Returns the value mapped to the given key from the local entity map of this node. Differently fromfind(Object), only the local entity map is scanned.- Parameters:
key- the key mapped to the value to return- Returns:
- the value mapped to the given key, or
nullif the local map does not contain the given key - See Also:
-
find
Returns the first non-null value mapped to the given key from the entity maps of all nodes. Differently fromget(Object), entity maps of all nodes are scanned.- Parameters:
key- the key mapped to the value to return- Returns:
- the value mapped to the given key, or
nullif the maps do not contain the given key - See Also:
-
findInfo
- Parameters:
key- the key to search- Returns:
- the first
OortObject.Infowhose entity map contains the given key.
-
isItemUpdate
- Specified by:
isItemUpdatein classOortContainer<ConcurrentMap<K,V>>
-
onItem
- Specified by:
onItemin classOortContainer<ConcurrentMap<K,V>>
-