Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.logging.log4j.core.appender
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

    public class MemoryMappedFileManager

extends OutputStreamManager

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.

Since:
  2.1
See Also:
  http://www.codeproject.com/Tips/683614/Things-to-Know-about-Memory-Mapped-File-in-Java, http://bugs.java.com/view_bug.do?bug_id=6893654, http://bugs.java.com/view_bug.do?bug_id=4724038, http://stackoverflow.com/questions/9261316/memory-mapped-mappedbytebuffer-or-direct-bytebuffer-for-db-implementation

Field Summary

Fields inherited from class org.apache.logging.log4j.core.appender.OutputStreamManager
`layout`

Fields inherited from class org.apache.logging.log4j.core.appender.AbstractManager
`count, LOGGER`

Constructor Summary
`protected` | `MemoryMappedFileManager(RandomAccessFile file, String fileName, OutputStream os, boolean force, long position, int regionLength, String advertiseURI, Layout<? extends Serializable> layout)`

Method Summary
`void` | `close()`
`void` | `flush()` Flushes any buffers.
`Map<String,String>` | `getContentFormat()` Gets this FileManager's content format specified by:
`static MemoryMappedFileManager` | `getFileManager(String fileName, boolean append, boolean isForce, int regionLength, String advertiseURI, Layout<? extends Serializable> layout)` Returns the MemoryMappedFileManager.
`String` | `getFileName()` Returns the name of the File being managed.
`int` | `getRegionLength()` Returns the length of the memory mapped region.
`Boolean` | `isEndOfBatch()`
`boolean` | `isImmediateFlush()` Returns `true` if the content of the buffer should be forced to the storage device on every write, `false` otherwise.
`static MappedByteBuffer` | `mmap(FileChannel fileChannel, String fileName, long start, int size)`
`void` | `setEndOfBatch(boolean isEndOfBatch)`
`protected void` | `write(byte[] bytes, int offset, int length)` Some output streams synchronize writes while others do not.

Methods inherited from class org.apache.logging.log4j.core.appender.OutputStreamManager
`getManager, getOutputStream, isOpen, releaseSub, setOutputStream, write, writeFooter`

Methods inherited from class org.apache.logging.log4j.core.appender.AbstractManager
`getCount, getName, hasManager, release`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### MemoryMappedFileManager

    protected MemoryMappedFileManager(RandomAccessFile file,
                                      String fileName,
                                      OutputStream os,
                                      boolean force,
                                      long position,
                                      int regionLength,
                                      String advertiseURI,
                                      Layout<? extends Serializable> layout)
                               throws IOException

Throws:
  `IOException`

Method Detail

### getFileManager

    public static MemoryMappedFileManager getFileManager(String fileName,
                                                         boolean append,
                                                         boolean isForce,
                                                         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.
    `isForce` - true if the contents should be flushed to disk on every write
    `regionLength` - The mapped region length.
    `advertiseURI` - the URI to use when advertising the file
    `layout` - The layout.
  Returns:
    A MemoryMappedFileManager for the File.

### isEndOfBatch

    public Boolean isEndOfBatch()

### setEndOfBatch

    public void setEndOfBatch(boolean isEndOfBatch)

### write

    protected void write(byte[] bytes,
                         int offset,
                         int length)

  Description copied from class: `OutputStreamManager`
  Some output streams synchronize writes while others do not. Synchronizing here insures that log events won't be intertwined.

  Overrides:
    `write` in class `OutputStreamManager`
  Parameters:
    `bytes` - The serialized Log event.
    `offset` - The offset into the byte array.
    `length` - The number of bytes to write.

### flush

    public void flush()

  Description copied from class: `OutputStreamManager`
  Flushes any buffers.

  Overrides:
    `flush` in class `OutputStreamManager`

### close

    public void close()

  Overrides:
    `close` in class `OutputStreamManager`

### mmap

    public static MappedByteBuffer mmap(FileChannel fileChannel,
                                        String fileName,
                                        long start,
                                        int size)
                                 throws IOException

  Throws:
    `IOException`

### getFileName

    public String 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()

  Returns `true` if the content of the buffer should be forced to the storage device on every write, `false` otherwise.

  Returns:
    whether each write should be force-sync'ed

### getContentFormat

    public Map<String,String> getContentFormat()

  Gets this FileManager's content format specified by:

  Key: "fileURI" Value: provided "advertiseURI" param.

  Overrides:
    `getContentFormat` in class `AbstractManager`
  Returns:
    Map of content format keys supporting FileManager

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

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