logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sde...@apache.org
Subject svn commit: r986563 - /logging/log4j/trunk/src/main/java/org/apache/log4j/net/SocketHubAppender.java
Date Wed, 18 Aug 2010 04:38:48 GMT
Author: sdeboy
Date: Wed Aug 18 04:38:47 2010
New Revision: 986563

URL: http://svn.apache.org/viewvc?rev=986563&view=rev
Log:
Now closing SockeHubAppender's serverSocket if the appender is closed
Verified a reload of the same sockethubappender configuration is able to re-use the same socket
port, and sockethubreceiver successfully reconnects

Modified:
    logging/log4j/trunk/src/main/java/org/apache/log4j/net/SocketHubAppender.java

Modified: logging/log4j/trunk/src/main/java/org/apache/log4j/net/SocketHubAppender.java
URL: http://svn.apache.org/viewvc/logging/log4j/trunk/src/main/java/org/apache/log4j/net/SocketHubAppender.java?rev=986563&r1=986562&r2=986563&view=diff
==============================================================================
--- logging/log4j/trunk/src/main/java/org/apache/log4j/net/SocketHubAppender.java (original)
+++ logging/log4j/trunk/src/main/java/org/apache/log4j/net/SocketHubAppender.java Wed Aug
18 04:38:47 2010
@@ -124,9 +124,10 @@ public class SocketHubAppender extends A
    * The MulticastDNS zone advertised by a SocketHubAppender
    */
   public static final String ZONE = "_log4j_obj_tcpaccept_appender.local.";
+  private ServerSocket serverSocket;
 
 
-  public SocketHubAppender() { }
+    public SocketHubAppender() { }
 
   /**
      Connects to remote server at <code>address</code> and <code>port</code>.
*/
@@ -176,7 +177,7 @@ public class SocketHubAppender extends A
 	LogLog.debug("stopping ServerSocket");
     serverMonitor.stopMonitor();
     serverMonitor = null;
-    
+
     // close all of the connections
 	LogLog.debug("closing client connections");
     while (oosList.size() != 0) {
@@ -369,8 +370,7 @@ public class SocketHubAppender extends A
     This class is used internally to monitor a ServerSocket
     and register new connections in a vector passed in the
     constructor. */
-  private
-  class ServerMonitor implements Runnable {
+  private class ServerMonitor implements Runnable {
     private int port;
     private Vector oosList;
     private boolean keepRunning;
@@ -392,13 +392,18 @@ public class SocketHubAppender extends A
     /**
       Stops the monitor. This method will not return until
       the thread has finished executing. */
-    public
-    synchronized
-    void stopMonitor() {
+    public synchronized void stopMonitor() {
       if (keepRunning) {
     	LogLog.debug("server monitor thread shutting down");
         keepRunning = false;
         try {
+            if (serverSocket != null) {
+                serverSocket.close();
+                serverSocket = null;
+            }
+        } catch (IOException ioe) {}
+
+        try {
           monitorThread.join();
         }
         catch (InterruptedException e) {
@@ -428,7 +433,7 @@ public class SocketHubAppender extends A
       they connect to the socket. */
     public
     void run() {
-      ServerSocket serverSocket = null;
+      serverSocket = null;
       try {
         serverSocket = createServerSocket(port);
         serverSocket.setSoTimeout(1000);



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