org.apache.logging.log4j.core.appender.db
Class AbstractDatabaseManager

java.lang.Object
  extended by org.apache.logging.log4j.core.appender.AbstractManager
      extended by org.apache.logging.log4j.core.appender.db.AbstractDatabaseManager
Direct Known Subclasses:
JDBCDatabaseManager, JPADatabaseManager, NoSQLDatabaseManager

public abstract class AbstractDatabaseManager
extends AbstractManager

Manager that allows database appenders to have their configuration reloaded without losing events.


Nested Class Summary
protected static class AbstractDatabaseManager.AbstractFactoryData
          Implementations should extend this class for passing data between the getManager method and the manager factory class.
 
Field Summary
 
Fields inherited from class org.apache.logging.log4j.core.appender.AbstractManager
count, LOGGER
 
Constructor Summary
protected AbstractDatabaseManager(String name, int bufferSize)
          Instantiates the base manager.
 
Method Summary
 void connect()
          This method is called within the appender when the appender is started.
protected abstract  void connectInternal()
          Implementations should implement this method to perform any proprietary connection operations.
 void disconnect()
          This method is called from the AbstractManager.release() method when the appender is stopped or the appender's manager is replaced.
protected abstract  void disconnectInternal()
          Implementations should implement this method to perform any proprietary disconnection / shutdown operations.
 void flush()
          This method is called automatically when the buffer size reaches its maximum or at the beginning of a call to disconnect().
protected static
<M extends AbstractDatabaseManager,T extends AbstractDatabaseManager.AbstractFactoryData>
M
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.
 boolean isConnected()
          Indicates whether the manager is currently connected connect() has been called and disconnect() has not been called).
 void releaseSub()
          May be overridden by Managers to perform processing while the Manager is being released and the lock is held.
 String toString()
           
 void write(LogEvent event)
          This method manages buffering and writing of events.
protected abstract  void writeInternal(LogEvent event)
          Performs the actual writing of the event in an implementation-specific way.
 
Methods inherited from class org.apache.logging.log4j.core.appender.AbstractManager
getContentFormat, getCount, getName, hasManager, release
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractDatabaseManager

protected AbstractDatabaseManager(String name,
                                  int bufferSize)
Instantiates the base manager.

Parameters:
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.
Method Detail

connectInternal

protected abstract void connectInternal()
                                 throws Exception
Implementations should implement this method to perform any proprietary connection operations. This method will never be called twice on the same instance. It is safe to throw any exceptions from this method.

Throws:
Exception

connect

public final void connect()
This method is called within the appender when the appender is started. If it has not already been called, it calls connectInternal() and catches any exceptions it might throw.


disconnectInternal

protected abstract void disconnectInternal()
                                    throws Exception
Implementations should implement this method to perform any proprietary disconnection / shutdown operations. This method will never be called twice on the same instance, and it will only be called after connectInternal(). It is safe to throw any exceptions from this method.

Throws:
Exception

disconnect

public final void disconnect()
This method is called from the AbstractManager.release() method when the appender is stopped or the appender's manager is replaced. If it has not already been called, it calls disconnectInternal() and catches any exceptions it might throw.


isConnected

public final boolean isConnected()
Indicates whether the manager is currently connected connect() has been called and disconnect() has not been called).

Returns:
true if the manager is connected.

writeInternal

protected abstract void writeInternal(LogEvent event)
Performs the actual writing of the event in an implementation-specific way. This method is called immediately from write(LogEvent) if buffering is off, or from flush() if the buffer has reached its limit.

Parameters:
event - The event to write to the database.

flush

public final void flush()
This method is called automatically when the buffer size reaches its maximum or at the beginning of a call to disconnect(). It can also be called manually to flush events to the database.


write

public final void write(LogEvent event)
This method manages buffering and writing of events.

Parameters:
event - The event to write to the database.

releaseSub

public final void releaseSub()
Description copied from class: AbstractManager
May be overridden by Managers to perform processing while the Manager is being released and the lock is held.

Overrides:
releaseSub in class AbstractManager

toString

public final String toString()
Overrides:
toString in class Object

getManager

protected static <M extends AbstractDatabaseManager,T extends AbstractDatabaseManager.AbstractFactoryData> M 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.

Type Parameters:
M - The concrete manager type.
T - The concrete AbstractDatabaseManager.AbstractFactoryData type.
Parameters:
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.
Returns:
a new or existing manager of the specified type and name.


Copyright © 1999-2013 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.