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
An abstract implementation of the ComponentTracker interface. Derived classes must implement
buildComponent(String)
, processPriorToRemoval(Object)
, and isComponentStale(Object)
methods as appropriate for their component type.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
private static interface
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final boolean
(package private) long
(package private) LinkedHashMap<String,
AbstractComponentTracker.Entry<C>> static final long
(package private) LinkedHashMap<String,
AbstractComponentTracker.Entry<C>> protected int
protected long
static final long
The 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 -
Method Summary
Modifier and TypeMethodDescriptionReturns the collection of all components tracked by this instance.allKeys()
Set of all keys in this tracker in no particular order.protected abstract C
buildComponent
(String key) Build a component based on the key.void
Mark component identified by 'key' as having reached its end-of-life.Find the component identified by 'key', without updating the timestamp.private void
genericStaleComponentRemover
(LinkedHashMap<String, AbstractComponentTracker.Entry<C>> map, long now, AbstractComponentTracker.RemovalPredicator<C> removalPredicator) int
Returns the number of components tracked.private AbstractComponentTracker.Entry<C>
getFromEitherMap
(String key) Get an entry from the liveMap, if not found search the lingerersMap.int
getOrCreate
(String key, long timestamp) Get the component identified by 'key', updating its timestamp in the process.long
protected abstract boolean
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
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)
-
Field Details
-
ACCESS_ORDERED
private static final boolean ACCESS_ORDERED- See Also:
-
LINGERING_TIMEOUT
public static final long LINGERING_TIMEOUT- See Also:
-
WAIT_BETWEEN_SUCCESSIVE_REMOVAL_ITERATIONS
public static final long WAIT_BETWEEN_SUCCESSIVE_REMOVAL_ITERATIONSThe minimum amount of time that has to elapse between successive removal iterations.- See Also:
-
maxComponents
protected int maxComponents -
timeout
protected long timeout -
liveMap
LinkedHashMap<String,AbstractComponentTracker.Entry<C>> liveMap -
lingerersMap
LinkedHashMap<String,AbstractComponentTracker.Entry<C>> lingerersMap -
lastCheck
long lastCheck -
byExcedent
-
byTimeout
-
byLingering
-
-
Constructor Details
-
AbstractComponentTracker
public AbstractComponentTracker()
-
-
Method Details
-
processPriorToRemoval
Stop or clean the component.- Parameters:
component
-
-
buildComponent
Build a component based on the key.- Parameters:
key
-- Returns:
-
isComponentStale
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:ComponentTracker
Returns the number of components tracked.- Specified by:
getComponentCount
in interfaceComponentTracker<C>
- Returns:
- number of components
-
getFromEitherMap
Get an entry from the liveMap, if not found search the lingerersMap.- Parameters:
key
-- Returns:
-
find
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:
find
in interfaceComponentTracker<C>
- Parameters:
key
-- Returns:
- corresponding component, may be null
-
getOrCreate
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:
getOrCreate
in interfaceComponentTracker<C>
- Parameters:
key
-timestamp
-- Returns:
-
endOfLife
Mark component identified by 'key' as having reached its end-of-life.- Specified by:
endOfLife
in 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:
removeStaleComponents
in interfaceComponentTracker<C>
- Parameters:
now
-
-
removeExcedentComponents
private void removeExcedentComponents() -
removeStaleComponentsFromMainMap
private void removeStaleComponentsFromMainMap(long now) -
removeStaleComponentsFromLingerersMap
private void removeStaleComponentsFromLingerersMap(long now) -
genericStaleComponentRemover
private void genericStaleComponentRemover(LinkedHashMap<String, AbstractComponentTracker.Entry<C>> map, long now, AbstractComponentTracker.RemovalPredicator<C> removalPredicator) -
isTooSoonForRemovalIteration
private boolean isTooSoonForRemovalIteration(long now) -
isEntryStale
-
isEntryDoneLingering
-
allKeys
Description copied from interface:ComponentTracker
Set of all keys in this tracker in no particular order.- Specified by:
allKeys
in interfaceComponentTracker<C>
- Returns:
-
allComponents
Description copied from interface:ComponentTracker
Returns the collection of all components tracked by this instance.- Specified by:
allComponents
in 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)
-