Package com.illumon.iris.db.v2.locations
Class AbstractTableLocationProvider
java.lang.Object
com.illumon.iris.db.v2.locations.SubscriptionAggregator<TableLocationProvider.Listener>
com.illumon.iris.db.v2.locations.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().
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.illumon.iris.db.v2.locations.TableKey
TableKey.KeyedObjectKeyImpl<VALUE_TYPE>, TableKey.SelfKeyedObjectKeyImpl<VALUE_TYPE extends TableKey>Nested classes/interfaces inherited from interface com.illumon.iris.db.v2.locations.TableLocationProvider
TableLocationProvider.Listener, TableLocationProvider.NullTableLocationProvider -
Field Summary
Fields inherited from class com.illumon.iris.db.v2.locations.SubscriptionAggregator
subscriptionsFields inherited from interface com.illumon.iris.db.v2.locations.TableLocationProvider
globalMark -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractTableLocationProvider(TableKey tableKey, boolean supportsSubscriptions) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidClear the collection of table locations known by this TableLocationProvider, and clear the column locations known to each TableLocation.<RESULT_TYPE,EXCEPTION_TYPE extends Exception>
RESULT_TYPEcomputeWithSubscriptionLock(FunctionalInterfaces.ThrowingSupplier<RESULT_TYPE, EXCEPTION_TYPE> supplier) If the TableLocationProvider supports subscriptions, do the action synchronized on the subscriptions lock.protected final voidPrompt listeners to record current state, under the subscriptions lock.protected voidInitialization method for subclasses to override, in case simply callingTableLocationProvider.refresh()is inappropriate.final TableLocationProviderEnsure that this location provider is initialized.protected static com.fishlib.io.logger.LoggergetLog()final CharSequenceprotected final TableLookupKey<String>getTableLocationIfPresent(TableLocationKey tableLocationKey) final Collection<TableLocation>Get this provider's currently available locations.final CharSequencefinal TableTypevoidhandleTableLocationKey(TableLocationKey locationKey) Deliver a possibly-new key.final voidhandleTableLocationKey(TableLocationKey locationKey, boolean verifyCheckpoint) Deliver a possibly-new key.voidhandleTableLocationKeyRemoved(TableLocation location) Remove the location, and notify subscribers that it is goneprotected final booleanInternal method for subclasses to call to determine if they need to callensureInitialized(), if doing so might entail extra work (e.g.protected abstract TableLocationmakeTableLocation(TableLocationKey locationKey) Make a new implementation-appropriate TableLocation from the supplied key.voidmark(long localStamp) Indicate the start of a sweep of locations.protected booleanmaybeReloadLocation(TableLocation tableLocation, boolean verifyCheckpoint, boolean observedLocationCreation) Determine whether the table (checkpoint) has changed out from under us and reload if necessary.voidInitialize or refresh state information about the list of existing locations.voidremoveTableLocationKey(TableLocationKey locationKey) Remove the given table location from the tableLocations map.booleanremoveUnvisited(long localStamp) Removes any locations that were not visited after the given mark time.protected final voidInternal method for subclasses to call when they consider themselves to have been initialized.final StringtoString()Methods inherited from class com.illumon.iris.db.v2.locations.SubscriptionAggregator
activateUnderlyingDataSource, activationFailed, activationSuccessful, checkHasSubscribers, deactivateUnderlyingDataSource, matchSubscriptionToken, postActivationHook, subscribe, supportsSubscriptions, unsubscribeMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.illumon.util.type.NamedImplementation
getImplementationNameMethods inherited from interface com.illumon.iris.db.v2.locations.TableKey
append, asTableIdentifier, toStringDetailed, toStringHelper, toStringSimple, writeToMethods inherited from interface com.illumon.iris.db.v2.locations.TableLocationProvider
getName, getTableLocation, getTableLocation, refresh, refreshAndRescan, subscribe, supportsSubscriptions, traverse, unsubscribe
-
Constructor Details
-
AbstractTableLocationProvider
- Parameters:
tableKey- A key whose field values will be deep-copied to this providersupportsSubscriptions- Whether this provider should support subscriptions
-
-
Method Details
-
getLog
protected static com.fishlib.io.logger.Logger getLog() -
toString
-
getTableKey
-
getNamespace
- Specified by:
getNamespacein interfaceTableKey- Returns:
- The namespace enclosing this table
-
getTableName
- Specified by:
getTableNamein interfaceTableKey- Returns:
- The name of this table
-
getTableType
- Specified by:
getTableTypein interfaceTableKey- Returns:
- The type of this table (which generally dictates storage, metadata-availability, etc)
-
mark
public void mark(long localStamp) Description copied from interface:TableLocationProviderIndicate the start of a sweep of locations. This will be used to detect locations that have been removed from downstream.- Specified by:
markin interfaceTableLocationProvider- Parameters:
localStamp- the value to set
-
removeUnvisited
public boolean removeUnvisited(long localStamp) Description copied from interface:TableLocationProviderRemoves any locations that were not visited after the given mark time.- Specified by:
removeUnvisitedin interfaceTableLocationProvider- 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:TableLocationProviderInitialize 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:
refreshAndRescanin interfaceTableLocationProvider
-
deliverInitialSnapshot
Description copied from class:SubscriptionAggregatorPrompt listeners to record current state, under the subscriptions lock.- Specified by:
deliverInitialSnapshotin classSubscriptionAggregator<TableLocationProvider.Listener>- Parameters:
listener- The listener to notify
-
handleTableLocationKey
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 keyverifyCheckpoint- whether extra checking is desired (re-read the checkpoint ot see if it has changed)
-
handleTableLocationKeyRemoved
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 locationverifyCheckpoint- true if we are in a mode calling for checking location checkpointsobservedLocationCreation- 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
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:
removeTableLocationKeyin interfaceTableLocationProvider- Parameters:
locationKey- the TableLocation to remove
-
makeTableLocation
Make a new implementation-appropriate TableLocation from the supplied key.- Parameters:
locationKey- The table location key- Returns:
- The new TableLocation
-
ensureInitialized
Description copied from interface:TableLocationProviderEnsure that this location provider is initialized. Mainly useful in cases where it cannot be otherwise guaranteed thatTableLocationProvider.refresh()orTableLocationProvider.subscribe(Listener)has been called prior to calls to the various table location fetch methods.- Specified by:
ensureInitializedin interfaceTableLocationProvider- Returns:
- this, to allow method chaining
-
isInitialized
protected final boolean isInitialized()Internal method for subclasses to call to determine if they need to callensureInitialized(), 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 callingTableLocationProvider.refresh()is inappropriate. This is *not* guaranteed to be called only once. It should internally callsetInitialized()upon successful initialization. -
getTableLocations
Description copied from interface:TableLocationProviderGet this provider's currently available locations. Locations returned may have null size - that is, they may not "exist" for application purposes.- Specified by:
getTableLocationsin interfaceTableLocationProvider- Returns:
- A collection of locations available from this provider
-
getTableLocationIfPresent
@Nullable public TableLocation getTableLocationIfPresent(@NotNull TableLocationKey tableLocationKey) - Specified by:
getTableLocationIfPresentin interfaceTableLocationProvider- 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_TYPEIf the TableLocationProvider supports subscriptions, do the action synchronized on the subscriptions lock.- Parameters:
supplier- TheFunctionalInterfaces.ThrowingSupplierto get- Returns:
- The result of invoking
supplier - Throws:
EXCEPTION_TYPE- Ifsupplierthrows its declared exception
-