public abstract class AbstractDatabaseManager extends AbstractManager implements Flushable
Modifier and Type | Class and Description |
---|---|
protected static class |
AbstractDatabaseManager.AbstractFactoryData
Implementations should extend this class for passing data between the getManager method and the manager factory
class.
|
count, LOGGER
Modifier | Constructor and Description |
---|---|
protected |
AbstractDatabaseManager(String name,
int bufferSize)
Instantiates the base manager.
|
protected |
AbstractDatabaseManager(String name,
int bufferSize,
Layout<? extends Serializable> layout)
Instantiates the base manager.
|
Modifier and Type | Method and Description |
---|---|
protected void |
buffer(LogEvent event) |
protected abstract boolean |
commitAndClose()
Commits any active transaction (if applicable) and disconnects from the database (returns the connection to the
connection pool).
|
protected abstract void |
connectAndStart()
Connects to the database and starts a transaction (if applicable).
|
void |
flush()
This method is called automatically when the buffer size reaches its maximum or at the beginning of a call to
shutdown() . |
protected static <M extends AbstractDatabaseManager,T extends AbstractDatabaseManager.AbstractFactoryData> |
getManager(String name,
T data,
ManagerFactory<M,T> factory)
Implementations should define their own getManager method and call this method from that to create or get
existing managers.
|
protected boolean |
isBuffered() |
boolean |
isRunning()
Indicates whether the manager is currently connected
startup() has been called and shutdown()
has not been called). |
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 |
shutdown()
This method is called from the
AbstractManager.close() method when the appender is stopped or the appender's manager
is replaced. |
protected abstract boolean |
shutdownInternal()
Implementations should implement this method to perform any proprietary disconnection / shutdown operations.
|
void |
startup()
This method is called within the appender when the appender is started.
|
protected abstract void |
startupInternal()
Implementations should implement this method to perform any proprietary startup operations.
|
String |
toString() |
void |
write(LogEvent event)
Deprecated.
since 2.11.0 Use
write(LogEvent, Serializable) . |
void |
write(LogEvent event,
Serializable serializable)
This method manages buffering and writing of events.
|
protected void |
writeInternal(LogEvent event)
Deprecated.
|
protected abstract void |
writeInternal(LogEvent event,
Serializable serializable)
Performs the actual writing of the event in an implementation-specific way.
|
protected void |
writeThrough(LogEvent event,
Serializable serializable) |
close, getContentFormat, getCount, getLoggerContext, getName, hasManager, log, logDebug, logError, logger, logWarn, narrow, release, stop, updateData
protected AbstractDatabaseManager(String name, int bufferSize)
name
- The manager name, which should include any configuration details that one might want to be able to
reconfigure at runtime, such as database name, username, (hashed) password, etc.bufferSize
- The size of the log event buffer.protected AbstractDatabaseManager(String name, int bufferSize, Layout<? extends Serializable> layout)
name
- The manager name, which should include any configuration details that one might want to be able to
reconfigure at runtime, such as database name, username, (hashed) password, etc.layout
- the Appender-level layout.bufferSize
- The size of the log event buffer.protected static <M extends AbstractDatabaseManager,T extends AbstractDatabaseManager.AbstractFactoryData> M getManager(String name, T data, ManagerFactory<M,T> factory)
M
- The concrete manager type.T
- The concrete AbstractDatabaseManager.AbstractFactoryData
type.name
- The manager name, which should include any configuration details that one might want to be able to
reconfigure at runtime, such as database name, username, (hashed) password, etc.data
- The concrete instance of AbstractDatabaseManager.AbstractFactoryData
appropriate for the given manager.factory
- A factory instance for creating the appropriate manager.protected abstract boolean commitAndClose()
writeInternal(org.apache.logging.log4j.core.LogEvent)
. With buffering disabled, this is called immediately after every invocation of
writeInternal(org.apache.logging.log4j.core.LogEvent)
.protected abstract void connectAndStart()
writeInternal(org.apache.logging.log4j.core.LogEvent)
. With buffering disabled, this is
called immediately before every invocation of writeInternal(org.apache.logging.log4j.core.LogEvent)
.public final void flush()
shutdown()
. It can also be called manually to flush events to the database.protected boolean isBuffered()
public final boolean isRunning()
startup()
has been called and shutdown()
has not been called).true
if the manager is connected.public final boolean releaseSub(long timeout, TimeUnit timeUnit)
AbstractManager
releaseSub
in class AbstractManager
timeout
- timeouttimeUnit
- timeout time unitpublic final boolean shutdown()
AbstractManager.close()
method when the appender is stopped or the appender's manager
is replaced. If it has not already been called, it calls shutdownInternal()
and catches any exceptions
it might throw.protected abstract boolean shutdownInternal() throws Exception
startupInternal()
. It is safe to throw any exceptions from this method. This method does not
necessarily disconnect from the database for the same reasons outlined in startupInternal()
.Exception
public final void startup()
startupInternal()
and catches any exceptions it might throw.protected abstract void startupInternal() throws Exception
Exception
@Deprecated public final void write(LogEvent event)
write(LogEvent, Serializable)
.event
- The event to write to the database.public final void write(LogEvent event, Serializable serializable)
event
- The event to write to the database.serializable
- Serializable event@Deprecated protected void writeInternal(LogEvent event)
writeInternal(LogEvent, Serializable)
.write(LogEvent, Serializable)
if buffering is off, or from flush()
if the buffer has reached its limit.event
- The event to write to the database.protected abstract void writeInternal(LogEvent event, Serializable serializable)
write(LogEvent, Serializable)
if buffering is off, or from flush()
if the buffer has reached its limit.event
- The event to write to the database.protected void writeThrough(LogEvent event, Serializable serializable)
Copyright © 1999-2021 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.