Package com.illumon.iris.db.v2
Class ReverseLookupListener
java.lang.Object
com.illumon.util.referencecounting.ReferenceCounted
com.illumon.iris.db.util.liveness.LivenessArtifact
com.illumon.iris.db.v2.ReverseLookupListener
- All Implemented Interfaces:
com.fishlib.base.log.LogOutputAppendable,NotificationQueue.Dependency,LivenessManager,LivenessNode,LivenessReferent,DynamicNode,NotificationStepSource,ReverseLookup,Serializable
public class ReverseLookupListener extends LivenessArtifact implements ReverseLookup, DynamicNode, NotificationStepSource
Maintains a map from key column values to their index.
This allows you to quickly find a row based on a unique key on a ticking table, without the need for searching the
entire table.
Note: The key column values must be unique.
- See Also:
- Serialized Form
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.illumon.iris.db.v2.ReverseLookup
ReverseLookup.Null -
Field Summary
-
Method Summary
Modifier and Type Method Description voidaddParentReference(Object parent)Called on a dependent node to ensure that a strong reference is maintained to any parent object that is required for the proper maintenance and functioning of the dependent.protected voiddestroy()Attempt to release (destructively when necessary) resources held by this object.voiddropReference()Drop a previously-retained reference to this referent.longget(Object key)Gets the index value where key exists in the table, or the no-entry-value if it is not found in the table.protected ObjectgetKey(long row)Gets the key for a given row.String[]getKeyColumns()longgetLastNotificationStep()Get the last logical clock step on which this element dispatched a notification.longgetNoEntryValue()Returns the value that will be returned fromReverseLookup.get(java.lang.Object)or if no entry exists for a given key.longgetPrev(Object key)Gets the index value where key previously in the table, or the no-entry-value if it is was not found in the table.WeakReference<? extends LivenessReferent>getWeakReference()Get aWeakReferenceto this referent.voidinitializeTransientFieldsForLiveness()Package-private forSerializablesub-classes to use inreadObjectonly.booleanisRefreshing()Is the node updating?static ReverseLookupListenermakeReverseLookupListenerWithLock(DynamicTable source, String... columns)static ReverseLookupListenermakeReverseLookupListenerWithSnapshot(BaseTable source, String... columns)protected voidonReferenceCountAtZero()Callback method that will be invoked when the reference count returns to zero.static voidprepareForTree(BaseTable preTree, String idColumn)Prepare the parameter table for use withtree tablebooleansatisfied(long step)Is this ancestor satisfied? Note that this method must be safe to call on any thread.booleansetRefreshing(boolean refreshing)Change the node's refresh mode.StringtoString()booleantryManage(LivenessReferent referent)Attempt to add the specified referent to this manager.booleantryRetainReference()If this referent is "live", behave asLivenessReferent.retainReference()and return true.Methods inherited from class com.illumon.iris.db.util.liveness.LivenessArtifact
manageWithCurrentScope, unmanage, unmanageMethods inherited from class com.illumon.util.referencecounting.ReferenceCounted
append, 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.util.liveness.LivenessReferent
getReferentDescription, retainReference
-
Method Details
-
makeReverseLookupListenerWithSnapshot
public static ReverseLookupListener makeReverseLookupListenerWithSnapshot(BaseTable source, String... columns) -
makeReverseLookupListenerWithLock
public static ReverseLookupListener makeReverseLookupListenerWithLock(DynamicTable source, String... columns) -
prepareForTree
Prepare the parameter table for use withtree table- Parameters:
preTree- The tree to prepareidColumn- The column that will be used as the id forTable.treeTable(String, String)
-
get
Description copied from interface:ReverseLookupGets the index value where key exists in the table, or the no-entry-value if it is not found in the table.- Specified by:
getin interfaceReverseLookup- Parameters:
key- a single object for a single column, or aSmartKeyfor multiple columns- Returns:
- the row index where key exists in the table
-
getPrev
Description copied from interface:ReverseLookupGets the index value where key previously in the table, or the no-entry-value if it is was not found in the table.- Specified by:
getPrevin interfaceReverseLookup- Parameters:
key- a single object for a single column, or aSmartKeyfor multiple columns- Returns:
- the row index where key previously existed in the table
-
getNoEntryValue
public long getNoEntryValue()Description copied from interface:ReverseLookupReturns the value that will be returned fromReverseLookup.get(java.lang.Object)or if no entry exists for a given key.- Specified by:
getNoEntryValuein interfaceReverseLookup
-
getKey
Gets the key for a given row.- Parameters:
row- the index value to retrieve the key for- Returns:
- an individual object or SmartKey for multi-column keys
-
toString
- Overrides:
toStringin classReferenceCounted
-
getKeyColumns
- Specified by:
getKeyColumnsin interfaceReverseLookup- Returns:
- the key columns this reverse lookup is indexed on
-
getLastNotificationStep
public long getLastNotificationStep()Description copied from interface:NotificationStepSourceGet the last logical clock step on which this element dispatched a notification.- Specified by:
getLastNotificationStepin interfaceNotificationStepSource- Returns:
- The last notification step
-
satisfied
public boolean satisfied(long step)Description copied from interface:NotificationQueue.DependencyIs this ancestor satisfied? Note that this method must be safe to call on any thread.- Specified by:
satisfiedin interfaceNotificationQueue.Dependency- Parameters:
step- The step for which we are testing satisfaction- Returns:
- Whether the dependency is satisfied on
step(and will not fire subsequent notifications)
-
isRefreshing
public boolean isRefreshing()Description copied from interface:DynamicNodeIs the node updating?- Specified by:
isRefreshingin interfaceDynamicNode- Returns:
- true if the node is updating; false otherwise.
-
setRefreshing
public boolean setRefreshing(boolean refreshing)Description copied from interface:DynamicNodeChange the node's refresh mode.- Specified by:
setRefreshingin interfaceDynamicNode- Parameters:
refreshing- true to cause the node to update; false otherwise.- Returns:
- new refreshing state
-
addParentReference
Description copied from interface:DynamicNodeCalled on a dependent node to ensure that a strong reference is maintained to any parent object that is required for the proper maintenance and functioning of the dependent. In the most common case, the parent object is a child listener to a parent node. The parent node only keeps a weak reference to its child listener, but the listener maintains a strong reference to the parent node. In this scenario, the only strong reference to the listener (and thus indirectly to the parent node itself) is the reference kept by the dependent node.- Specified by:
addParentReferencein interfaceDynamicNode- Parameters:
parent- A parent of this node
-
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
-
destroy
protected void destroy()Attempt to release (destructively when necessary) resources held by this object. This may render the object unusable for subsequent operations. Implementations should be sure to call super.destroy().
This is intended to only ever be used as a side effect of decreasing the reference count to 0.
-
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
-