logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From psm...@apache.org
Subject svn commit: r691872 - in /logging/log4j/companions/receivers/trunk: pom.xml src/changes/changes.xml src/main/java/org/apache/log4j/net/SocketHubReceiver.java src/main/java/org/apache/log4j/net/SocketNode13.java
Date Thu, 04 Sep 2008 04:57:12 GMT
Author: psmith
Date: Wed Sep  3 21:57:11 2008
New Revision: 691872

URL: http://svn.apache.org/viewvc?rev=691872&view=rev
Log:
Bug 42171 Applied patch supplied by ray@ that resolves a bug where by duplicate events are
received
after a SocketHubReceiver is shutdown and then restartedi such as when used under Chainsaw.


Modified:
    logging/log4j/companions/receivers/trunk/pom.xml
    logging/log4j/companions/receivers/trunk/src/changes/changes.xml
    logging/log4j/companions/receivers/trunk/src/main/java/org/apache/log4j/net/SocketHubReceiver.java
    logging/log4j/companions/receivers/trunk/src/main/java/org/apache/log4j/net/SocketNode13.java

Modified: logging/log4j/companions/receivers/trunk/pom.xml
URL: http://svn.apache.org/viewvc/logging/log4j/companions/receivers/trunk/pom.xml?rev=691872&r1=691871&r2=691872&view=diff
==============================================================================
--- logging/log4j/companions/receivers/trunk/pom.xml (original)
+++ logging/log4j/companions/receivers/trunk/pom.xml Wed Sep  3 21:57:11 2008
@@ -216,7 +216,7 @@
     <dependency>
       <groupId>log4j</groupId>
       <artifactId>log4j</artifactId>
-      <version>1.2.15</version>
+      <version>1.2.16-SNAPSHOT</version>
     </dependency>    
     <dependency>
       <groupId>log4j</groupId>

Modified: logging/log4j/companions/receivers/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4j/companions/receivers/trunk/src/changes/changes.xml?rev=691872&r1=691871&r2=691872&view=diff
==============================================================================
--- logging/log4j/companions/receivers/trunk/src/changes/changes.xml (original)
+++ logging/log4j/companions/receivers/trunk/src/changes/changes.xml Wed Sep  3 21:57:11 2008
@@ -24,6 +24,7 @@
       <action issue="42102" type="add">
         Initial release of receivers companion backported from log4j 1.3.
       </action>
+      <action issue="42171" type="fix">SocketHubReceiver duplicates messages</action>
     </release>
   </body>
 </document>

Modified: logging/log4j/companions/receivers/trunk/src/main/java/org/apache/log4j/net/SocketHubReceiver.java
URL: http://svn.apache.org/viewvc/logging/log4j/companions/receivers/trunk/src/main/java/org/apache/log4j/net/SocketHubReceiver.java?rev=691872&r1=691871&r2=691872&view=diff
==============================================================================
--- logging/log4j/companions/receivers/trunk/src/main/java/org/apache/log4j/net/SocketHubReceiver.java
(original)
+++ logging/log4j/companions/receivers/trunk/src/main/java/org/apache/log4j/net/SocketHubReceiver.java
Wed Sep  3 21:57:11 2008
@@ -76,7 +76,7 @@
     /**
      * Socket.
      */
-  protected Socket socket;
+  protected SocketNode13 socketNode;
 
     /**
      * Listener list.
@@ -255,13 +255,14 @@
 
     // close the socket
     try {
-      if (socket != null) {
-        socket.close();
+      if (socketNode != null) {
+        socketNode.close();
+        socketNode = null;
       }
     } catch (Exception e) {
+      getLogger().info("Excpetion closing socket", e);
       // ignore for now
     }
-    socket = null;
 
     // stop the connector
     if (connector != null) {
@@ -276,11 +277,14 @@
    @param e exception not used.
    */
   public void socketClosedEvent(final Exception e) {
+    // if it is a non-normal closed event
     // we clear the connector object here
     // so that it actually does reconnect if the
     // remote socket dies.
-    connector = null;
-    fireConnector(true);
+    if (e != null) {
+      connector = null;
+      fireConnector(true);
+    }
   }
 
     /**
@@ -303,18 +307,17 @@
      */
   private synchronized void setSocket(final Socket newSocket) {
     connector = null;
-    socket = newSocket;
-    SocketNode13 node = new SocketNode13(socket, this);
-    node.addSocketNodeEventListener(this);
+    socketNode = new SocketNode13(newSocket, this);
+    socketNode.addSocketNodeEventListener(this);
 
     synchronized (listenerList) {
         for (Iterator iter = listenerList.iterator(); iter.hasNext();) {
             SocketNodeEventListener listener =
                     (SocketNodeEventListener) iter.next();
-            node.addSocketNodeEventListener(listener);
+            socketNode.addSocketNodeEventListener(listener);
         }
     }
-    new Thread(node).start();
+    new Thread(socketNode).start();
   }
 
   /**

Modified: logging/log4j/companions/receivers/trunk/src/main/java/org/apache/log4j/net/SocketNode13.java
URL: http://svn.apache.org/viewvc/logging/log4j/companions/receivers/trunk/src/main/java/org/apache/log4j/net/SocketNode13.java?rev=691872&r1=691871&r2=691872&view=diff
==============================================================================
--- logging/log4j/companions/receivers/trunk/src/main/java/org/apache/log4j/net/SocketNode13.java
(original)
+++ logging/log4j/companions/receivers/trunk/src/main/java/org/apache/log4j/net/SocketNode13.java
Wed Sep  3 21:57:11 2008
@@ -61,6 +61,10 @@
      */
   private boolean paused;
     /**
+     * Closed state.
+     */
+  private boolean closed;
+    /**
      * Socket.
      */
   private Socket socket;
@@ -165,7 +169,7 @@
       fireSocketOpened(remoteInfo);
 
       try {
-        while (true) {
+        while (!isClosed()) {
           // read an event from the wire
           event = (LoggingEvent) ois.readObject();
           event.setProperty(Constants.HOSTNAME_KEY, hostName);
@@ -173,7 +177,7 @@
           event.setProperty("log4j.remoteSourceInfo", remoteInfo);
 
           // if configured with a receiver, tell it to post the event
-          if (!isPaused()) {
+          if (!isPaused() && !isClosed()) {
             if ((receiver != null)) {
               receiver.doPost(event);
 
@@ -222,7 +226,7 @@
     }
 
     // send event to listener, if configured
-    if (listenerList.size() > 0) {
+    if (listenerList.size() > 0 && !isClosed()) {
       fireSocketClosedEvent(listenerException);
     }
   }
@@ -274,4 +278,22 @@
   public boolean isPaused() {
     return this.paused;
   }
+
+    /**
+     * Close the node and underlying socket
+     */
+  public void close() throws IOException {
+    getLogger().debug("closing socket");
+    this.closed = true;
+    socket.close();
+    fireSocketClosedEvent(null);
+  }
+  
+    /**
+     * Get if node is closed.
+     * @return true if closed.
+     */
+  public boolean isClosed() {
+    return this.closed;
+  }
 }



---------------------------------------------------------------------
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