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.Notification
Nested classes/interfaces inherited from class com.illumon.iris.db.v2.InstrumentedListenerBase
InstrumentedListenerBase.ErrorNotification, InstrumentedListenerBase.NotificationBase
Nested 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 void
clear()
boolean
containsKey(Object key)
boolean
containsValue(Object value)
void
dropReference()
Drop a previously-retained reference to this referent.Set<Map.Entry<K,V>>
entrySet()
V
get(Object key)
<T> T
get(K key, ColumnSource<T> cs)
<T> T
get(K key, groovy.lang.Closure<T> valueProducer, groovy.lang.Closure<T> prevValueProducer)
<T> T
get(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 aWeakReference
to this referent.void
initializeTransientFieldsForLiveness()
Package-private forSerializable
sub-classes to use inreadObject
only.boolean
isEmpty()
Set<K>
keySet()
static <K1, V1> ToMapListener<K1,V1>
make(DynamicTable source, ColumnSource<K1> keySource, ColumnSource<V1> valueSource)
static ToMapListener
make(DynamicTable source, String keySourceName)
static ToMapListener
make(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 void
onReferenceCountAtZero()
Callback method that will be invoked when the reference count returns to zero.void
onUpdate(ShiftAwareListener.Update upstream)
Process notification of table changes.V
put(K key, V value)
void
putAll(Map<? extends K,? extends V> m)
V
remove(Object key)
int
size()
boolean
tryManage(LivenessReferent referent)
Attempt to add the specified referent to this manager.boolean
tryRetainReference()
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, onFailureInternal
Methods inherited from class com.illumon.iris.db.v2.InstrumentedListenerBase
append, getEntry, getErrorNotification, onFailure, onFailureInternalWithDependent, satisfied, setVerboseLogging, toString
Methods inherited from class com.illumon.iris.db.util.liveness.LivenessArtifact
manageWithCurrentScope, unmanage, unmanage
Methods inherited from class com.illumon.util.referencecounting.ReferenceCounted
decrementReferenceCount, incrementReferenceCount, resetReferenceCount, tryDecrementReferenceCount, tryIncrementReferenceCount
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface com.illumon.iris.db.v2.ListenerBase
getErrorNotification, onFailure
Methods inherited from interface com.illumon.iris.db.util.liveness.LivenessManager
manage, tryManage
Methods inherited from interface com.illumon.iris.db.util.liveness.LivenessReferent
dropReference, getReferentDescription, getWeakReference, retainReference, tryRetainReference
Methods 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:ShiftAwareListener
Process notification of table changes.- Specified by:
onUpdate
in interfaceShiftAwareListener
- Specified by:
onUpdate
in classInstrumentedShiftAwareListenerAdapter
- Parameters:
upstream
- The set of upstream table updates.
-
size
public int size() -
isEmpty
public boolean isEmpty() -
containsKey
- Specified by:
containsKey
in interfaceMap<K,V>
-
containsValue
- Specified by:
containsValue
in 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 forSerializable
sub-classes to use inreadObject
only. 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:LivenessReferent
If this referent is "live", behave asLivenessReferent.retainReference()
and return true. Otherwise, returns false rather than throwing an exception.- Specified by:
tryRetainReference
in interfaceLivenessReferent
- Returns:
- True if this referent was retained, false otherwise
-
dropReference
public final void dropReference()Description copied from interface:LivenessReferent
Drop a previously-retained reference to this referent.- Specified by:
dropReference
in interfaceLivenessReferent
-
getWeakReference
Description copied from interface:LivenessReferent
Get aWeakReference
to this referent. This may be cached, or newly created.- Specified by:
getWeakReference
in interfaceLivenessReferent
- Returns:
- A new or cached reference to this referent
-
tryManage
Description copied from interface:LivenessManager
Attempt to add the specified referent to this manager.- Specified by:
tryManage
in interfaceLivenessManager
- Parameters:
referent
- The referent to add- Returns:
- Whether the referent was in fact added
-
onReferenceCountAtZero
protected final void onReferenceCountAtZero()Description copied from class:ReferenceCounted
Callback method that will be invoked when the reference count returns to zero.- Specified by:
onReferenceCountAtZero
in classReferenceCounted
-