You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by mi...@apache.org on 2016/03/22 12:55:36 UTC

[12/41] logging-log4j2 git commit: LOG4J2-1080 AsyncLoggerConfig now always tries to enqueue log events; if this fails because the queue is full, then fall back to asking AsyncEventRouter what to do with the event

LOG4J2-1080 AsyncLoggerConfig now always tries to enqueue log events; if this fails because the queue is full, then fall back to asking AsyncEventRouter what to do with the event


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

Branch: refs/heads/gelf-layout-gc-free
Commit: 7a7f5e4ed1ce8a27357a12a06d32ca2b04e5eb56
Parents: 76067f2
Author: rpopma <rp...@apache.org>
Authored: Tue Mar 15 02:01:34 2016 +1100
Committer: rpopma <rp...@apache.org>
Committed: Tue Mar 15 02:01:34 2016 +1100

----------------------------------------------------------------------
 .../logging/log4j/core/async/AsyncLoggerConfig.java       |  6 ++++--
 .../log4j/core/async/AsyncLoggerConfigDelegate.java       |  2 ++
 .../log4j/core/async/AsyncLoggerConfigDisruptor.java      | 10 ++++++++--
 3 files changed, 14 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a7f5e4e/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfig.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfig.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfig.java
index 24d0086..f1c6800 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfig.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfig.java
@@ -88,8 +88,10 @@ public class AsyncLoggerConfig extends LoggerConfig {
     protected void callAppenders(final LogEvent event) {
         populateLazilyInitializedFields(event);
 
-        final EventRoute eventRoute = delegate.getEventRoute(event.getLevel());
-        eventRoute.logMessage(this, event);
+        if (!delegate.tryEnqueue(event, this)) {
+            final EventRoute eventRoute = delegate.getEventRoute(event.getLevel());
+            eventRoute.logMessage(this, event);
+        }
     }
 
     private void populateLazilyInitializedFields(final LogEvent event) {

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a7f5e4e/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigDelegate.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigDelegate.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigDelegate.java
index e49a004..5cbe0e4 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigDelegate.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigDelegate.java
@@ -46,4 +46,6 @@ public interface AsyncLoggerConfigDelegate {
     EventRoute getEventRoute(final Level level);
 
     void enqueueEvent(LogEvent event, AsyncLoggerConfig asyncLoggerConfig);
+
+    boolean tryEnqueue(LogEvent event, AsyncLoggerConfig asyncLoggerConfig);
 }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a7f5e4e/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigDisruptor.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigDisruptor.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigDisruptor.java
index 20e025c..20abda8 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigDisruptor.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigDisruptor.java
@@ -162,7 +162,7 @@ public class AsyncLoggerConfigDisruptor implements AsyncLoggerConfigDelegate {
         final WaitStrategy waitStrategy = DisruptorUtil.createWaitStrategy("AsyncLoggerConfig.WaitStrategy");
         executor = Executors.newSingleThreadExecutor(THREAD_FACTORY);
         backgroundThreadId = DisruptorUtil.getExecutorThreadId(executor);
-        asyncEventRouter = AsyncEventRouterFactory.create(ringBufferSize);
+        asyncEventRouter = AsyncEventRouterFactory.create();
 
         disruptor = new Disruptor<>(FACTORY, ringBufferSize, executor, ProducerType.MULTI, waitStrategy);
 
@@ -229,7 +229,7 @@ public class AsyncLoggerConfigDisruptor implements AsyncLoggerConfigDelegate {
         if (remainingCapacity < 0) {
             return EventRoute.DISCARD;
         }
-        return asyncEventRouter.getRoute(backgroundThreadId, logLevel, ringBufferSize, remainingCapacity);
+        return asyncEventRouter.getRoute(backgroundThreadId, logLevel);
     }
 
     private int remainingDisruptorCapacity() {
@@ -278,6 +278,12 @@ public class AsyncLoggerConfigDisruptor implements AsyncLoggerConfigDelegate {
         disruptor.getRingBuffer().publishEvent(TRANSLATOR, logEvent, asyncLoggerConfig);
     }
 
+    @Override
+    public boolean tryEnqueue(final LogEvent event, final AsyncLoggerConfig asyncLoggerConfig) {
+        final LogEvent logEvent = prepareEvent(event);
+        return disruptor.getRingBuffer().tryPublishEvent(TRANSLATOR, logEvent, asyncLoggerConfig);
+    }
+
     private LogEvent ensureImmutable(final LogEvent event) {
         LogEvent result = event;
         if (event instanceof RingBufferLogEvent) {