Class PreemptiveUpdatesTable

All Implemented Interfaces:
com.fishlib.base.log.LogOutputAppendable, NotificationQueue.Dependency, Deflatable<Table>, Table, LivenessManager, LivenessNode, LivenessReferent, LongSizedDataStructure, DynamicNode, DynamicTable, NotificationStepReceiver, NotificationStepSource, SubscribableTable, SystemicObject, Serializable

public class PreemptiveUpdatesTable
extends WrappedDelegatingTable
implements SubscribableTable
The server side representation of a preemptive updates table, which wraps an original table. When a client subscribes initially, a snapshot of the table is sent. The snapshot is obtained using either get() or getPrev() based on the state of the LogicalClock. On each subsequent update, the client is given the deltas between the last update propagation and the next. On the client side, this table will be represented by a ReplicatedTable.
See Also:
Serialized Form
  • Method Details

    • 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 class BaseTable
    • logPremptiveUpdateTableStatistics

      public static void logPremptiveUpdateTableStatistics​(com.fishlib.io.logger.Logger log)
      Log the count of created, destroyed, and subscribed PreemptiveUpdatesTables in this worker.
    • markSystemic

      public void markSystemic()
      Description copied from interface: SystemicObject
      Mark this object as systemically important.
      Specified by:
      markSystemic in interface SystemicObject
      Overrides:
      markSystemic in class BaseTable
    • addSubscription

      public boolean addSubscription​(com.fishlib.net.api.CommandSender client, int handleId, BitSet columnsToSubscribe, boolean isViewport)
      Description copied from interface: SubscribableTable
      Add a subscription to this table.
      Specified by:
      addSubscription in interface SubscribableTable
      Parameters:
      client - the client requesting the subscription, used to uniquely identify he handleId and send deltas, snapshots and responses
      handleId - the ID of our subscription
      columnsToSubscribe - the bitset of columns to subscribe to
      isViewport - true if the subscription is a viewport, false if it is a full subscription
      Returns:
      true if the subscription was added
    • updateSubscription

      public boolean updateSubscription​(com.fishlib.net.api.CommandSender client, int subscriptionId, BitSet newSubscribedColumns)
      Description copied from interface: SubscribableTable
      Update the subscription's columns.
      Specified by:
      updateSubscription in interface SubscribableTable
      Parameters:
      client - the client requesting the subscription, used to send deltas, snapshots and responses
      subscriptionId - the ID of our subscription
      newSubscribedColumns - the bitset of columns to subscribe to
      Returns:
      true if the subscription was found and updated
    • updateViewport

      public boolean updateViewport​(com.fishlib.net.api.CommandSender client, int subscriptionId, Index newViewPort)
      Description copied from interface: SubscribableTable
      Update the subscription's viewport (rows).
      Specified by:
      updateViewport in interface SubscribableTable
      Parameters:
      client - the client requesting the subscription, used to send deltas, snapshots and responses
      subscriptionId - the ID of our subscription
      newViewPort - the index representing which rows to subscribe to (in position space)
      Returns:
      true if the subscription was found and updated
    • updateViewportAndColumns

      public boolean updateViewportAndColumns​(com.fishlib.net.api.CommandSender client, int subscriptionId, Index newViewPort, BitSet columnsToSubscribe)
      Description copied from interface: SubscribableTable
      Update the subscription's columns and viewport (rows).
      Specified by:
      updateViewportAndColumns in interface SubscribableTable
      Parameters:
      client - the client requesting the subscription, used to send deltas, snapshots and responses
      subscriptionId - the ID of our subscription
      newViewPort - the index representing which rows to subscribe to (in position space)
      columnsToSubscribe - the bitset of columns to subscribe to
      Returns:
      true if the subscription was found and updated
    • removeSubscription

      public boolean removeSubscription​(com.fishlib.net.api.CommandSender client, int subscriptionId)
      Description copied from interface: SubscribableTable
      Remove a subscription.
      Specified by:
      removeSubscription in interface SubscribableTable
      Parameters:
      client - the client requesting the subscription, used to send responses
      subscriptionId - the ID of our subscription
      Returns:
      true if the subscription was found and updated
    • copyPartialColumns

      public static void copyPartialColumns​(Index sourceIndex, Index destIndex, Object[] sourceDataColumns, Object[] destDataColumns)
    • 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
      Overrides:
      setLastNotificationStep in class BaseTable
      Parameters:
      lastNotificationStep - The last notification step to be delivered
    • 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
      Overrides:
      setAttribute in class BaseTable
      Parameters:
      key - the name of the attribute
      object - the value
    • getIndex

      public Index getIndex()
      Specified by:
      getIndex in interface Table
    • size

      public long size()
      Description copied from interface: LongSizedDataStructure
      The size of this data structure.
      Specified by:
      size in interface LongSizedDataStructure
      Returns:
      The size
    • isFlat

      public boolean isFlat()
      Description copied from interface: Table
      Return true if this table is guaranteed to be flat. The index of a flat table will be from 0...numRows-1.
      Specified by:
      isFlat in interface Table
    • isSnapshot

      public boolean isSnapshot()
      Description copied from interface: SubscribableTable
      True if this table is a snapshot table (as opposed to a preemptive updates table); used by RemoteQueryProcessor to set the isSnapshot flag on ExportedTableCreationMessage messages, so that a client knows if it has an appropriate type of table for its viewport.
      Specified by:
      isSnapshot in interface SubscribableTable
      Returns:
      true if this is a subscription snapshot table.
    • sizeForInstrumentation

      public long sizeForInstrumentation()
      Specified by:
      sizeForInstrumentation in interface Table
    • preemptiveSnapshotTable

      public Table preemptiveSnapshotTable​(long updateInterval)
      Specified by:
      preemptiveSnapshotTable in interface Table
      Overrides:
      preemptiveSnapshotTable in class WrappedDelegatingTable
    • rollup

      public HierarchicalTable rollup​(ComboAggregateFactory comboAggregateFactory, boolean includeConstituents, SelectColumn... columns)
      Specified by:
      rollup in interface Table
      Overrides:
      rollup in class WrappedDelegatingTable
      ImplNote:
      The Preemptive version of this method will return a non-preemptive table
    • treeTable

      public HierarchicalTable treeTable​(String idColumn, String parentColumn)
      Create a hierarchical tree table. The structure of the table is encoded by an "id" and a "parent" column. The id column should represent a unique identifier for a given row, and the parent column indicates which row is the parent for a given row. Rows that have a null parent, are shown in the main table. It is possible for rows to be "orphaned", if their parent reference is non-null and does not exist in the table.
      Specified by:
      treeTable in interface Table
      Overrides:
      treeTable in class WrappedDelegatingTable
      Parameters:
      idColumn - the name of a column containing a unique identifier for a particular row in the table
      parentColumn - the name of a column containing the parent's identifier, null for elements that are part of the root table
      Returns:
      a hierarchical table grouped according to the parentColumn
      ImplNote:
      The Preemptive version of this method will return a non-preemptive table
    • preemptiveUpdatesTable

      public Table preemptiveUpdatesTable​(long updateInterval)
      Specified by:
      preemptiveUpdatesTable in interface Table
      Overrides:
      preemptiveUpdatesTable in class WrappedDelegatingTable
    • applyPreview

      public Table applyPreview()
    • initializeTransientFieldsForLiveness

      @VisibleForTesting public final void initializeTransientFieldsForLiveness()
      Package-private for Serializable sub-classes to use in readObject 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 as LivenessReferent.retainReference() and return true. Otherwise, returns false rather than throwing an exception.
      Specified by:
      tryRetainReference in interface LivenessReferent
      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 interface LivenessReferent
    • getWeakReference

      public WeakReference<? extends LivenessReferent> getWeakReference()
      Description copied from interface: LivenessReferent
      Get a WeakReference to this referent. This may be cached, or newly created.
      Specified by:
      getWeakReference in interface LivenessReferent
      Returns:
      A new or cached reference to this referent
    • tryManage

      public final boolean tryManage​(@NotNull LivenessReferent referent)
      Description copied from interface: LivenessManager
      Attempt to add the specified referent to this manager.
      Specified by:
      tryManage in interface LivenessManager
      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 class ReferenceCounted