Class MemoryMappedFileManager
java.lang.Object
org.apache.logging.log4j.core.appender.AbstractManager
org.apache.logging.log4j.core.appender.OutputStreamManager
org.apache.logging.log4j.core.appender.MemoryMappedFileManager
- All Implemented Interfaces:
AutoCloseable,ByteBufferDestination
Extends OutputStreamManager but instead of using a buffered output stream, this class maps a region of a file into
memory and writes to this memory region.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.logging.log4j.core.appender.AbstractManager
AbstractManager.AbstractFactoryData -
Field Summary
Fields inherited from class org.apache.logging.log4j.core.appender.OutputStreamManager
byteBuffer, layoutFields inherited from class org.apache.logging.log4j.core.appender.AbstractManager
count, LOGGER -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedMemoryMappedFileManager(RandomAccessFile file, String fileName, OutputStream os, boolean immediateFlush, long position, int regionLength, String advertiseURI, Layout<? extends Serializable> layout, boolean writeHeader) -
Method Summary
Modifier and TypeMethodDescriptionbooleandrain(ByteBuffer buf) Drains the ByteBufferDestination's buffer into the destination.voidflush()Flushes any buffers.protected voidflushBuffer(ByteBuffer buffer) Drains the ByteBufferDestination's buffer into the destination.Returns thisByteBufferDestination's buffer.Gets this FileManager's content format specified by:static MemoryMappedFileManagergetFileManager(String fileName, boolean append, boolean immediateFlush, int regionLength, String advertiseURI, Layout<? extends Serializable> layout) Returns the MemoryMappedFileManager.Returns the name of the File being managed.intReturns the length of the memory mapped region.Deprecated.end-of-batch on the event is used instead.booleanReturnstrueif the content of the buffer should be forced to the storage device on every write,falseotherwise.static MappedByteBuffermmap(FileChannel fileChannel, String fileName, long start, int size) voidsetEndOfBatch(boolean endOfBatch) Deprecated.end-of-batch on the event is used instead.protected voidwrite(byte[] bytes, int offset, int length, boolean immediateFlush) Some output streams synchronize writes while others do not.Methods inherited from class org.apache.logging.log4j.core.appender.OutputStreamManager
createOutputStream, flushDestination, getManager, getOutputStream, hasOutputStream, isOpen, releaseSub, setOutputStream, skipFooter, write, write, write, writeBytes, writeBytes, writeFooter, writeHeader, writeToDestinationMethods inherited from class org.apache.logging.log4j.core.appender.AbstractManager
close, getCount, getLoggerContext, getManager, getName, getStrSubstitutor, hasManager, log, logDebug, logError, logger, logWarn, narrow, release, stop, updateData
-
Constructor Details
-
MemoryMappedFileManager
protected MemoryMappedFileManager(RandomAccessFile file, String fileName, OutputStream os, boolean immediateFlush, long position, int regionLength, String advertiseURI, Layout<? extends Serializable> layout, boolean writeHeader) throws IOException - Throws:
IOException
-
-
Method Details
-
getFileManager
public static MemoryMappedFileManager getFileManager(String fileName, boolean append, boolean immediateFlush, int regionLength, String advertiseURI, Layout<? extends Serializable> layout) Returns the MemoryMappedFileManager.- Parameters:
fileName- The name of the file to manage.append- true if the file should be appended to, false if it should be overwritten.immediateFlush- true if the contents should be flushed to disk on every writeregionLength- The mapped region length.advertiseURI- the URI to use when advertising the filelayout- The layout.- Returns:
- A MemoryMappedFileManager for the File.
-
isEndOfBatch
Deprecated.end-of-batch on the event is used instead.No longer used, theLogEvent.isEndOfBatch()attribute is used instead.- Returns:
Boolean.FALSE.
-
setEndOfBatch
Deprecated.end-of-batch on the event is used instead.No longer used, theLogEvent.isEndOfBatch()attribute is used instead. This method is a no-op. -
write
protected void write(byte[] bytes, int offset, int length, boolean immediateFlush) Description copied from class:OutputStreamManagerSome output streams synchronize writes while others do not. Synchronizing here insures that log events won't be intertwined.- Overrides:
writein classOutputStreamManager- Parameters:
bytes- The serialized Log event.offset- The offset into the byte array.length- The number of bytes to write.immediateFlush- flushes immediately after writing.
-
flush
public void flush()Description copied from class:OutputStreamManagerFlushes any buffers.- Overrides:
flushin classOutputStreamManager
-
closeOutputStream
public boolean closeOutputStream()- Overrides:
closeOutputStreamin classOutputStreamManager
-
mmap
public static MappedByteBuffer mmap(FileChannel fileChannel, String fileName, long start, int size) throws IOException - Throws:
IOException
-
getFileName
Returns the name of the File being managed.- Returns:
- The name of the File being managed.
-
getRegionLength
public int getRegionLength()Returns the length of the memory mapped region.- Returns:
- the length of the mapped region
-
isImmediateFlush
public boolean isImmediateFlush()Returnstrueif the content of the buffer should be forced to the storage device on every write,falseotherwise.- Returns:
- whether each write should be force-sync'ed
-
getContentFormat
Gets this FileManager's content format specified by:Key: "fileURI" Value: provided "advertiseURI" param.
- Overrides:
getContentFormatin classAbstractManager- Returns:
- Map of content format keys supporting FileManager
-
flushBuffer
Description copied from class:OutputStreamManagerDrains the ByteBufferDestination's buffer into the destination. By default this callsOutputStreamManager.write(byte[], int, int, boolean)with the buffer contents. The underlying stream is not flushed.- Overrides:
flushBufferin classOutputStreamManager- See Also:
-
getByteBuffer
Description copied from class:OutputStreamManagerReturns thisByteBufferDestination's buffer.- Specified by:
getByteBufferin interfaceByteBufferDestination- Overrides:
getByteBufferin classOutputStreamManager- Returns:
- the buffer
-
drain
Description copied from class:OutputStreamManagerDrains the ByteBufferDestination's buffer into the destination. By default this callsOutputStreamManager.flushBuffer(ByteBuffer)with the specified buffer. Subclasses may override.Do not call this method lightly! For some subclasses this is a very expensive operation. For example,
MemoryMappedFileManagerwill assume this method was called because the end of the mapped region was reached during a text encoding operation and will remap its buffer.To just flush the buffered contents to the underlying stream, call
OutputStreamManager.flushBuffer(ByteBuffer)directly instead.- Specified by:
drainin interfaceByteBufferDestination- Overrides:
drainin classOutputStreamManager- Parameters:
buf- the buffer whose contents to write the destination- Returns:
- the specified buffer
-