Package ch.qos.logback.core
Class ContextBase
- java.lang.Object
-
- ch.qos.logback.core.ContextBase
-
- All Implemented Interfaces:
Context,LifeCycle,PropertyContainer
- Direct Known Subclasses:
AccessContext,LoggerContext,RequestLogImpl
public class ContextBase extends java.lang.Object implements Context, LifeCycle
-
-
Field Summary
Fields Modifier and Type Field Description private longbirthTime(package private) LogbackLockconfigurationLockprivate LifeCycleManagerlifeCycleManagerprivate java.lang.Stringname(package private) java.util.Map<java.lang.String,java.lang.Object>objectMap(package private) java.util.Map<java.lang.String,java.lang.String>propertyMapprivate java.util.concurrent.ScheduledExecutorServicescheduledExecutorServiceprotected java.util.List<java.util.concurrent.ScheduledFuture<?>>scheduledFuturesprivate StatusManagersmprivate booleanstarted
-
Constructor Summary
Constructors Constructor Description ContextBase()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddScheduledFuture(java.util.concurrent.ScheduledFuture<?> scheduledFuture)longgetBirthTime()The time at which this context was created, expressed in millisecond elapsed since the epoch (1.1.1970).java.lang.ObjectgetConfigurationLock()Object used for synchronization purposes.java.util.Map<java.lang.String,java.lang.String>getCopyOfPropertyMap()Get a copy of the property mapjava.util.concurrent.ExecutorServicegetExecutorService()Every context has an ExecutorService which be invoked to execute certain tasks in a separate thread.(package private) LifeCycleManagergetLifeCycleManager()Gets the life cycle manager for this context.java.lang.StringgetName()Contexts are named objects.java.lang.ObjectgetObject(java.lang.String key)A Context can act as a store for various objects used by LOGBack components.java.lang.StringgetProperty(java.lang.String key)Given a key, return the corresponding property value.java.util.concurrent.ScheduledExecutorServicegetScheduledExecutorService()Returns the ScheduledExecutorService for this context.java.util.List<java.util.concurrent.ScheduledFuture<?>>getScheduledFutures()StatusManagergetStatusManager()Return the StatusManager instance in use.protected voidinitCollisionMaps()booleanisStarted()private java.lang.StringlazyGetHostname()private voidputHostnameProperty(java.lang.String hostname)voidputObject(java.lang.String key, java.lang.Object value)Store an object under 'key'.voidputProperty(java.lang.String key, java.lang.String val)Set a property of this context.voidregister(LifeCycle component)Register a component that participates in the context's life cycle.voidremoveObject(java.lang.String key)private voidremoveShutdownHook()voidreset()Clear the internal objectMap and all properties.voidsetName(java.lang.String name)The context name can be set only if it is not already set, or if the current name is the default context name, namely "default", or if the current name and the old name are the same.voidsetStatusManager(StatusManager statusManager)Set theStatusManagerfor this context.voidstart()voidstop()private voidstopExecutorService()java.lang.StringtoString()
-
-
-
Field Detail
-
birthTime
private long birthTime
-
name
private java.lang.String name
-
sm
private StatusManager sm
-
propertyMap
java.util.Map<java.lang.String,java.lang.String> propertyMap
-
objectMap
java.util.Map<java.lang.String,java.lang.Object> objectMap
-
configurationLock
LogbackLock configurationLock
-
scheduledExecutorService
private java.util.concurrent.ScheduledExecutorService scheduledExecutorService
-
scheduledFutures
protected java.util.List<java.util.concurrent.ScheduledFuture<?>> scheduledFutures
-
lifeCycleManager
private LifeCycleManager lifeCycleManager
-
started
private boolean started
-
-
Method Detail
-
getStatusManager
public StatusManager getStatusManager()
Description copied from interface:ContextReturn the StatusManager instance in use.- Specified by:
getStatusManagerin interfaceContext- Returns:
- the
StatusManagerinstance in use.
-
setStatusManager
public void setStatusManager(StatusManager statusManager)
Set theStatusManagerfor this context. Note that by default this context is initialized with aBasicStatusManager. A null value for the 'statusManager' argument is not allowed.A malicious attacker can set the status manager to a dummy instance, disabling internal error reporting.
- Parameters:
statusManager- the new status manager
-
getCopyOfPropertyMap
public java.util.Map<java.lang.String,java.lang.String> getCopyOfPropertyMap()
Description copied from interface:ContextGet a copy of the property map- Specified by:
getCopyOfPropertyMapin interfaceContext- Specified by:
getCopyOfPropertyMapin interfacePropertyContainer
-
putProperty
public void putProperty(java.lang.String key, java.lang.String val)Description copied from interface:ContextSet a property of this context.- Specified by:
putPropertyin interfaceContext
-
initCollisionMaps
protected void initCollisionMaps()
-
getProperty
public java.lang.String getProperty(java.lang.String key)
Given a key, return the corresponding property value. If invoked with the special key "CONTEXT_NAME", the name of the context is returned.- Specified by:
getPropertyin interfaceContext- Specified by:
getPropertyin interfacePropertyContainer- Parameters:
key-- Returns:
-
lazyGetHostname
private java.lang.String lazyGetHostname()
-
putHostnameProperty
private void putHostnameProperty(java.lang.String hostname)
-
getObject
public java.lang.Object getObject(java.lang.String key)
Description copied from interface:ContextA Context can act as a store for various objects used by LOGBack components.
-
putObject
public void putObject(java.lang.String key, java.lang.Object value)Description copied from interface:ContextStore an object under 'key'. If no object can be found, null is returned.
-
removeObject
public void removeObject(java.lang.String key)
-
getName
public java.lang.String getName()
Description copied from interface:ContextContexts are named objects.
-
reset
public void reset()
Clear the internal objectMap and all properties. Removes registered shutdown hook
-
setName
public void setName(java.lang.String name) throws java.lang.IllegalStateExceptionThe context name can be set only if it is not already set, or if the current name is the default context name, namely "default", or if the current name and the old name are the same.
-
getBirthTime
public long getBirthTime()
Description copied from interface:ContextThe time at which this context was created, expressed in millisecond elapsed since the epoch (1.1.1970).- Specified by:
getBirthTimein interfaceContext- Returns:
- The time as measured when this class was created.
-
getConfigurationLock
public java.lang.Object getConfigurationLock()
Description copied from interface:ContextObject used for synchronization purposes. INTENDED FOR INTERNAL USAGE.- Specified by:
getConfigurationLockin interfaceContext
-
getExecutorService
public java.util.concurrent.ExecutorService getExecutorService()
Description copied from interface:ContextEvery context has an ExecutorService which be invoked to execute certain tasks in a separate thread.- Specified by:
getExecutorServicein interfaceContext- Returns:
- the executor for this context.
-
getScheduledExecutorService
public java.util.concurrent.ScheduledExecutorService getScheduledExecutorService()
Description copied from interface:ContextReturns the ScheduledExecutorService for this context.- Specified by:
getScheduledExecutorServicein interfaceContext- Returns:
-
stopExecutorService
private void stopExecutorService()
-
removeShutdownHook
private void removeShutdownHook()
-
register
public void register(LifeCycle component)
Description copied from interface:ContextRegister a component that participates in the context's life cycle.All components registered via this method will be stopped and removed from the context when the context is reset.
-
getLifeCycleManager
LifeCycleManager getLifeCycleManager()
Gets the life cycle manager for this context.The default implementation lazily initializes an instance of
LifeCycleManager. Subclasses may override to provide a custom manager implementation, but must take care to return the same manager object for each call to this method.This is exposed primarily to support instrumentation for unit testing.
- Returns:
- manager object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
addScheduledFuture
public void addScheduledFuture(java.util.concurrent.ScheduledFuture<?> scheduledFuture)
- Specified by:
addScheduledFuturein interfaceContext
-
getScheduledFutures
public java.util.List<java.util.concurrent.ScheduledFuture<?>> getScheduledFutures()
-
-