public abstract class AbstractManager extends Object implements AutoCloseable
This class implements AutoCloseable
mostly to allow unit tests to be written safely and succinctly. While
managers do need to allocate resources (usually on construction) and then free these resources, a manager is longer
lived than other auto-closeable objects like streams. None the less, making a manager AutoCloseable forces readers to
be aware of the pattern: allocate resources on construction and call close()
at some point.
Modifier and Type | Class and Description |
---|---|
protected static class |
AbstractManager.AbstractFactoryData
Implementations should extend this class for passing data between the getManager method and the manager factory
class.
|
Modifier and Type | Field and Description |
---|---|
protected int |
count
Number of Appenders using this manager.
|
protected static Logger |
LOGGER
Allow subclasses access to the status logger without creating another instance.
|
Modifier | Constructor and Description |
---|---|
protected |
AbstractManager(LoggerContext loggerContext,
String name) |
Modifier and Type | Method and Description |
---|---|
void |
close()
Called to signify that this Manager is no longer required by an Appender.
|
Map<String,String> |
getContentFormat()
Provide a description of the content format supported by this Manager.
|
protected int |
getCount() |
LoggerContext |
getLoggerContext()
Gets the logger context used to create this instance or null.
|
static <M extends AbstractManager,T> |
getManager(String name,
ManagerFactory<M,T> factory,
T data)
Retrieves a Manager if it has been previously created or creates a new Manager.
|
String |
getName()
Returns the name of the Manager.
|
protected StrSubstitutor |
getStrSubstitutor()
Gets my configuration's StrSubstitutor or null.
|
static boolean |
hasManager(String name)
Determines if a Manager with the specified name exists.
|
protected void |
log(Level level,
String message,
Throwable throwable) |
protected void |
logDebug(String message,
Throwable throwable) |
protected void |
logError(String message,
Throwable throwable) |
protected static StatusLogger |
logger() |
protected void |
logWarn(String message,
Throwable throwable) |
protected static <M extends AbstractManager> |
narrow(Class<M> narrowClass,
AbstractManager manager)
Returns the specified manager, cast to the specified narrow type.
|
void |
release()
Deprecated.
In 2.7, use
close() . |
protected boolean |
releaseSub(long timeout,
TimeUnit timeUnit)
May be overridden by managers to perform processing while the manager is being released and the
lock is held.
|
boolean |
stop(long timeout,
TimeUnit timeUnit) |
void |
updateData(Object data)
Used by Log4j to update the Manager during reconfiguration.
|
protected static final Logger LOGGER
protected int count
protected AbstractManager(LoggerContext loggerContext, String name)
public void close()
close
in interface AutoCloseable
public boolean stop(long timeout, TimeUnit timeUnit)
public static <M extends AbstractManager,T> M getManager(String name, ManagerFactory<M,T> factory, T data)
M
- The Type of the Manager to be created.T
- The type of the Factory data.name
- The name of the Manager to retrieve.factory
- The Factory to use to create the Manager.data
- An Object that should be passed to the factory when creating the Manager.public void updateData(Object data)
data
- The data to update.public static boolean hasManager(String name)
name
- The name of the Manager.protected static <M extends AbstractManager> M narrow(Class<M> narrowClass, AbstractManager manager)
M
- the narrow typenarrowClass
- the type to cast tomanager
- the manager object to returnConfigurationException
- if the manager cannot be cast to the specified type, which only happens when
the configuration has multiple incompatible appenders pointing to the same resourceprotected static StatusLogger logger()
protected boolean releaseSub(long timeout, TimeUnit timeUnit)
timeout
- timeouttimeUnit
- timeout time unitprotected int getCount()
public LoggerContext getLoggerContext()
@Deprecated public void release()
close()
.public String getName()
public Map<String,String> getContentFormat()
protected StrSubstitutor getStrSubstitutor()
Copyright © 1999-2023 The Apache Software Foundation. All Rights Reserved.
Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather logo, the Apache Logging project logo, and the Apache Log4j logo are trademarks of The Apache Software Foundation.