Package ch.qos.logback.core.spi
Class AbstractComponentTracker<C>
- java.lang.Object
-
- ch.qos.logback.core.spi.AbstractComponentTracker<C>
-
- Type Parameters:
C- component type
- All Implemented Interfaces:
ComponentTracker<C>
- Direct Known Subclasses:
AppenderTracker,CyclicBufferTracker
public abstract class AbstractComponentTracker<C> extends java.lang.Object implements ComponentTracker<C>
An abstract implementation of the ComponentTracker interface. Derived classes must implementbuildComponent(String),processPriorToRemoval(Object), andisComponentStale(Object)methods as appropriate for their component type.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classAbstractComponentTracker.Entry<C>private static interfaceAbstractComponentTracker.RemovalPredicator<C>
-
Field Summary
Fields Modifier and Type Field Description private static booleanACCESS_ORDEREDprivate AbstractComponentTracker.RemovalPredicator<C>byExcedentprivate AbstractComponentTracker.RemovalPredicator<C>byLingeringprivate AbstractComponentTracker.RemovalPredicator<C>byTimeout(package private) longlastCheck(package private) java.util.LinkedHashMap<java.lang.String,AbstractComponentTracker.Entry<C>>lingerersMapstatic longLINGERING_TIMEOUT(package private) java.util.LinkedHashMap<java.lang.String,AbstractComponentTracker.Entry<C>>liveMapprotected intmaxComponentsprotected longtimeoutstatic longWAIT_BETWEEN_SUCCESSIVE_REMOVAL_ITERATIONSThe minimum amount of time that has to elapse between successive removal iterations.-
Fields inherited from interface ch.qos.logback.core.spi.ComponentTracker
DEFAULT_MAX_COMPONENTS, DEFAULT_TIMEOUT
-
-
Constructor Summary
Constructors Constructor Description AbstractComponentTracker()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method 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 CbuildComponent(java.lang.String key)Build a component based on the key.voidendOfLife(java.lang.String key)Mark component identified by 'key' as having reached its end-of-life.Cfind(java.lang.String key)Find the component identified by 'key', without updating the timestamp.private voidgenericStaleComponentRemover(java.util.LinkedHashMap<java.lang.String,AbstractComponentTracker.Entry<C>> map, long now, AbstractComponentTracker.RemovalPredicator<C> removalPredicator)intgetComponentCount()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.intgetMaxComponents()CgetOrCreate(java.lang.String key, long timestamp)Get the component identified by 'key', updating its timestamp in the process.longgetTimeout()protected abstract booleanisComponentStale(C c)Components can declare themselves stale.private booleanisEntryDoneLingering(AbstractComponentTracker.Entry<C> entry, long now)private booleanisEntryStale(AbstractComponentTracker.Entry<C> entry, long now)private booleanisTooSoonForRemovalIteration(long now)protected abstract voidprocessPriorToRemoval(C component)Stop or clean the component.private voidremoveExcedentComponents()voidremoveStaleComponents(long now)Clear (and detach) components which are stale.private voidremoveStaleComponentsFromLingerersMap(long now)private voidremoveStaleComponentsFromMainMap(long now)voidsetMaxComponents(int maxComponents)voidsetTimeout(long timeout)
-
-
-
Field Detail
-
ACCESS_ORDERED
private static final boolean ACCESS_ORDERED
- See Also:
- Constant Field Values
-
LINGERING_TIMEOUT
public static final long LINGERING_TIMEOUT
- See Also:
- Constant Field Values
-
WAIT_BETWEEN_SUCCESSIVE_REMOVAL_ITERATIONS
public static final long WAIT_BETWEEN_SUCCESSIVE_REMOVAL_ITERATIONS
The minimum amount of time that has to elapse between successive removal iterations.- See Also:
- Constant Field Values
-
maxComponents
protected int maxComponents
-
timeout
protected long timeout
-
liveMap
java.util.LinkedHashMap<java.lang.String,AbstractComponentTracker.Entry<C>> liveMap
-
lingerersMap
java.util.LinkedHashMap<java.lang.String,AbstractComponentTracker.Entry<C>> lingerersMap
-
lastCheck
long lastCheck
-
byExcedent
private AbstractComponentTracker.RemovalPredicator<C> byExcedent
-
byTimeout
private AbstractComponentTracker.RemovalPredicator<C> byTimeout
-
byLingering
private AbstractComponentTracker.RemovalPredicator<C> byLingering
-
-
Method Detail
-
processPriorToRemoval
protected abstract void processPriorToRemoval(C component)
Stop or clean the component.- Parameters:
component-
-
buildComponent
protected abstract C buildComponent(java.lang.String key)
Build a component based on the key.- Parameters:
key-- Returns:
-
isComponentStale
protected abstract boolean isComponentStale(C c)
Components can declare themselves stale. Such components may be removed before they time out.- Parameters:
c-- Returns:
-
getComponentCount
public int getComponentCount()
Description copied from interface:ComponentTrackerReturns the number of components tracked.- Specified by:
getComponentCountin interfaceComponentTracker<C>- Returns:
- number of components
-
getFromEitherMap
private AbstractComponentTracker.Entry<C> getFromEitherMap(java.lang.String key)
Get an entry from the liveMap, if not found search the lingerersMap.- Parameters:
key-- Returns:
-
find
public C find(java.lang.String key)
Find the component identified by 'key', without updating the timestamp. Returns null if no corresponding component could be found.Note that this method is synchronized.
- Specified by:
findin interfaceComponentTracker<C>- Parameters:
key-- Returns:
- corresponding component, may be null
-
getOrCreate
public C getOrCreate(java.lang.String key, long timestamp)
Get the component identified by 'key', updating its timestamp in the process. If the corresponding component could not be found, it is created.Note that this method is atomic, i.e. synchronized.
- Specified by:
getOrCreatein interfaceComponentTracker<C>- Parameters:
key-timestamp-- Returns:
-
endOfLife
public void endOfLife(java.lang.String key)
Mark component identified by 'key' as having reached its end-of-life.- Specified by:
endOfLifein interfaceComponentTracker<C>- Parameters:
key-
-
removeStaleComponents
public void removeStaleComponents(long now)
Clear (and detach) components which are stale. Components which have not been accessed for more than a user-specified duration are deemed stale.- Specified by:
removeStaleComponentsin interfaceComponentTracker<C>- Parameters:
now-
-
removeExcedentComponents
private void removeExcedentComponents()
-
removeStaleComponentsFromMainMap
private void removeStaleComponentsFromMainMap(long now)
-
removeStaleComponentsFromLingerersMap
private void removeStaleComponentsFromLingerersMap(long now)
-
genericStaleComponentRemover
private void genericStaleComponentRemover(java.util.LinkedHashMap<java.lang.String,AbstractComponentTracker.Entry<C>> map, long now, AbstractComponentTracker.RemovalPredicator<C> removalPredicator)
-
isTooSoonForRemovalIteration
private boolean isTooSoonForRemovalIteration(long now)
-
isEntryStale
private boolean isEntryStale(AbstractComponentTracker.Entry<C> entry, long now)
-
isEntryDoneLingering
private boolean isEntryDoneLingering(AbstractComponentTracker.Entry<C> entry, long now)
-
allKeys
public java.util.Set<java.lang.String> allKeys()
Description copied from interface:ComponentTrackerSet of all keys in this tracker in no particular order.- Specified by:
allKeysin interfaceComponentTracker<C>- Returns:
-
allComponents
public java.util.Collection<C> allComponents()
Description copied from interface:ComponentTrackerReturns the collection of all components tracked by this instance.- Specified by:
allComponentsin interfaceComponentTracker<C>- Returns:
- collection of components
-
getTimeout
public long getTimeout()
-
setTimeout
public void setTimeout(long timeout)
-
getMaxComponents
public int getMaxComponents()
-
setMaxComponents
public void setMaxComponents(int maxComponents)
-
-