- java.lang.Object
-
- ch.qos.logback.core.ContextBase
-
- All Implemented Interfaces:
Context,LifeCycle,PropertyContainer
- Direct Known Subclasses:
LoggerContext
public class ContextBase extends Object implements Context, LifeCycle
-
-
Field Summary
Fields Modifier and Type Field Description protected ReentrantLockconfigurationLockprotected List<ScheduledFuture<?>>scheduledFutures
-
Constructor Summary
Constructors Constructor Description ContextBase()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddConfigurationEventListener(ConfigurationEventListener listener)Add aConfigurationEventListenerto this context.voidaddScheduledFuture(ScheduledFuture<?> scheduledFuture)Add scheduledFuture parameter to the list of known futures.voidaddSubstitutionProperty(String key, String value)voidfireConfigurationEvent(ConfigurationEvent configurationEvent)FireConfigurationEventby invokingregistered listeners.ExecutorServicegetAlternateExecutorService()Return an alternateExecutorServiceused for one task per thread execution.longgetBirthTime()The time at which this context was created, expressed in millisecond elapsed since the epoch (1.1.1970).ReentrantLockgetConfigurationLock()Object used for synchronization purposes.Map<String,String>getCopyOfPropertyMap()Get a copy of the property mapList<ScheduledFuture<?>>getCopyOfScheduledFutures()ExecutorServicegetExecutorService()Every context has an ExecutorService which be invoked to execute certain tasks in a separate thread.StringgetName()Contexts are named objects.ObjectgetObject(String key)A Context can act as a store for various objects used by LOGBack components.StringgetProperty(String key)Given a key, return the corresponding property value.ScheduledExecutorServicegetScheduledExecutorService()Returns the ScheduledExecutorService for this context.List<ScheduledFuture<?>>getScheduledFutures()Deprecated.replaced by getCopyOfScheduledFuturesSequenceNumberGeneratorgetSequenceNumberGenerator()StatusManagergetStatusManager()Return the StatusManager instance in use.booleanisStarted()voidputObject(String key, Object value)Store an object under 'key'.voidputProperty(String key, String val)Set a property of this context.voidregister(LifeCycle component)Register a component that participates in the context's life cycle.voidremoveConfigurationEventListener(ConfigurationEventListener listener)Remove an existing ConfigurationEventListenervoidremoveObject(String key)voidreset()Clear the internal objectMap and all properties.voidsetName(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.voidsetSequenceNumberGenerator(SequenceNumberGenerator sequenceNumberGenerator)voidsetStatusManager(StatusManager statusManager)Set theStatusManagerfor this context.voidstart()voidstop()StringtoString()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface ch.qos.logback.core.spi.PropertyContainer
addSubstitutionProperties
-
-
-
-
Field Detail
-
configurationLock
protected ReentrantLock configurationLock
-
scheduledFutures
protected List<ScheduledFuture<?>> scheduledFutures
-
-
Constructor Detail
-
ContextBase
public ContextBase()
-
-
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 Map<String,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(String key, String val)
Description copied from interface:ContextSet a property of this context.- Specified by:
putPropertyin interfaceContext
-
addSubstitutionProperty
public void addSubstitutionProperty(String key, String value)
- Specified by:
addSubstitutionPropertyin interfacePropertyContainer
-
getProperty
public String getProperty(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:
-
getObject
public Object getObject(String key)
Description copied from interface:ContextA Context can act as a store for various objects used by LOGBack components.
-
putObject
public void putObject(String key, Object value)
Description copied from interface:ContextStore an object under 'key'. If no object can be found, null is returned.
-
removeObject
public void removeObject(String key)
-
getName
public String getName()
Description copied from interface:ContextContexts are named objects.
-
reset
public void reset()
Clear the internal objectMap and all properties. Removes any registered shutdown hook.
-
setName
public void setName(String name) throws IllegalStateException
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.- Specified by:
setNamein interfaceContext- Throws:
IllegalStateException- if the context already has a name, other than "default".
-
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 ReentrantLock getConfigurationLock()
Description copied from interface:ContextObject used for synchronization purposes. INTENDED FOR INTERNAL USAGE.- Specified by:
getConfigurationLockin interfaceContext
-
getExecutorService
public 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.
-
getAlternateExecutorService
public ExecutorService getAlternateExecutorService()
Description copied from interface:ContextReturn an alternateExecutorServiceused for one task per thread execution.- Specified by:
getAlternateExecutorServicein interfaceContext- Returns:
- ExecutorService
-
getScheduledExecutorService
public ScheduledExecutorService getScheduledExecutorService()
Description copied from interface:ContextReturns the ScheduledExecutorService for this context.- Specified by:
getScheduledExecutorServicein interfaceContext- Returns:
- ScheduledExecutorService
-
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.
-
addScheduledFuture
public void addScheduledFuture(ScheduledFuture<?> scheduledFuture)
Description copied from interface:ContextAdd scheduledFuture parameter to the list of known futures.- Specified by:
addScheduledFuturein interfaceContext
-
getScheduledFutures
@Deprecated public List<ScheduledFuture<?>> getScheduledFutures()
Deprecated.replaced by getCopyOfScheduledFutures
-
getCopyOfScheduledFutures
public List<ScheduledFuture<?>> getCopyOfScheduledFutures()
-
getSequenceNumberGenerator
public SequenceNumberGenerator getSequenceNumberGenerator()
- Specified by:
getSequenceNumberGeneratorin interfaceContext
-
setSequenceNumberGenerator
public void setSequenceNumberGenerator(SequenceNumberGenerator sequenceNumberGenerator)
- Specified by:
setSequenceNumberGeneratorin interfaceContext
-
addConfigurationEventListener
public void addConfigurationEventListener(ConfigurationEventListener listener)
Description copied from interface:ContextAdd aConfigurationEventListenerto this context.Configuration events are supposed to be rare and listeners to such events rarer still.
The propagation of
configuration eventsis intended for internal testing as well as some coordination between configurators.- Specified by:
addConfigurationEventListenerin interfaceContext
-
removeConfigurationEventListener
public void removeConfigurationEventListener(ConfigurationEventListener listener)
Description copied from interface:ContextRemove an existing ConfigurationEventListener- Specified by:
removeConfigurationEventListenerin interfaceContext
-
fireConfigurationEvent
public void fireConfigurationEvent(ConfigurationEvent configurationEvent)
Description copied from interface:ContextFireConfigurationEventby invokingregistered listeners.Note that it is the role of configurators to invoke this method as a context does not necessarily know when it is being configured.
- Specified by:
fireConfigurationEventin interfaceContext
-
-