Class ReplicatedTable

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

public class ReplicatedTable
extends InitialSnapshotTable
implements LiveTable, Closeable

A client side viewport of a server side Table. This is backed by a RemoteTableHandle.TableProxy which is in turn backed by a RemoteTableHandle. Clients may request a client id to set a specific viewport. This class will subscribe to updates for all of the specified rows and columns in all set viewports.

Note that in this case viewport is defined as a set of positions into the original table.

See Also:
Serialized Form
  • Field Details

  • Constructor Details

  • Method Details

    • getProcessedDelta

      public long getProcessedDelta()
    • setInitialSnapshot

      public void setInitialSnapshot​(InitialSnapshot initialSnapshot)
    • setReplacementSnapshot

      public void setReplacementSnapshot​(InitialSnapshot replacementSnapshot)
    • setColumnUpdateSnapshot

      @VisibleForTesting public void setColumnUpdateSnapshot​(InitialSnapshot updateSnapshot)
    • setRowUpdateSnapshot

      @VisibleForTesting public void setRowUpdateSnapshot​(InitialSnapshot updateSnapshot)
    • getSubscriptionId

      public int getSubscriptionId()
      Get the subscription ID of this table with the server. This ID can be used to retrieve the table on the server within a RemoteQuery
      Returns:
      the id of this table for use with queries to the server
    • handleUpdate

      @InternalUseOnly public void handleUpdate​(DeltaUpdates deltaUpdates)
    • refresh

      public void refresh()
      Description copied from interface: LiveTable
      Refresh this LiveTable.
      Specified by:
      refresh in interface LiveTable
    • getNotificationQueue

      protected NotificationQueue getNotificationQueue()
      Description copied from class: BaseTable
      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.
      Overrides:
      getNotificationQueue in class BaseTable
      Returns:
      The NotificationQueue to add to.
    • freeze

      public void freeze()
      Freeze the table. This will stop all update propagation.
    • close

      public void close()
      Description copied from interface: Table
      Release resources held by this table, possibly destructively. This may render the table unsuitable or unsafe for further use.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface Table
    • unsubscribe

      public void unsubscribe()
      Unsubscribe this table from the server. The table will no longer be usable afterwards
    • updateColumnSubscriptions

      public void updateColumnSubscriptions​(int client, BitSet newColumns)
      Set the set of columns subscribed for the specified client id.
      Parameters:
      client - the client id
      newColumns - the columns that should be subscribed.
    • getViewportClientId

      public int getViewportClientId()
      Allocate and return a new viewport client ID for use with setViewPort(int, Index) and it's overrides.
      Returns:
      the newly allocated client id.
    • setViewPort

      public void setViewPort​(int client, long firstPosition, long lastPosition)
      Set the row viewport for the specified client.
      Parameters:
      client - the client id
      firstPosition - the first position in the viewport
      lastPosition - the last position in the viewport (exclusive)
    • setViewportAndColumns

      public void setViewportAndColumns​(int client, long firstPosition, long lastPosition, BitSet columns)
      Set the row and column viewport for the specified client.
      Parameters:
      client - the client id
      firstPosition - the first position in the viewport
      lastPosition - the last position in the viewport (exclusive)
      columns - the columns in the viewport
    • removeViewportClient

      public void removeViewportClient​(int client)
      Remove the specified client from the set of viewports. This will remove any subscribed viewports for this client.
      Parameters:
      client - the client to remove.
    • suspendViewportClient

      public void suspendViewportClient​(int client)
      Suspend the viewport for a particular client. Suspended viewports will not receive updates
      Parameters:
      client - the client to suspend
    • setViewPort

      public void setViewPort​(int client, @NotNull Index newViewPort)
      Set the positional viewport for a particular client
      Parameters:
      client - the client id
      newViewPort - the viewport for this client
    • setViewportAndColumns

      public void setViewportAndColumns​(int client, Index newViewPort, BitSet columns)
      Set the positional viewport and relevant columns for the specified client
      Parameters:
      client - the client id
      newViewPort - the positional viewport
      columns - the columns to include
    • getUnsubscribed

      public boolean getUnsubscribed()
      Check if this table has been unsubscribed.
      Returns:
      true if the table has been unsubscribed
    • setUnsubscribed

      public void setUnsubscribed()
      Set this table as unsubscribed.
    • enqueueError

      public void enqueueError​(Throwable e)
      Enqueue an error to be reported on the next refresh cycle.
      Parameters:
      e - The error
    • getTableProxy

      public RemoteTableHandle.TableProxy getTableProxy()
      Get the RemoteTableHandle.TableProxy backing this replicated table.
      Returns:
      the backing proxy
    • setupReplicatedTable

      @InternalUseOnly public static ReplicatedTable setupReplicatedTable​(com.fishlib.io.logger.Logger log, int tableId, @NotNull RemoteTableHandle.TableProxy tableProxy, BitSet subscribedColumns, boolean isViewPort)
      Set up a Replicated table from the given proxy, id and columns. This is intended for Deephaven use only.
      Parameters:
      log - a logger
      tableId - the table ID from the pq
      tableProxy - the proxy to the original table
      subscribedColumns - a bitset of columns that are subscribed
      isViewPort - true if the table will be a viewport.
      Returns:
      a properly initialized ReplicatedTable
    • setupForUnitTests

      @TestUseOnly public static ReplicatedTable setupForUnitTests​(com.fishlib.io.logger.Logger log, LiveTableRegistrar registrar, NotificationQueue notificationQueue, @NotNull RemoteTableHandle.TableProxy tableProxy, int tableId, Table tablePrototype, boolean isViewPort)
    • makeColumns

      @NotNull protected static LinkedHashMap<String,​ColumnSource> makeColumns​(com.illumon.dataobjects.ColumnDefinition[] columns, WritableSource[] writableSources, RedirectionIndex emptyRedirectionIndex)
      Setup the columns for the replicated table. NB: Your emptyRedirectionIndex must be initialized and empty.
    • waitForData

      public void waitForData()
      Wait for initial data to be available. This method will block.
    • waitForPopulation

      public void waitForPopulation​(long position, int column)
      Waits for the specified position to become populated. This method automatically converts the specified position into the table's keyspace.
      Parameters:
      position - the position
      column - the column
    • waitForPopulation

      public void waitForPopulation()
      Wait for all of the columns and rows in the viewport to become populated.
    • waitForPopulation

      public void waitForPopulation​(Index positions, BitSet columns)
      Waits for all of the columns in the specified positions to become populated. This method automatically converts the specified positions into the table's keyspace.
      Parameters:
      positions - the rows to inspect
      columns - a BitSet of column indices to check for population
    • isViewPort

      public boolean isViewPort()
      Check if this table is a viewport. A viewport table is a partial view of another table. If this returns false then this table contains the entire source table it was based on.
      Returns:
      true if this table was a viewport.
    • isPopulated

      public boolean isPopulated​(long position, int column)
      Check if the specified position is populated. This method automatically converts the specified position into the table's keyspace.
      Parameters:
      position - the position
      column - the column
      Returns:
      true of it has been populated
    • getViewportIndex

      public Index getViewportIndex()
      Get the current positional viewport index. If this ReplicatedTable is a viewport for another table (see ...) then this returns the union of all viewports from all clients. Otherwise it returns a flat set of positions from 0 - tableSize -1;
      Returns:
      an index of viewport positions
    • getPopulatedRows

      public Index getPopulatedRows()
      Get the set of populated rows in Key space.
      Returns:
      the populated keys.
    • isPopulated

      public boolean isPopulated​(long row, BitSet columns)
      Check if All of the columns in the specified row are populated. Note that the input row index is expected to be in position space. It is internally converted to the table's keyspace.
      Parameters:
      row - The row to inspect
      columns - a BitSet of column indices to check for population
    • isPopulated

      public boolean isPopulated​(Index rows, BitSet columns)
      Check if All of the columns in the specified row are populated. Note that the input row index is expected to be in position space. It is internally converted to the table's keyspace.
      Parameters:
      rows - the rows to inspect
      columns - a BitSet of column indices to check for population
    • isColumnFullyPopulated

      public boolean isColumnFullyPopulated​(int column)
      Check if the column specified is fully populated.
      Parameters:
      column - the column index
      Returns:
      true if the column is completely populated.
    • 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
      Overrides:
      getAttribute in class BaseTable
      Parameters:
      key - the name of the attribute
      Returns:
      the value, or null if there was none.
    • 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
      Overrides:
      hasAttribute in class BaseTable
      Parameters:
      name - the name of the attribute
      Returns:
      true if the attribute exists
    • addPopulationListener

      public void addPopulationListener​(@NotNull ReplicatedTable.PopulationListener listener)
      Listen for population events. Note that these are stored as WeakReferences, so you must retain a reference to them somewhere or they will be reclaimed by the garbage collector.
      Parameters:
      listener - the listener
    • removePopulationListener

      public void removePopulationListener​(@NotNull ReplicatedTable.PopulationListener listener)
      Remove the specified listener from notifications.
      Parameters:
      listener - the listener to remove
    • getRemoteTableHandle

      public RemoteTableHandle getRemoteTableHandle()
      Get the RemoteTableHandle backing this ReplicatedTable
      Returns:
      the RemoteTableHandle.
    • toString

      public String toString()
      Overrides:
      toString in class BaseTable
    • 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 BaseTable
    • 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