Package com.illumon.iris.db.util
Class ToMapListener<K,V>
- Type Parameters:
K- the key typeV- the value type
- All Implemented Interfaces:
com.fishlib.base.log.LogOutputAppendable,NotificationQueue.Dependency,LivenessManager,LivenessNode,LivenessReferent,ListenerBase,ShiftAwareListener,Serializable,Map<K,V>
public class ToMapListener<K,V> extends InstrumentedShiftAwareListenerAdapter implements Map<K,V>
Listens to a table, mapping keys to values.
When you call get, we return the value as of the start of this clock cycle.
- See Also:
- Serialized Form
-
Nested Class Summary
Nested classes/interfaces inherited from class com.illumon.iris.db.v2.InstrumentedShiftAwareListener
InstrumentedShiftAwareListener.NotificationNested classes/interfaces inherited from class com.illumon.iris.db.v2.InstrumentedListenerBase
InstrumentedListenerBase.ErrorNotification, InstrumentedListenerBase.NotificationBaseNested classes/interfaces inherited from interface java.util.Map
Map.Entry<K extends Object,V extends Object>Nested classes/interfaces inherited from interface com.illumon.iris.db.v2.ShiftAwareListener
ShiftAwareListener.Update -
Field Summary
-
Method Summary
Modifier and Type Method Description voidclear()booleancontainsKey(Object key)booleancontainsValue(Object value)voiddropReference()Drop a previously-retained reference to this referent.Set<Map.Entry<K,V>>entrySet()Vget(Object key)<T> Tget(K key, ColumnSource<T> cs)<T> Tget(K key, groovy.lang.Closure<T> valueProducer, groovy.lang.Closure<T> prevValueProducer)<T> Tget(K key, LongFunction<T> valueProducer, LongFunction<T> prevValueProducer)Get but instead of applying the default value producer, use a custom value producer.WeakReference<? extends LivenessReferent>getWeakReference()Get aWeakReferenceto this referent.voidinitializeTransientFieldsForLiveness()Package-private forSerializablesub-classes to use inreadObjectonly.booleanisEmpty()Set<K>keySet()static <K1, V1> ToMapListener<K1,V1>make(DynamicTable source, ColumnSource<K1> keySource, ColumnSource<V1> valueSource)static ToMapListenermake(DynamicTable source, String keySourceName)static ToMapListenermake(DynamicTable source, String keySourceName, String valueSourceName)static <K1, V1> ToMapListener<K1,V1>make(DynamicTable source, LongFunction<K1> keyProducer, LongFunction<K1> prevKeyProducer, LongFunction<V1> valueProducer, LongFunction<V1> prevValueProducer)protected voidonReferenceCountAtZero()Callback method that will be invoked when the reference count returns to zero.voidonUpdate(ShiftAwareListener.Update upstream)Process notification of table changes.Vput(K key, V value)voidputAll(Map<? extends K,? extends V> m)Vremove(Object key)intsize()booleantryManage(LivenessReferent referent)Attempt to add the specified referent to this manager.booleantryRetainReference()If this referent is "live", behave asLivenessReferent.retainReference()and return true.Collection<V>values()Methods inherited from class com.illumon.iris.db.v2.InstrumentedShiftAwareListenerAdapter
canExecute, destroy, onFailureInternalMethods inherited from class com.illumon.iris.db.v2.InstrumentedListenerBase
append, getEntry, getErrorNotification, onFailure, onFailureInternalWithDependent, satisfied, setVerboseLogging, toStringMethods inherited from class com.illumon.iris.db.util.liveness.LivenessArtifact
manageWithCurrentScope, unmanage, unmanageMethods inherited from class com.illumon.util.referencecounting.ReferenceCounted
decrementReferenceCount, incrementReferenceCount, resetReferenceCount, tryDecrementReferenceCount, tryIncrementReferenceCountMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.illumon.iris.db.v2.ListenerBase
getErrorNotification, onFailureMethods inherited from interface com.illumon.iris.db.util.liveness.LivenessManager
manage, tryManageMethods inherited from interface com.illumon.iris.db.util.liveness.LivenessReferent
dropReference, getReferentDescription, getWeakReference, retainReference, tryRetainReferenceMethods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Method Details
-
make
-
make
public static ToMapListener make(DynamicTable source, String keySourceName, String valueSourceName) -
make
public static <K1, V1> ToMapListener<K1,V1> make(DynamicTable source, ColumnSource<K1> keySource, ColumnSource<V1> valueSource) -
make
public static <K1, V1> ToMapListener<K1,V1> make(DynamicTable source, LongFunction<K1> keyProducer, LongFunction<K1> prevKeyProducer, LongFunction<V1> valueProducer, LongFunction<V1> prevValueProducer) -
onUpdate
Description copied from interface:ShiftAwareListenerProcess notification of table changes.- Specified by:
onUpdatein interfaceShiftAwareListener- Specified by:
onUpdatein classInstrumentedShiftAwareListenerAdapter- Parameters:
upstream- The set of upstream table updates.
-
size
public int size() -
isEmpty
public boolean isEmpty() -
containsKey
- Specified by:
containsKeyin interfaceMap<K,V>
-
containsValue
- Specified by:
containsValuein interfaceMap<K,V>
-
get
-
get
public <T> T get(K key, groovy.lang.Closure<T> valueProducer, groovy.lang.Closure<T> prevValueProducer) -
get
-
get
Get but instead of applying the default value producer, use a custom value producer. The intention is that you can wrap the map up with several different value producers, e.g. one for bid and another for ask.- Type Parameters:
T- the type of the value we are retrieving- Parameters:
key- the key to retrievevalueProducer- retrieve the current value out of the tableprevValueProducer- retrieve the previous value out of the table- Returns:
- the value associated with key
-
put
-
remove
-
putAll
-
clear
public void clear() -
keySet
-
values
-
entrySet
-
initializeTransientFieldsForLiveness
Package-private forSerializablesub-classes to use inreadObjectonly. Public to allow unit tests in another package to work around mock issues where the constructor is never invoked. -
tryRetainReference
public final boolean tryRetainReference()Description copied from interface:LivenessReferentIf this referent is "live", behave asLivenessReferent.retainReference()and return true. Otherwise, returns false rather than throwing an exception.- Specified by:
tryRetainReferencein interfaceLivenessReferent- Returns:
- True if this referent was retained, false otherwise
-
dropReference
public final void dropReference()Description copied from interface:LivenessReferentDrop a previously-retained reference to this referent.- Specified by:
dropReferencein interfaceLivenessReferent
-
getWeakReference
Description copied from interface:LivenessReferentGet aWeakReferenceto this referent. This may be cached, or newly created.- Specified by:
getWeakReferencein interfaceLivenessReferent- Returns:
- A new or cached reference to this referent
-
tryManage
Description copied from interface:LivenessManagerAttempt to add the specified referent to this manager.- Specified by:
tryManagein interfaceLivenessManager- Parameters:
referent- The referent to add- Returns:
- Whether the referent was in fact added
-
onReferenceCountAtZero
protected final void onReferenceCountAtZero()Description copied from class:ReferenceCountedCallback method that will be invoked when the reference count returns to zero.- Specified by:
onReferenceCountAtZeroin classReferenceCounted
-