Class LocalTableMap
- All Implemented Interfaces:
com.fishlib.base.log.LogOutputAppendable
,NotificationQueue.Dependency
,Deflatable<TableMap>
,LivenessManager
,LivenessNode
,LivenessReferent
,DynamicNode
,SystemicObject
,TableMap
,TransformableTableMap
,Serializable
- Direct Known Subclasses:
FilteredTableMap
,LastByTableImportState.ResultTableMap
public class LocalTableMap extends TableMapImpl implements NotificationQueue.Dependency, SystemicObject
- See Also:
- Serialized Form
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
LocalTableMap.PopulateCallback
The TableMaps don't know how to create empty tables for themselves, if the TableMap needs to be pre-populated, it must pass this callback into the constructor.Nested classes/interfaces inherited from interface com.illumon.iris.db.v2.TableMap
TableMap.KeyListener, TableMap.Listener
Nested classes/interfaces inherited from interface com.illumon.iris.db.v2.TransformableTableMap
TransformableTableMap.AsTableBuilder
-
Field Summary
-
Constructor Summary
Constructors Constructor Description LocalTableMap(LocalTableMap.PopulateCallback populateCallback)
Constructor to create an instance with an empty default map.LocalTableMap(LocalTableMap.PopulateCallback populateCallback, TableDefinition constituentDefinition)
Constructor to create an instance with an empty default map. -
Method Summary
Modifier and Type Method Description <R> R
apply(com.fishlib.base.Function.Unary<R,TableMap> function)
Applies a function to this tableMap.Table
asTable(boolean strictKeys, boolean allowCoalesce, boolean sanityCheckJoins)
Create a Table out of this TableMap's values.Table
computeIfAbsent(Object key, Function<Object,Table> tableFactory)
boolean
containsKey(Object key)
protected void
destroy()
Attempt to release (destructively when necessary) resources held by this object.void
dropReference()
Drop a previously-retained reference to this referent.Collection<Map.Entry<Object,Table>>
entrySet()
Gets the entries.TableMap
flatten()
Flattens all of the result tables within the tablemap.Table
get(Object key)
Gets a table with a given key.LocalTableMap.PopulateCallback
getCallback()
Optional<TableDefinition>
getConstituentDefinition()
TableDefinition
getConstituentDefinitionOrErr()
Object[]
getKeySet()
Gets the keys.int
getTransformationThreads()
Returns the number of transformation threads that will be used (if this TableMap is not configured to use the global thread pool).WeakReference<? extends LivenessReferent>
getWeakReference()
Get aWeakReference
to this referent.Table
getWithTransform(Object key, Function<Table,Table> transform)
Gets a table with a given key, applying the specified transform before returning.void
initializeTransientFieldsForLiveness()
Package-private forSerializable
sub-classes to use inreadObject
only.boolean
isMergeable()
boolean
isSystemicObject()
Returns true if this is a systemically important object (seeSystemicObjectTracker
).void
markSystemic()
Mark this object as systemically important.Table
merge()
Merges all of the component tables into a single Table.protected void
onReferenceCountAtZero()
Callback method that will be invoked when the reference count returns to zero.TableMap
populateKeys(Object... keys)
When creating the table map, some of the keys that we would like to be there eventually may not exist.TableMap
preemptiveUpdatesTable(int intervalMillis)
Creates preemptive tables out of all of the result tables within the tablemap.Table
put(Object key, Table table)
Add a table to the map with the given key.void
removeKeys(Object... keys)
boolean
satisfied(long step)
Is this ancestor satisfied? Note that this method must be safe to call on any thread.void
setDependency(NotificationQueue.Dependency dependency)
void
setTransformationThreads(int transformationThreads)
Set the number of transformation threads that should be used.void
setUseGlobalTransformationThreadPool(boolean useGlobalTransformationThreadPool)
Sets whether this LocalTableMap is configured to use the global transformation thread pool.int
size()
Number of tables in the map.String
toString()
TableMap
transformTables(NotificationQueue.Dependency dependency, BiFunction<Object,Table,Table> function)
TableMap
transformTablesWithKey(NotificationQueue.Dependency dependency, TableDefinition returnDefinition, BiFunction<Object,Table,Table> function)
TableMap
transformTablesWithKey(TableDefinition returnDefinition, BiFunction<Object,Table,Table> function)
Applies a transformation function on all tables in the TableMap, producing a new TableMap which will update as new keys are added.TableMap
transformTablesWithKey(BiFunction<Object,Table,Table> function)
Applies a transformation function on all tables in the TableMap, producing a new TableMap which will update as new keys are added.TableMap
transformTablesWithMap(TableMap other, BiFunction<Table,Table,Table> function)
Applies a BiFunction function on all tables in this TableMap and otherMap that have matching keys, producing a new TableMap which will update as new keys are added.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.boolean
useGlobalTransformationThreadPool()
Returns whether this LocalTableMap is configured to use the global transformation thread pool.Collection<Table>
values()
Gets the values.Methods inherited from class com.illumon.iris.db.v2.TableMapImpl
addKeyListener, addListener, addParentReference, isRefreshing, notifyKeyListeners, notifyListeners, removeKeyListener, removeListener, setRefreshing
Methods inherited from class com.illumon.iris.db.util.liveness.LivenessArtifact
manageWithCurrentScope, unmanage, unmanage
Methods inherited from class com.illumon.util.referencecounting.ReferenceCounted
append, 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.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 com.illumon.iris.db.v2.TableMap
asTableMap, deflate, transformTables, transformTables
Methods inherited from interface com.illumon.iris.db.v2.TransformableTableMap
asTable, asTableBuilder
-
Constructor Details
-
LocalTableMap
Constructor to create an instance with an empty default map.- Parameters:
populateCallback
- the callback that is invoked whenpopulateKeys(Object...)
is called
-
LocalTableMap
public LocalTableMap(LocalTableMap.PopulateCallback populateCallback, TableDefinition constituentDefinition)Constructor to create an instance with an empty default map.- Parameters:
populateCallback
- the callback that is invoked whenpopulateKeys(Object...)
is calledconstituentDefinition
- the definition of the constituent tables (optional, but by providing it, a TableMap with no constituents can be merged)
-
-
Method Details
-
getCallback
-
isSystemicObject
public boolean isSystemicObject()Description copied from interface:SystemicObject
Returns true if this is a systemically important object (seeSystemicObjectTracker
).- Specified by:
isSystemicObject
in interfaceSystemicObject
- Returns:
- true if this is a systemically important object, false otherwise.
-
markSystemic
public void markSystemic()Description copied from interface:SystemicObject
Mark this object as systemically important.- Specified by:
markSystemic
in interfaceSystemicObject
-
put
Add a table to the map with the given key. Return the previous value, if any.- Parameters:
key
- the key to addtable
- the value to add- Returns:
- the previous table for the given key
-
computeIfAbsent
-
get
Description copied from interface:TableMap
Gets a table with a given key. Note that this causes the currentLivenessManager
(seeLivenessScopeStack
) to manage the result if non-null. -
getWithTransform
Description copied from interface:TableMap
Gets a table with a given key, applying the specified transform before returning.- Specified by:
getWithTransform
in interfaceTableMap
- Parameters:
key
- key- Returns:
- table associated with the key, or null if the key is not present.
-
getKeySet
Description copied from interface:TableMap
Gets the keys. -
values
Description copied from interface:TableMap
Gets the values. -
size
public int size()Description copied from interface:TableMap
Number of tables in the map. -
populateKeys
Description copied from interface:TableMap
When creating the table map, some of the keys that we would like to be there eventually may not exist. This call lets you pre-populate keys, so that at initialization time you can perform the appropriate joins, etc., on empty tables that you expect to be populated in the future.- Specified by:
populateKeys
in interfaceTableMap
- Parameters:
keys
- the keys to add to the map- Returns:
- this TableMap
-
removeKeys
-
containsKey
-
entrySet
Description copied from interface:TableMap
Gets the entries. -
flatten
Description copied from interface:TableMap
Flattens all of the result tables within the tablemap. -
preemptiveUpdatesTable
Description copied from interface:TableMap
Creates preemptive tables out of all of the result tables within the tablemap.- Specified by:
preemptiveUpdatesTable
in interfaceTableMap
- Parameters:
intervalMillis
- update interval for the preemptive tables
-
apply
Description copied from interface:TableMap
Applies a function to this tableMap. This is useful if you have a reference to a tableMap; but not the database and want to run a series of operations against the table map without each individual operation resulting in a remote method invocation. -
transformTables
public TableMap transformTables(NotificationQueue.Dependency dependency, BiFunction<Object,Table,Table> function) -
transformTablesWithKey
Description copied from interface:TableMap
Applies a transformation function on all tables in the TableMap, producing a new TableMap which will update as new keys are added.The function may be passed a sentinel key, which can be checked with
TableMap.isSentinel(Object)
. On the sentinel key, the function will be passed in an empty table, and is expected to return an empty table of the proper definition. To avoid this sentinel invocation, callers can be explicit and useTableMap.transformTablesWithKey(TableDefinition, BiFunction)
.- Specified by:
transformTablesWithKey
in interfaceTableMap
- Parameters:
function
- the bifunction to apply to each table in this TableMap- Returns:
- a new TableMap where each table has had function applied
-
transformTablesWithKey
public TableMap transformTablesWithKey(TableDefinition returnDefinition, BiFunction<Object,Table,Table> function)Description copied from interface:TableMap
Applies a transformation function on all tables in the TableMap, producing a new TableMap which will update as new keys are added.- Specified by:
transformTablesWithKey
in interfaceTableMap
- Parameters:
returnDefinition
- the table definition for the tables the function will returnfunction
- the bifunction to apply to each table in this TableMap- Returns:
- a new TableMap where each table has had function applied
-
transformTablesWithKey
public TableMap transformTablesWithKey(NotificationQueue.Dependency dependency, TableDefinition returnDefinition, BiFunction<Object,Table,Table> function) -
transformTablesWithMap
Description copied from interface:TableMap
Applies a BiFunction function on all tables in this TableMap and otherMap that have matching keys, producing a new TableMap which will update as new keys are added. Only applies the function to tables which exist in both maps.- Specified by:
transformTablesWithMap
in interfaceTableMap
- Parameters:
other
- the other TableMapfunction
- the function to apply to each table in this TableMap, the tables in this map are the first argument the tables in the other map are the second argument.- Returns:
- a new TableMap where each table has had function applied
-
asTable
Description copied from interface:TransformableTableMap
Create a Table out of this TableMap's values.Creates a proxy object that in many respects acts like a Table, you can perform many of the table operations on it, which are then applied using
TableMap.transformTables(java.util.function.Function)
orTableMap.transformTablesWithMap(TableMap, BiFunction)
if the right hand side of an operation is another TableMap.The returned table acts as if it were an uncoalesced table; when two of our Proxy objects are operated on together, e.g., by a
Table.join(com.illumon.iris.db.tables.Table)
) operation, then tables with identical keys are used. If strictKeys is set, an error occurs if the two TableMaps do not have identical keySets.Supported operations include those which return a
Table
,LongSizedDataStructure.size()
,Table.getDefinition()
and operations to retrieve attributes. Operations which retrieve data (such asTable.getIndex()
} orTable.getColumn(int)
require a coalesce operation. If allowCoalesce is not set to true, then the coalescing operations will fail with anIllegalArgumentException
.- Specified by:
asTable
in interfaceTransformableTableMap
- Parameters:
strictKeys
- if we should fail when our RHS TableMap does not have the same keySetallowCoalesce
- if we should allow this TableMap to be automatically coalesced into a tablesanityCheckJoins
- if we should sanity check join keys, meaning that we should refuse to perform any joins if the join keys would span two segments of the TableMap. This option is safer, but requires additional work on the query engine to perform the safety checks.- Returns:
- a Table object that performs operations by segment
-
isMergeable
public boolean isMergeable() -
getConstituentDefinition
-
getConstituentDefinitionOrErr
-
merge
Description copied from interface:TransformableTableMap
Merges all of the component tables into a single Table.- Specified by:
merge
in interfaceTransformableTableMap
- Returns:
- all of our component tables merged into a single Table.
-
setDependency
-
satisfied
public boolean satisfied(long step)Description copied from interface:NotificationQueue.Dependency
Is this ancestor satisfied? Note that this method must be safe to call on any thread.- Specified by:
satisfied
in 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)
-
toString
- Overrides:
toString
in classReferenceCounted
-
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.
- Overrides:
destroy
in classTableMapImpl
-
useGlobalTransformationThreadPool
public boolean useGlobalTransformationThreadPool()Returns whether this LocalTableMap is configured to use the global transformation thread pool. Derived TableMaps will inherit this setting (but use their own thread pool).- Returns:
- true if transformTables and transformTablesWithMap will use the global thread pool; false if they will use a private thread pool
-
setUseGlobalTransformationThreadPool
public void setUseGlobalTransformationThreadPool(boolean useGlobalTransformationThreadPool)Sets whether this LocalTableMap is configured to use the global transformation thread pool. When set to true, the global thread pool configured inTableMapTransformThreadPool
is used. When set to false, a thread pool for this particular TableMap is used (or no thread pool if transformation threads is set to 1). -
getTransformationThreads
public int getTransformationThreads()Returns the number of transformation threads that will be used (if this TableMap is not configured to use the global thread pool). If this TableMap is configured to use the global thread pool, then this value is ignored.- Returns:
- the number of threads that will be used for transformations
-
setTransformationThreads
public void setTransformationThreads(int transformationThreads)Set the number of transformation threads that should be used. Additionally, the global transformation thread pool is disabled for this TableMap. Derived TableMaps will inherit this setting (but use their own thread pool).- Parameters:
transformationThreads
- the number of threads that should be used for transformations
-
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
-