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
subscriptions
Fields inherited from interface com.illumon.iris.db.v2.locations.TableLocationProvider
globalMark
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
AbstractTableLocationProvider
(TableKey tableKey, boolean supportsSubscriptions) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Clear 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 void
Prompt listeners to record current state, under the subscriptions lock.protected void
Initialization method for subclasses to override, in case simply callingTableLocationProvider.refresh()
is inappropriate.final TableLocationProvider
Ensure that this location provider is initialized.protected static com.fishlib.io.logger.Logger
getLog()
final CharSequence
protected final TableLookupKey<String>
getTableLocationIfPresent
(TableLocationKey tableLocationKey) final Collection<TableLocation>
Get this provider's currently available locations.final CharSequence
final TableType
void
handleTableLocationKey
(TableLocationKey locationKey) Deliver a possibly-new key.final void
handleTableLocationKey
(TableLocationKey locationKey, boolean verifyCheckpoint) Deliver a possibly-new key.void
handleTableLocationKeyRemoved
(TableLocation location) Remove the location, and notify subscribers that it is goneprotected final boolean
Internal method for subclasses to call to determine if they need to callensureInitialized()
, if doing so might entail extra work (e.g.protected abstract TableLocation
makeTableLocation
(TableLocationKey locationKey) Make a new implementation-appropriate TableLocation from the supplied key.void
mark
(long localStamp) Indicate the start of a sweep of locations.protected boolean
maybeReloadLocation
(TableLocation tableLocation, boolean verifyCheckpoint, boolean observedLocationCreation) Determine whether the table (checkpoint) has changed out from under us and reload if necessary.void
Initialize or refresh state information about the list of existing locations.void
removeTableLocationKey
(TableLocationKey locationKey) Remove the given table location from the tableLocations map.boolean
removeUnvisited
(long localStamp) Removes any locations that were not visited after the given mark time.protected final void
Internal method for subclasses to call when they consider themselves to have been initialized.final String
toString()
Methods inherited from class com.illumon.iris.db.v2.locations.SubscriptionAggregator
activateUnderlyingDataSource, activationFailed, activationSuccessful, checkHasSubscribers, deactivateUnderlyingDataSource, matchSubscriptionToken, postActivationHook, subscribe, supportsSubscriptions, unsubscribe
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface com.illumon.util.type.NamedImplementation
getImplementationName
Methods inherited from interface com.illumon.iris.db.v2.locations.TableKey
append, asTableIdentifier, toStringDetailed, toStringHelper, toStringSimple, writeTo
Methods 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:
getNamespace
in interfaceTableKey
- Returns:
- The namespace enclosing this table
-
getTableName
- Specified by:
getTableName
in interfaceTableKey
- Returns:
- The name of this table
-
getTableType
- Specified by:
getTableType
in interfaceTableKey
- 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 interfaceTableLocationProvider
- 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 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: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 interfaceTableLocationProvider
-
deliverInitialSnapshot
Description copied from class:SubscriptionAggregator
Prompt listeners to record current state, under the subscriptions lock.- Specified by:
deliverInitialSnapshot
in 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:
removeTableLocationKey
in 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:TableLocationProvider
Ensure 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:
ensureInitialized
in 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: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 interfaceTableLocationProvider
- Returns:
- A collection of locations available from this provider
-
getTableLocationIfPresent
@Nullable public TableLocation getTableLocationIfPresent(@NotNull TableLocationKey tableLocationKey) - Specified by:
getTableLocationIfPresent
in 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.ThrowingSupplier
to get- Returns:
- The result of invoking
supplier
- Throws:
EXCEPTION_TYPE
- Ifsupplier
throws its declared exception
-