C - component typepublic abstract class AbstractComponentTracker<C> extends java.lang.Object implements ComponentTracker<C>
buildComponent(String), processPriorToRemoval(Object), and isComponentStale(Object)
methods as appropriate for their component type.| Modifier and Type | Class and Description |
|---|---|
private static class |
AbstractComponentTracker.Entry<C> |
private static interface |
AbstractComponentTracker.RemovalPredicator<C> |
| Modifier and Type | Field and Description |
|---|---|
private static boolean |
ACCESS_ORDERED |
private AbstractComponentTracker.RemovalPredicator<C> |
byExcedent |
private AbstractComponentTracker.RemovalPredicator<C> |
byLingering |
private AbstractComponentTracker.RemovalPredicator<C> |
byTimeout |
(package private) long |
lastCheck |
(package private) java.util.LinkedHashMap<java.lang.String,AbstractComponentTracker.Entry<C>> |
lingerersMap |
static long |
LINGERING_TIMEOUT |
(package private) java.util.LinkedHashMap<java.lang.String,AbstractComponentTracker.Entry<C>> |
liveMap |
protected int |
maxComponents |
protected long |
timeout |
static long |
WAIT_BETWEEN_SUCCESSIVE_REMOVAL_ITERATIONS
The minimum amount of time that has to elapse between successive removal iterations.
|
DEFAULT_MAX_COMPONENTS, DEFAULT_TIMEOUT| Constructor and Description |
|---|
AbstractComponentTracker() |
| Modifier and Type | Method and Description |
|---|---|
java.util.Collection<C> |
allComponents()
Returns the collection of all components tracked by this instance.
|
java.util.Set<java.lang.String> |
allKeys()
Set of all keys in this tracker in no particular order.
|
protected abstract C |
buildComponent(java.lang.String key)
Build a component based on the key.
|
void |
endOfLife(java.lang.String key)
Mark component identified by 'key' as having reached its end-of-life.
|
C |
find(java.lang.String key)
Find the component identified by 'key', without updating the timestamp.
|
private void |
genericStaleComponentRemover(java.util.LinkedHashMap<java.lang.String,AbstractComponentTracker.Entry<C>> map,
long now,
AbstractComponentTracker.RemovalPredicator<C> removalPredicator) |
int |
getComponentCount()
Returns the number of components tracked.
|
private AbstractComponentTracker.Entry<C> |
getFromEitherMap(java.lang.String key)
Get an entry from the liveMap, if not found search the lingerersMap.
|
int |
getMaxComponents() |
C |
getOrCreate(java.lang.String key,
long timestamp)
Get the component identified by 'key', updating its timestamp in the
process.
|
long |
getTimeout() |
protected abstract boolean |
isComponentStale(C c)
Components can declare themselves stale.
|
private boolean |
isEntryDoneLingering(AbstractComponentTracker.Entry<C> entry,
long now) |
private boolean |
isEntryStale(AbstractComponentTracker.Entry<C> entry,
long now) |
private boolean |
isTooSoonForRemovalIteration(long now) |
protected abstract void |
processPriorToRemoval(C component)
Stop or clean the component.
|
private void |
removeExcedentComponents() |
void |
removeStaleComponents(long now)
Clear (and detach) components which are stale.
|
private void |
removeStaleComponentsFromLingerersMap(long now) |
private void |
removeStaleComponentsFromMainMap(long now) |
void |
setMaxComponents(int maxComponents) |
void |
setTimeout(long timeout) |
private static final boolean ACCESS_ORDERED
public static final long LINGERING_TIMEOUT
public static final long WAIT_BETWEEN_SUCCESSIVE_REMOVAL_ITERATIONS
protected int maxComponents
protected long timeout
java.util.LinkedHashMap<java.lang.String,AbstractComponentTracker.Entry<C>> liveMap
java.util.LinkedHashMap<java.lang.String,AbstractComponentTracker.Entry<C>> lingerersMap
long lastCheck
private AbstractComponentTracker.RemovalPredicator<C> byExcedent
private AbstractComponentTracker.RemovalPredicator<C> byTimeout
private AbstractComponentTracker.RemovalPredicator<C> byLingering
protected abstract void processPriorToRemoval(C component)
component - protected abstract C buildComponent(java.lang.String key)
key - protected abstract boolean isComponentStale(C c)
c - public int getComponentCount()
ComponentTrackergetComponentCount in interface ComponentTracker<C>private AbstractComponentTracker.Entry<C> getFromEitherMap(java.lang.String key)
key - public C find(java.lang.String key)
Note that this method is synchronized.
find in interface ComponentTracker<C>key - public C getOrCreate(java.lang.String key, long timestamp)
Note that this method is atomic, i.e. synchronized.
getOrCreate in interface ComponentTracker<C>key - timestamp - public void endOfLife(java.lang.String key)
endOfLife in interface ComponentTracker<C>key - public void removeStaleComponents(long now)
removeStaleComponents in interface ComponentTracker<C>now - private void removeExcedentComponents()
private void removeStaleComponentsFromMainMap(long now)
private void removeStaleComponentsFromLingerersMap(long now)
private void genericStaleComponentRemover(java.util.LinkedHashMap<java.lang.String,AbstractComponentTracker.Entry<C>> map, long now, AbstractComponentTracker.RemovalPredicator<C> removalPredicator)
private boolean isTooSoonForRemovalIteration(long now)
private boolean isEntryStale(AbstractComponentTracker.Entry<C> entry, long now)
private boolean isEntryDoneLingering(AbstractComponentTracker.Entry<C> entry, long now)
public java.util.Set<java.lang.String> allKeys()
ComponentTrackerallKeys in interface ComponentTracker<C>public java.util.Collection<C> allComponents()
ComponentTrackerallComponents in interface ComponentTracker<C>public long getTimeout()
public void setTimeout(long timeout)
public int getMaxComponents()
public void setMaxComponents(int maxComponents)