logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r1156959 - in /logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/flume: FlumeAvroAppender.java FlumeAvroManager.java
Date Fri, 12 Aug 2011 04:00:47 GMT
Author: rgoers
Date: Fri Aug 12 04:00:47 2011
New Revision: 1156959

URL: http://svn.apache.org/viewvc?rev=1156959&view=rev
Log:
Have the appender keep the delay and retry count

Modified:
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/flume/FlumeAvroAppender.java
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/flume/FlumeAvroManager.java

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/flume/FlumeAvroAppender.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/flume/FlumeAvroAppender.java?rev=1156959&r1=1156958&r2=1156959&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/flume/FlumeAvroAppender.java
(original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/flume/FlumeAvroAppender.java
Fri Aug 12 04:00:47 2011
@@ -48,9 +48,13 @@ public class FlumeAvroAppender extends A
 
     private final String hostname;
 
+    private final int reconnectDelay;
+
+    private final int retries;
+
     private FlumeAvroAppender(String name, Filters filters, Layout layout, boolean handleException,
                               String hostname, String includes, String excludes, String required,
String mdcPrefix,
-                              String eventPrefix, boolean compress, FlumeAvroManager manager)
{
+                              String eventPrefix, boolean compress, int delay, int retries,
FlumeAvroManager manager) {
         super(name, filters, layout, handleException);
         this.manager = manager;
         this.mdcIncludes = includes;
@@ -60,6 +64,8 @@ public class FlumeAvroAppender extends A
         this.mdcPrefix = mdcPrefix;
         this.compressBody = compress;
         this.hostname = hostname;
+        this.reconnectDelay = delay;
+        this.retries = retries;
     }
 
     public void append(LogEvent event) {
@@ -67,7 +73,7 @@ public class FlumeAvroAppender extends A
         FlumeEvent flumeEvent = new FlumeEvent(event, hostname, mdcIncludes, mdcExcludes,
mdcRequired, mdcPrefix,
             eventPrefix, compressBody);
         flumeEvent.setBody(getLayout().format(flumeEvent));
-        manager.send(flumeEvent);
+        manager.send(flumeEvent, reconnectDelay, retries);
     }
 
     @Override
@@ -119,11 +125,11 @@ public class FlumeAvroAppender extends A
             return null;
         }
 
-        FlumeAvroManager manager = FlumeAvroManager.getManager(agents, reconnectDelay, retries);
+        FlumeAvroManager manager = FlumeAvroManager.getManager(agents);
         if (manager == null) {
             return null;
         }
         return new FlumeAvroAppender(name, filters, layout,  handleExceptions, hostname,
includes,
-            excludes, required, mdcPrefix, eventPrefix, compress, manager);
+            excludes, required, mdcPrefix, eventPrefix, compress, reconnectDelay, retries,
manager);
     }
 }

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/flume/FlumeAvroManager.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/flume/FlumeAvroManager.java?rev=1156959&r1=1156958&r2=1156959&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/flume/FlumeAvroManager.java
(original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/flume/FlumeAvroManager.java
Fri Aug 12 04:00:47 2011
@@ -37,14 +37,10 @@ import java.net.URL;
  */
 public class FlumeAvroManager extends AbstractManager {
 
-    private final int reconnectionDelay;
-
     private FlumeEventAvroServer client;
 
     private final Agent[] agents;
 
-    private final int retries;
-
     private static final int DEFAULT_RECONNECTS = 3;
 
     private int current = 0;
@@ -58,16 +54,11 @@ public class FlumeAvroManager extends Ab
 
     private static Logger logger = StatusLogger.getLogger();
 
-    public static FlumeAvroManager getManager(Agent[] agents, int delay, int retries) {
+    public static FlumeAvroManager getManager(Agent[] agents) {
         if (agents == null || agents.length == 0) {
             throw new IllegalArgumentException("At least one agent is required");
         }
-        if (delay == 0) {
-            delay = DEFAULT_RECONNECTION_DELAY;
-        }
-        if (retries == 0) {
-            retries = DEFAULT_RECONNECTS;
-        }
+
         StringBuilder sb = new StringBuilder("FlumeAvro[");
         boolean first = true;
         for (Agent agent : agents) {
@@ -78,19 +69,23 @@ public class FlumeAvroManager extends Ab
             first = false;
         }
         sb.append("]");
-        return (FlumeAvroManager) getManager(sb.toString(), factory, new FactoryData(agents,
delay, retries));
+        return (FlumeAvroManager) getManager(sb.toString(), factory, new FactoryData(agents));
     }
 
 
-    public FlumeAvroManager(String name, Agent[] agents, int delay, int retries) {
+    public FlumeAvroManager(String name, Agent[] agents) {
         super(name);
         this.agents = agents;
         this.client = connect(agents);
-        this.reconnectionDelay = delay;
-        this.retries = retries;
     }
 
-    protected synchronized void send(FlumeEvent event)  {
+    protected synchronized void send(FlumeEvent event, int delay, int retries)  {
+        if (delay == 0) {
+            delay = DEFAULT_RECONNECTION_DELAY;
+        }
+        if (retries == 0) {
+            retries = DEFAULT_RECONNECTS;
+        }
         AvroFlumeEvent avroEvent = AvroEventConvertUtil.toAvroEvent(event);
         int i = 0;
 
@@ -106,7 +101,7 @@ public class FlumeAvroManager extends Ab
                     logger.warn(msg, ex);
                     break;
                 }
-                sleep();
+                sleep(delay);
             }
         } while (++i < retries);
 
@@ -131,7 +126,7 @@ public class FlumeAvroManager extends Ab
                         logger.warn(warnMsg, ex);
                         break;
                     }
-                    sleep();
+                    sleep(delay);
                 }
             } while (++i < retries);
         }
@@ -140,9 +135,9 @@ public class FlumeAvroManager extends Ab
 
     }
 
-    private void sleep() {
+    private void sleep(int delay) {
         try {
-            Thread.sleep(reconnectionDelay);
+            Thread.sleep(delay);
         } catch (InterruptedException ex) {
             Thread.currentThread().interrupt();
         }
@@ -189,13 +184,9 @@ public class FlumeAvroManager extends Ab
 
     private static class FactoryData {
         Agent[] agents;
-        int delay;
-        int retries;
 
-        public FactoryData(Agent[] agents, int delay, int retries) {
+        public FactoryData(Agent[] agents) {
             this.agents = agents;
-            this.delay = delay;
-            this.retries = retries;
         }
     }
 
@@ -204,7 +195,7 @@ public class FlumeAvroManager extends Ab
         public FlumeAvroManager createManager(String name, FactoryData data) {
             try {
 
-                return new FlumeAvroManager(name, data.agents, data.delay, data.retries);
+                return new FlumeAvroManager(name, data.agents);
             } catch (Exception ex) {
                 logger.error("Could not create FlumeAvroManager", ex);
             }



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


Mime
View raw message