Class NoSqlDatabaseManager<W>
- java.lang.Object
-
- org.apache.logging.log4j.core.appender.AbstractManager
-
- org.apache.logging.log4j.core.appender.db.AbstractDatabaseManager
-
- org.apache.logging.log4j.core.appender.nosql.NoSqlDatabaseManager<W>
-
- Type Parameters:
W- A type parameter for reassuring the compiler that all operations are using the sameNoSqlObject.
- All Implemented Interfaces:
java.io.Flushable,java.lang.AutoCloseable
public final class NoSqlDatabaseManager<W> extends AbstractDatabaseManager
AnAbstractDatabaseManagerimplementation for all NoSQL databases.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classNoSqlDatabaseManager.FactoryDataEncapsulates data thatNoSqlDatabaseManager.NoSQLDatabaseManagerFactoryuses to create managers.private static classNoSqlDatabaseManager.NoSQLDatabaseManagerFactoryCreates managers.-
Nested classes/interfaces inherited from class org.apache.logging.log4j.core.appender.db.AbstractDatabaseManager
AbstractDatabaseManager.AbstractFactoryData
-
-
Field Summary
Fields Modifier and Type Field Description private KeyValuePair[]additionalFieldsprivate NoSqlConnection<W,? extends NoSqlObject<W>>connectionprivate static NoSqlDatabaseManager.NoSQLDatabaseManagerFactoryFACTORYprivate NoSqlProvider<NoSqlConnection<W,? extends NoSqlObject<W>>>provider-
Fields inherited from class org.apache.logging.log4j.core.appender.AbstractManager
count, LOGGER
-
-
Constructor Summary
Constructors Modifier Constructor Description privateNoSqlDatabaseManager(java.lang.String name, int bufferSize, NoSqlProvider<NoSqlConnection<W,? extends NoSqlObject<W>>> provider, KeyValuePair[] additionalFields, Configuration configuration)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description private NoSqlObject<W>buildMarkerEntity(Marker marker)protected booleancommitAndClose()Commits any active transaction (if applicable) and disconnects from the database (returns the connection to the connection pool).protected voidconnectAndStart()Connects to the database and starts a transaction (if applicable).private NoSqlObject<W>[]convertStackTrace(java.lang.StackTraceElement[] stackTrace)private NoSqlObject<W>convertStackTraceElement(java.lang.StackTraceElement element)static NoSqlDatabaseManager<?>getNoSqlDatabaseManager(java.lang.String name, int bufferSize, NoSqlProvider<?> provider)static NoSqlDatabaseManager<?>getNoSqlDatabaseManager(java.lang.String name, int bufferSize, NoSqlProvider<?> provider, KeyValuePair[] additionalFields, Configuration configuration)Creates a NoSQL manager for use within theNoSqlAppender, or returns a suitable one if it already exists.private voidsetAdditionalFields(NoSqlObject<W> entity)private voidsetFields(LogEvent event, NoSqlObject<W> entity)private voidsetFields(MapMessage<?,?> mapMessage, NoSqlObject<W> noSqlObject)protected booleanshutdownInternal()Implementations should implement this method to perform any proprietary disconnection / shutdown operations.protected voidstartupInternal()Implementations should implement this method to perform any proprietary startup operations.protected voidwriteInternal(LogEvent event, java.io.Serializable serializable)Performs the actual writing of the event in an implementation-specific way.-
Methods inherited from class org.apache.logging.log4j.core.appender.db.AbstractDatabaseManager
buffer, flush, getManager, isBuffered, isRunning, releaseSub, shutdown, startup, toString, write, write, writeInternal, writeThrough
-
Methods inherited from class org.apache.logging.log4j.core.appender.AbstractManager
close, getContentFormat, getCount, getLoggerContext, getManager, getName, getStrSubstitutor, hasManager, log, logDebug, logError, logger, logWarn, narrow, release, stop, updateData
-
-
-
-
Field Detail
-
FACTORY
private static final NoSqlDatabaseManager.NoSQLDatabaseManagerFactory FACTORY
-
provider
private final NoSqlProvider<NoSqlConnection<W,? extends NoSqlObject<W>>> provider
-
connection
private NoSqlConnection<W,? extends NoSqlObject<W>> connection
-
additionalFields
private final KeyValuePair[] additionalFields
-
-
Constructor Detail
-
NoSqlDatabaseManager
private NoSqlDatabaseManager(java.lang.String name, int bufferSize, NoSqlProvider<NoSqlConnection<W,? extends NoSqlObject<W>>> provider, KeyValuePair[] additionalFields, Configuration configuration)
-
-
Method Detail
-
getNoSqlDatabaseManager
@Deprecated public static NoSqlDatabaseManager<?> getNoSqlDatabaseManager(java.lang.String name, int bufferSize, NoSqlProvider<?> provider)
Creates a NoSQL manager for use within theNoSqlAppender, or returns a suitable one if it already exists.- Parameters:
name- The name of the manager, which should include connection details and hashed passwords where possible.bufferSize- The size of the log event buffer.provider- A provider instance which will be used to obtain connections to the chosen NoSQL database.- Returns:
- a new or existing NoSQL manager as applicable.
-
getNoSqlDatabaseManager
public static NoSqlDatabaseManager<?> getNoSqlDatabaseManager(java.lang.String name, int bufferSize, NoSqlProvider<?> provider, KeyValuePair[] additionalFields, Configuration configuration)
Creates a NoSQL manager for use within theNoSqlAppender, or returns a suitable one if it already exists.- Parameters:
name- The name of the manager, which should include connection details and hashed passwords where possible.bufferSize- The size of the log event buffer.provider- A provider instance which will be used to obtain connections to the chosen NoSQL database.additionalFields- Additional fields.configuration- TODO- Returns:
- a new or existing NoSQL manager as applicable.
-
buildMarkerEntity
private NoSqlObject<W> buildMarkerEntity(Marker marker)
-
commitAndClose
protected boolean commitAndClose()
Description copied from class:AbstractDatabaseManagerCommits any active transaction (if applicable) and disconnects from the database (returns the connection to the connection pool). With buffering enabled, this is called when flushing the buffer completes, after the last call toAbstractDatabaseManager.writeInternal(org.apache.logging.log4j.core.LogEvent). With buffering disabled, this is called immediately after every invocation ofAbstractDatabaseManager.writeInternal(org.apache.logging.log4j.core.LogEvent).- Specified by:
commitAndClosein classAbstractDatabaseManager- Returns:
- true if all resources were closed normally, false otherwise.
-
connectAndStart
protected void connectAndStart()
Description copied from class:AbstractDatabaseManagerConnects to the database and starts a transaction (if applicable). With buffering enabled, this is called when flushing the buffer begins, before the first call toAbstractDatabaseManager.writeInternal(org.apache.logging.log4j.core.LogEvent). With buffering disabled, this is called immediately before every invocation ofAbstractDatabaseManager.writeInternal(org.apache.logging.log4j.core.LogEvent).- Specified by:
connectAndStartin classAbstractDatabaseManager
-
convertStackTrace
private NoSqlObject<W>[] convertStackTrace(java.lang.StackTraceElement[] stackTrace)
-
convertStackTraceElement
private NoSqlObject<W> convertStackTraceElement(java.lang.StackTraceElement element)
-
setAdditionalFields
private void setAdditionalFields(NoSqlObject<W> entity)
-
setFields
private void setFields(LogEvent event, NoSqlObject<W> entity)
-
setFields
private void setFields(MapMessage<?,?> mapMessage, NoSqlObject<W> noSqlObject)
-
shutdownInternal
protected boolean shutdownInternal()
Description copied from class:AbstractDatabaseManagerImplementations 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 afterAbstractDatabaseManager.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 inAbstractDatabaseManager.startupInternal().- Specified by:
shutdownInternalin classAbstractDatabaseManager- Returns:
- true if all resources were closed normally, false otherwise.
-
startupInternal
protected void startupInternal()
Description copied from class:AbstractDatabaseManagerImplementations should implement this method to perform any proprietary startup operations. This method will never be called twice on the same instance. It is safe to throw any exceptions from this method. This method does not necessarily connect to the database, as it is generally unreliable to connect once and use the same connection for hours.- Specified by:
startupInternalin classAbstractDatabaseManager
-
writeInternal
protected void writeInternal(LogEvent event, java.io.Serializable serializable)
Description copied from class:AbstractDatabaseManagerPerforms the actual writing of the event in an implementation-specific way. This method is called immediately fromAbstractDatabaseManager.write(LogEvent, Serializable)if buffering is off, or fromAbstractDatabaseManager.flush()if the buffer has reached its limit.- Specified by:
writeInternalin classAbstractDatabaseManager- Parameters:
event- The event to write to the database.
-
-