K
- key type of the maps, trackable by this event listenerV
- value type of the maps, trackable by this event listenerpublic abstract class MapEventListener<K,V> extends Object implements Serializable
ChronicleMap
key events occur. Typical use cases:
This is an adapter class - all methods have default implementations as no-ops. Extend this class and override only methods corresponding the events you are interested in.
To configure MapEventListener
for ChronicleMap
, use ChronicleMapBuilder.eventListener(MapEventListener)
method.
See logging(String)
implementation.
All these calls are synchronous while a ChronicleMap
lock is held so make them as
quick as possible.
The entry
passed to the methods is Bytes
instance positioned at meta data
area. See ChronicleHashBuilder.metaDataBytes(int)
for more information.
Constructor and Description |
---|
MapEventListener() |
Modifier and Type | Method and Description |
---|---|
static <K,V> MapEventListener<K,V> |
logging(String prefix)
Returns the map event listener, which logs strings like "map
file opType key value", where opType is either "get", "put" or "remove", to the logger
provided by SLF4J.
|
void |
onGetFound(K key,
V foundValue)
This method is called if the key is found in the map during
get ,
getUsing or acquireUsing
method call. |
void |
onPut(K key,
V newValue,
V replacedValue,
boolean replicationEvent)
This method is called whenever a new value is put for the key in the map during calls of such
methods as
put , putIfAbsent , replace , etc. |
void |
onRemove(K key,
V value,
boolean replicationEvent)
This is called when an entry is removed.
|
public static <K,V> MapEventListener<K,V> logging(String prefix)
K
- the map key typeV
- the map value typeprefix
- logging prefixpublic void onGetFound(K key, V foundValue)
get
,
getUsing
or acquireUsing
method call.key
- the key looked upfoundValue
- the value found for the keypublic void onPut(K key, V newValue, @Nullable V replacedValue, boolean replicationEvent)
put
, putIfAbsent
, replace
, etc. When a new value is default for the map or obtained during
acquireUsing
call is put for the key, this method is called
as well.
This method is called when put is already happened.
key
- the key the given value is put fornewValue
- the value which is now associated with the given keyreplacedValue
- the value which was replaced by newValue
, null
if the
key was absent in the map before current ChronicleMap
replicationEvent
- public void onRemove(K key, V value, boolean replicationEvent)
map.remove(key)
is
called, but key is already absent in the map, are not notified.key
- the key removed from the mapvalue
- the value which was associated with the given keyreplicationEvent
- Copyright © 2015. All rights reserved.