You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rp...@apache.org on 2016/04/11 19:53:36 UTC

[09/11] logging-log4j2 git commit: LOG4J2-1343 MemoryMappedFileManager: simplified by leveraging superclass logic

LOG4J2-1343 MemoryMappedFileManager: simplified by leveraging superclass logic


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/382dc410
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/382dc410
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/382dc410

Branch: refs/heads/LOG4J2-1343-no-gc-os-appenders-bytebuffered
Commit: 382dc4106fd8b4f3285a1de3d369551faa1ec97e
Parents: 294fe58
Author: rpopma <rp...@apache.org>
Authored: Tue Apr 12 02:42:52 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Tue Apr 12 02:42:52 2016 +0900

----------------------------------------------------------------------
 .../core/appender/MemoryMappedFileManager.java  | 35 +++-----------------
 1 file changed, 5 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/382dc410/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/MemoryMappedFileManager.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/MemoryMappedFileManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/MemoryMappedFileManager.java
index dc9fc88..336b9ee 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/MemoryMappedFileManager.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/MemoryMappedFileManager.java
@@ -76,13 +76,14 @@ public class MemoryMappedFileManager extends OutputStreamManager implements Byte
     protected MemoryMappedFileManager(final RandomAccessFile file, final String fileName, final OutputStream os,
             final boolean force, final long position, final int regionLength, final String advertiseURI,
             final Layout<? extends Serializable> layout, final boolean writeHeader) throws IOException {
-        super(os, fileName, layout, writeHeader);
+        super(os, fileName, layout, writeHeader, ByteBuffer.wrap(new byte[0]));
         this.isForce = force;
         this.randomAccessFile = Objects.requireNonNull(file, "RandomAccessFile");
         this.regionLength = regionLength;
         this.advertiseURI = advertiseURI;
         this.isEndOfBatch.set(Boolean.FALSE);
         this.mappedBuffer = mmap(randomAccessFile.getChannel(), getFileName(), position, regionLength);
+        this.byteBuffer = mappedBuffer;
         this.mappingOffset = position;
     }
 
@@ -113,24 +114,7 @@ public class MemoryMappedFileManager extends OutputStreamManager implements Byte
     }
 
     @Override
-    protected void write(final byte[] bytes) {
-        write(bytes, 0, bytes.length, false);
-    }
-
-    @Override
-    protected void write(final byte[] bytes, final boolean immediateFlush) {
-        write(bytes, 0, bytes.length, immediateFlush);
-    }
-
-    @Override
-    protected void write(final byte[] bytes, final int offset, final int length) {
-        write(bytes, 0, bytes.length, false);
-    }
-
-    @Override
     protected synchronized void write(final byte[] bytes, int offset, int length, final boolean immediateFlush) {
-        super.write(bytes, offset, length, immediateFlush); // writes to dummy output stream
-
         while (length > mappedBuffer.remaining()) {
             final int chunk = mappedBuffer.remaining();
             mappedBuffer.put(bytes, offset, chunk);
@@ -160,6 +144,7 @@ public class MemoryMappedFileManager extends OutputStreamManager implements Byte
                     millis);
 
             mappedBuffer = mmap(randomAccessFile.getChannel(), getFileName(), offset, length);
+            this.byteBuffer = mappedBuffer;
             mappingOffset = offset;
         } catch (final Exception ex) {
             logError("unable to remap", ex);
@@ -284,19 +269,9 @@ public class MemoryMappedFileManager extends OutputStreamManager implements Byte
         return result;
     }
 
-    /**
-     * Returns this {@code MemoryMappedFileManager}.
-     * @param immediateFlush ignored
-     * @return this {@code MemoryMappedFileManager}
-     */
-    @Override
-    protected ByteBufferDestination createByteBufferDestination(final boolean immediateFlush) {
-        return this;
-    }
-
     @Override
-    protected void flushBuffer() {
-        // do nothing (avoid spurious calls to remap())
+    protected void flushBuffer(final ByteBuffer buffer) {
+        // do nothing (do not call drain() to avoid spurious remapping)
     }
 
     @Override