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
,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
-
Field Summary
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractTableLocationProvider(TableKey tableKey, boolean supportsSubscriptions)
-
Method Summary
Modifier and Type Method Description protected void
deliverInitialSnapshot(TableLocationProvider.Listener listener)
Prompt listeners to record current state, under the subscriptions lock.protected void
doInitialization()
Initialization method for subclasses to override, in case simply callingTableLocationProvider.refresh()
is inappropriate.TableLocationProvider
ensureInitialized()
Ensure that this location provider is initialized.protected static com.fishlib.io.logger.Logger
getLog()
CharSequence
getNamespace()
protected TableLookupKey<String>
getTableKey()
TableLocation
getTableLocationIfPresent(TableLocationKey tableLocationKey)
Collection<TableLocation>
getTableLocations()
Get this provider's currently available locations.CharSequence
getTableName()
TableType
getTableType()
void
handleTableLocationKey(TableLocationKey locationKey)
Deliver a possibly-new key.void
handleTableLocationKey(TableLocationKey locationKey, boolean verifyCheckpoint)
Deliver a possibly-new key.protected boolean
isInitialized()
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 now)
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
refreshAndRescan()
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 void
setInitialized()
Internal method for subclasses to call when they consider themselves to have been initialized.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.iris.db.v2.locations.TableKey
append, asTableIdentifier, toStringDetailed, toStringHelper, writeTo
Methods inherited from interface com.illumon.iris.db.v2.locations.TableLocationProvider
getName, getTableLocation, getTableLocation, refresh, refreshAndRescan, subscribe, supportsSubscriptions, 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 now)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:
now
- 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)
-
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
-