Class BaseTable

All Implemented Interfaces:
com.fishlib.base.log.LogOutputAppendable, NotificationQueue.Dependency, Deflatable<Table>, Table, LivenessManager, LivenessNode, LivenessReferent, LongSizedDataStructure, DynamicNode, DynamicTable, NotificationStepReceiver, NotificationStepSource, SystemicObject, Serializable
Direct Known Subclasses:
QueryTable, SubscriptionSnapshotTable, UncoalescedTable, WrappedDelegatingTable

public abstract class BaseTable extends LivenessArtifact implements DynamicTable, Serializable, NotificationStepReceiver, NotificationStepSource
Base abstract class all standard table implementations.
See Also:
  • Field Details

    • definition

      protected final TableDefinition definition
      This table's definition.
    • description

      protected final String description
      This table's description.
    • attributes

      protected Map<String,Object> attributes
    • sharedAttributes

      protected volatile boolean sharedAttributes
  • Constructor Details

  • Method Details

    • getDefinition

      public TableDefinition getDefinition()
      Specified by:
      getDefinition in interface Table
    • getDescription

      public String getDescription()
      Specified by:
      getDescription in interface Table
    • toString

      public String toString()
      Overrides:
      toString in class ReferenceCounted
    • append

      public com.fishlib.base.log.LogOutput append(@NotNull com.fishlib.base.log.LogOutput logOutput)
      Specified by:
      append in interface com.fishlib.base.log.LogOutputAppendable
      Overrides:
      append in class ReferenceCounted
    • setAttribute

      public void setAttribute(@NotNull String key, Object object)
      Description copied from interface: Table
      Set the value of an attribute.
      Specified by:
      setAttribute in interface Table
      Parameters:
      key - the name of the attribute
      object - the value
    • getAttribute

      public Object getAttribute(@NotNull String key)
      Description copied from interface: Table
      Get the value of the specified attribute.
      Specified by:
      getAttribute in interface Table
      Parameters:
      key - the name of the attribute
      Returns:
      the value, or null if there was none.
    • getAttributeNames

      @NotNull public Set<String> getAttributeNames()
      Description copied from interface: Table
      Get a set of all the attributes that have values for this table.
      Specified by:
      getAttributeNames in interface Table
      Returns:
      a set of names
    • hasAttribute

      public boolean hasAttribute(@NotNull String name)
      Description copied from interface: Table
      Check if the specified attribute exists in this table.
      Specified by:
      hasAttribute in interface Table
      Parameters:
      name - the name of the attribute
      Returns:
      true if the attribute exists
    • getAttributes

      public Map<String,Object> getAttributes(Collection<String> excludedAttrs)
      Description copied from interface: Table
      Get all attributes from the desired table except the items that appear in excluded.
      Specified by:
      getAttributes in interface Table
      Parameters:
      excludedAttrs - A set of attributes to exclude from the result
      Returns:
      All of the table's attributes except the ones present in excluded
    • shouldCopyAttribute

      protected static boolean shouldCopyAttribute(String attrName, BaseTable.CopyAttributeOperation copyType)
    • copyAttributes

      public void copyAttributes(Table dest, BaseTable.CopyAttributeOperation copyType)
      Copy this table's attributes to the specified table. Attributes will be copied based upon the input BaseTable.CopyAttributeOperation.
      Parameters:
      dest - The table to copy attributes to
      copyType - The operation being performed that requires attributes to be copied.
    • copyAttributes

      public void copyAttributes(Table dest, Predicate<String> shouldCopy)
      Copy this table's attributes to the specified table. Attributes are copied based on a predicate.
      Parameters:
      dest - The table to copy attributes to
      shouldCopy - should we copy this attribute?
    • isAddOnly

      public boolean isAddOnly()
      Returns true if this table is static, or has an attribute asserting that no modifies, shifts, or removals are generated.
      Returns:
      true if this table does not produce modifications, shifts, or removals
    • isAddOnly

      public static boolean isAddOnly(Table table)
      Returns true if this provided table is static, or has an attribute asserting that no modifies, shifts, or removals are generated.
      Returns:
      true if the table does not produce modifications, shifts, or removals
    • addParentReference

      public final void addParentReference(@NotNull Object parent)
      Description copied from interface: DynamicNode
      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. 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:
      addParentReference in interface DynamicNode
      Parameters:
      parent - A parent of this node
    • 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 interface NotificationQueue.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)
    • awaitUpdate

      public void awaitUpdate() throws InterruptedException
      Description copied from interface: DynamicTable

      Wait for updates to this DynamicTable.

      In some implementations, this call may also terminate in case of interrupt or spurious wakeup (see java.util.concurrent.locks.Condition#await()).

      Specified by:
      awaitUpdate in interface DynamicTable
      Throws:
      InterruptedException - In the event this thread is interrupted
    • awaitUpdate

      public boolean awaitUpdate(long timeout) throws InterruptedException
      Description copied from interface: DynamicTable

      Wait for updates to this DynamicTable.

      In some implementations, this call may also terminate in case of interrupt or spurious wakeup (see java.util.concurrent.locks.Condition#await()).

      Specified by:
      awaitUpdate in interface DynamicTable
      Parameters:
      timeout - The maximum time to wait in milliseconds.
      Returns:
      false if the timeout elapses without notification, true otherwise.
      Throws:
      InterruptedException - In the event this thread is interrupted
    • listenForUpdates

      public void listenForUpdates(Listener listener, boolean replayInitialImage)
      Description copied from interface: DynamicTable
      Subscribe for updates to this table. After the optional initial image, listener will be invoked via the LiveTableMonitor notification queue associated with this DynamicTable.
      Specified by:
      listenForUpdates in interface DynamicTable
      Parameters:
      listener - listener for updates
      replayInitialImage - true to process updates for all initial rows in the table plus all new row changes; false to only process new row changes
    • listenForUpdates

      public void listenForUpdates(ShiftAwareListener listener)
      Description copied from interface: DynamicTable
      Subscribe for updates to this table. Listener will be invoked via the LiveTableMonitor notification queue associated with this DynamicTable.
      Specified by:
      listenForUpdates in interface DynamicTable
      Parameters:
      listener - listener for updates
    • listenForDirectUpdates

      public void listenForDirectUpdates(Listener listener)
      Description copied from interface: DynamicTable
      Subscribe for updates to this table. Direct listeners are invoked immediately when changes are published, rather than via a LiveTableMonitor notification queue.
      Specified by:
      listenForDirectUpdates in interface DynamicTable
      Parameters:
      listener - listener for updates
    • removeUpdateListener

      public void removeUpdateListener(Listener listenerToRemove)
      Description copied from interface: DynamicTable
      Unsubscribe the supplied listener.
      Specified by:
      removeUpdateListener in interface DynamicTable
      Parameters:
      listenerToRemove - listener for updates
    • removeUpdateListener

      public void removeUpdateListener(ShiftAwareListener listenerToRemove)
      Description copied from interface: DynamicTable
      Unsubscribe the supplied listener.
      Specified by:
      removeUpdateListener in interface DynamicTable
      Parameters:
      listenerToRemove - listener for updates
    • removeDirectUpdateListener

      public void removeDirectUpdateListener(Listener listenerToRemove)
      Description copied from interface: DynamicTable
      Unsubscribe the supplied listener.
      Specified by:
      removeDirectUpdateListener in interface DynamicTable
      Parameters:
      listenerToRemove - listener for updates
    • notifyListenersOnError

      public final void notifyListenersOnError(Throwable e, @Nullable UpdatePerformanceTracker.Entry sourceEntry)
      Description copied from interface: DynamicTable
      Initiate failure delivery to this table's listeners. Will notify direct listeners before completing, and enqueue notifications for all other listeners.
      Specified by:
      notifyListenersOnError in interface DynamicTable
      Parameters:
      e - error
      sourceEntry - performance tracking
    • isRefreshing

      public final boolean isRefreshing()
      Description copied from interface: DynamicNode
      Is the node updating?
      Specified by:
      isRefreshing in interface DynamicNode
      Returns:
      true if the node is updating; false otherwise.
    • setRefreshing

      public final boolean setRefreshing(boolean refreshing)
      Description copied from interface: DynamicNode
      Change the node's refresh mode.
      Specified by:
      setRefreshing in interface DynamicNode
      Parameters:
      refreshing - true to cause the node to update; false otherwise.
      Returns:
      new refreshing state
    • isFailed

      public boolean isFailed()
      Specified by:
      isFailed in interface DynamicTable
      Returns:
      true if this table is in a failure state.
    • notifyListeners

      public final void notifyListeners(ShiftAwareListener.Update update)
      Description copied from interface: DynamicTable
      Initiate update delivery to this table's listeners. Will notify direct listeners before completing, and enqueue notifications for all other listeners.
      Specified by:
      notifyListeners in interface DynamicTable
      Parameters:
      update - the set of table changes to propagate The caller gives this update object away; the invocation of notifyListeners takes ownership, and will call release on it once it is not used anymore; callers should pass a clone for updates they intend to further use.
    • getNotificationQueue

      protected NotificationQueue getNotificationQueue()
      Get the notification queue to insert notifications into as they are generated by listeners during DynamicTable.notifyListeners(Index, Index, Index). This method may be overridden to provide a different notification queue than the LiveTableMonitor.DEFAULT instance for more complex behavior.
      Returns:
      The NotificationQueue to add to.
    • getLastNotificationStep

      public long getLastNotificationStep()
      Description copied from interface: NotificationStepSource
      Get the last logical clock step on which this element dispatched a notification.
      Specified by:
      getLastNotificationStep in interface NotificationStepSource
      Returns:
      The last notification step
    • setLastNotificationStep

      public void setLastNotificationStep(long lastNotificationStep)
      Description copied from interface: NotificationStepReceiver
      Deliver a last notification step to this receiver.
      Specified by:
      setLastNotificationStep in interface NotificationStepReceiver
      Parameters:
      lastNotificationStep - The last notification step to be delivered
    • isSystemicObject

      public boolean isSystemicObject()
      Description copied from interface: SystemicObject
      Returns true if this is a systemically important object (see SystemicObjectTracker).
      Specified by:
      isSystemicObject in interface SystemicObject
      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 interface SystemicObject
    • withKeys

      public Table withKeys(String... columns)
      Description copied from interface: Table
      Set the table's key columns.
      Specified by:
      withKeys in interface Table
      Returns:
      The same table this method was invoked on, with the keyColumns attribute set
    • withUniqueKeys

      public Table withUniqueKeys(String... columns)
      Description copied from interface: Table
      Set the table's key columns and indicate that each key set will be unique.
      Specified by:
      withUniqueKeys in interface Table
      Returns:
      The same table this method was invoked on, with the keyColumns and unique attributes set
    • restrictSortTo

      public Table restrictSortTo(String... allowedSortingColumns)
      Description copied from interface: Table

      Disallow sorting on all but the specified columns.

      Specified by:
      restrictSortTo in interface Table
      Parameters:
      allowedSortingColumns - The columns on which sorting is allowed.
      Returns:
      The same table this was invoked on.
    • clearSortingRestrictions

      public Table clearSortingRestrictions()
      Description copied from interface: Table

      Clear all sorting restrictions that was applied to the current table.

      Note that this table operates on the table it was invoked on and does not create a new table. So in the following code T1 = baseTable.where(...) T2 = T1.restrictSortTo("C1") T3 = T2.clearSortingRestrictions() T1 == T2 == T3 and the result has no restrictions on sorting.

      Specified by:
      clearSortingRestrictions in interface Table
      Returns:
      The same table this was invoked on.
    • layoutHints

      public Table layoutHints(String hints)
      Specified by:
      layoutHints in interface Table
    • copy

      public Table copy()
      Copies this table, but with a new set of attributes.
      Returns:
      an identical table; but with a new set of attributes
    • setTotalsTable

      public Table setTotalsTable(TotalsTableBuilder builder)
      Description copied from interface: Table
      Sets parameters for the default totals table display.
      Specified by:
      setTotalsTable in interface Table
      Parameters:
      builder - a TotalsTableBuilder object
      Returns:
      a table with the totals applied
    • setColumnRenderers

      public Table setColumnRenderers(ColumnRenderersBuilder builder)
      Description copied from interface: Table
      Sets renderers for columns.
      Specified by:
      setColumnRenderers in interface Table
      Parameters:
      builder - a builder that creates the packed string for the attribute
      Returns:
      The same table with the ColumnRenderes attribute set
    • initializeWithSnapshot

      public <SL extends SwapListenerBase> void initializeWithSnapshot(String logPrefix, SL swapListener, ConstructSnapshot.SnapshotFunction snapshotFunction)
    • createSwapListenerIfRefreshing

      @Nullable public <T extends SwapListenerBase> T createSwapListenerIfRefreshing(BaseTable.SwapListenerFactory<T> factory)
      If we are a refreshing table, then we should create a swap listener and listen for updates. Otherwise, we return null.
      Returns:
      a swap listener for this table (or null)
    • destroy

      protected void destroy()
      Description copied from class: ReferenceCountedLivenessNode

      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 class ReferenceCountedLivenessNode
    • withTableDescription

      public Table withTableDescription(String description)
      Specified by:
      withTableDescription in interface Table
    • withColumnDescription

      public Table withColumnDescription(Map<String,String> descriptions)
      Description copied from interface: Table
      Add a set of column descriptions to the table.
      Specified by:
      withColumnDescription in interface Table
      Parameters:
      descriptions - a map of Column name to Column description.
      Returns:
      a copy of the table with the descriptions applied.