Class AbstractTableLocationProvider

All Implemented Interfaces:
com.fishlib.base.log.LogOutputAppendable, TableKey, TableLocationProvider, NamedImplementation
Direct Known Subclasses:
ReadOnlyLocalTableLocationProvider, RemoteTableDataService.TableLocationProviderImpl, WritableLocalTableLocationProvider

public abstract class AbstractTableLocationProvider extends SubscriptionAggregator<TableLocationProvider.Listener> implements TableLocationProvider
Partial TableLocationProvider implementation for use by TableDataService implementations.

It implements an interface similar to TableLocationProvider.Listener for implementation classes to use when communicating with the parent.

Note that implementations are responsible for determining when it's appropriate to call setInitialized() and/or override doInitialization().

  • Constructor Details

    • AbstractTableLocationProvider

      protected AbstractTableLocationProvider(@NotNull TableKey tableKey, boolean supportsSubscriptions)
      Parameters:
      tableKey - A key whose field values will be deep-copied to this provider
      supportsSubscriptions - Whether this provider should support subscriptions
  • Method Details

    • getLog

      protected static com.fishlib.io.logger.Logger getLog()
    • toString

      public final String toString()
      Overrides:
      toString in class Object
    • getTableKey

      @NotNull protected final TableLookupKey<String> getTableKey()
    • getNamespace

      @NotNull public final CharSequence getNamespace()
      Specified by:
      getNamespace in interface TableKey
      Returns:
      The namespace enclosing this table
    • getTableName

      @NotNull public final CharSequence getTableName()
      Specified by:
      getTableName in interface TableKey
      Returns:
      The name of this table
    • getTableType

      @NotNull public final TableType getTableType()
      Specified by:
      getTableType in interface TableKey
      Returns:
      The type of this table (which generally dictates storage, metadata-availability, etc)
    • mark

      public void mark(long localStamp)
      Description copied from interface: TableLocationProvider
      Indicate the start of a sweep of locations. This will be used to detect locations that have been removed from downstream.
      Specified by:
      mark in interface TableLocationProvider
      Parameters:
      localStamp - the value to set
    • removeUnvisited

      public boolean removeUnvisited(long localStamp)
      Description copied from interface: TableLocationProvider
      Removes any locations that were not visited after the given mark time.
      Specified by:
      removeUnvisited in interface TableLocationProvider
      Parameters:
      localStamp - any locations last visited before this mark will be removed.
      Returns:
      true if any locations were removed.
    • refreshAndRescan

      public void refreshAndRescan()
      Description copied from interface: TableLocationProvider
      Initialize or refresh state information about the list of existing locations. If applicable, perform extra work to ensure any cached information is up to date.
      Specified by:
      refreshAndRescan in interface TableLocationProvider
    • deliverInitialSnapshot

      protected final void deliverInitialSnapshot(@NotNull TableLocationProvider.Listener listener)
      Description copied from class: SubscriptionAggregator
      Prompt listeners to record current state, under the subscriptions lock.
      Specified by:
      deliverInitialSnapshot in class SubscriptionAggregator<TableLocationProvider.Listener>
      Parameters:
      listener - The listener to notify
    • handleTableLocationKey

      public void handleTableLocationKey(@NotNull TableLocationKey locationKey)
      Deliver a possibly-new key.
      Parameters:
      locationKey - The new key
    • handleTableLocationKey

      public final void handleTableLocationKey(@NotNull TableLocationKey locationKey, boolean verifyCheckpoint)
      Deliver a possibly-new key.
      Parameters:
      locationKey - The new key
      verifyCheckpoint - whether extra checking is desired (re-read the checkpoint ot see if it has changed)
    • handleTableLocationKeyRemoved

      public void handleTableLocationKeyRemoved(@NotNull TableLocation location)
      Remove the location, and notify subscribers that it is gone
      Parameters:
      location - the TableLocation to be removed
    • maybeReloadLocation

      protected boolean maybeReloadLocation(TableLocation tableLocation, boolean verifyCheckpoint, boolean observedLocationCreation)
      Determine whether the table (checkpoint) has changed out from under us and reload if necessary.
      Parameters:
      tableLocation - the maybe-new table location
      verifyCheckpoint - true if we are in a mode calling for checking location checkpoints
      observedLocationCreation - true if the location was just created, vs pulled from a map. This may influence what work is performed in this method.
      Returns:
      if the checkpoint was reloaded
    • removeTableLocationKey

      public void removeTableLocationKey(@NotNull TableLocationKey locationKey)
      Remove the given table location from the tableLocations map. Use with caution: the intent is that when a TableLocationProvider is told that a location is gone, we should quit providing it in the list of locations, and quit asking downstream providers how big it is.
      Specified by:
      removeTableLocationKey in interface TableLocationProvider
      Parameters:
      locationKey - the TableLocation to remove
    • makeTableLocation

      @NotNull protected abstract TableLocation makeTableLocation(@NotNull TableLocationKey locationKey)
      Make a new implementation-appropriate TableLocation from the supplied key.
      Parameters:
      locationKey - The table location key
      Returns:
      The new TableLocation
    • ensureInitialized

      public final TableLocationProvider ensureInitialized()
      Description copied from interface: TableLocationProvider
      Ensure that this location provider is initialized. Mainly useful in cases where it cannot be otherwise guaranteed that TableLocationProvider.refresh() or TableLocationProvider.subscribe(Listener) has been called prior to calls to the various table location fetch methods.
      Specified by:
      ensureInitialized in interface TableLocationProvider
      Returns:
      this, to allow method chaining
    • isInitialized

      protected final boolean isInitialized()
      Internal method for subclasses to call to determine if they need to call ensureInitialized(), if doing so might entail extra work (e.g. enqueueing an asynchronous job).
      Returns:
      Whether setInitialized() has been called
    • setInitialized

      protected final void setInitialized()
      Internal method for subclasses to call when they consider themselves to have been initialized.
    • doInitialization

      protected void doInitialization()
      Initialization method for subclasses to override, in case simply calling TableLocationProvider.refresh() is inappropriate. This is *not* guaranteed to be called only once. It should internally call setInitialized() upon successful initialization.
    • getTableLocations

      @NotNull public final Collection<TableLocation> getTableLocations()
      Description copied from interface: TableLocationProvider
      Get this provider's currently available locations. Locations returned may have null size - that is, they may not "exist" for application purposes.
      Specified by:
      getTableLocations in interface TableLocationProvider
      Returns:
      A collection of locations available from this provider
    • getTableLocationIfPresent

      @Nullable public TableLocation getTableLocationIfPresent(@NotNull TableLocationKey tableLocationKey)
      Specified by:
      getTableLocationIfPresent in interface TableLocationProvider
      Parameters:
      tableLocationKey - A key specifying the location to get
      Returns:
      The TableLocation matching the given key if present, else null
    • clearTableLocations

      protected void clearTableLocations()
      Clear the collection of table locations known by this TableLocationProvider, and clear the column locations known to each TableLocation. Synchronize as appropriate.
    • computeWithSubscriptionLock

      public <RESULT_TYPE, EXCEPTION_TYPE extends Exception> RESULT_TYPE computeWithSubscriptionLock(@NotNull FunctionalInterfaces.ThrowingSupplier<RESULT_TYPE,EXCEPTION_TYPE> supplier) throws EXCEPTION_TYPE
      If the TableLocationProvider supports subscriptions, do the action synchronized on the subscriptions lock.
      Parameters:
      supplier - The FunctionalInterfaces.ThrowingSupplier to get
      Returns:
      The result of invoking supplier
      Throws:
      EXCEPTION_TYPE - If supplier throws its declared exception