logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1582057 - in /logging/log4j/log4j2/trunk: log4j-core/src/main/java/org/apache/logging/log4j/core/net/ log4j-core/src/test/java/org/apache/logging/log4j/core/net/ src/changes/
Date Wed, 26 Mar 2014 21:15:18 GMT
Author: ggregory
Date: Wed Mar 26 21:15:18 2014
New Revision: 1582057

URL: http://svn.apache.org/r1582057
Log:
<action issue="LOG4J2-582" dev="ggregory" type="update">
  Rename org.apache.logging.log4j.core.net.SocketServer to TCPSocketServer and refactor with
UDP.
</action>

Added:
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/AbstractSocketServer.java
  (with props)
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/TCPSocketServer.java
      - copied, changed from r1582054, logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/SocketServer.java
Removed:
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/SocketServer.java
Modified:
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/UDPSocketServer.java
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/AbstractSocketServerTest.java
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/TCPSocketServerTest.java
    logging/log4j/log4j2/trunk/src/changes/changes.xml

Added: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/AbstractSocketServer.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/AbstractSocketServer.java?rev=1582057&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/AbstractSocketServer.java
(added)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/AbstractSocketServer.java
Wed Mar 26 21:15:18 2014
@@ -0,0 +1,85 @@
+package org.apache.logging.log4j.core.net;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URL;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.LogEventListener;
+import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.config.xml.XMLConfiguration;
+import org.apache.logging.log4j.core.config.xml.XMLConfigurationFactory;
+
+public abstract class AbstractSocketServer extends LogEventListener {
+
+    /**
+     * Factory that creates a Configuration for the server.
+     */
+    protected static class ServerConfigurationFactory extends XMLConfigurationFactory {
+
+        private final String path;
+
+        public ServerConfigurationFactory(final String path) {
+            this.path = path;
+        }
+
+        @Override
+        public Configuration getConfiguration(final String name, final URI configLocation)
{
+            if (path != null && path.length() > 0) {
+                File file = null;
+                ConfigurationSource source = null;
+                try {
+                    file = new File(path);
+                    final FileInputStream is = new FileInputStream(file);
+                    source = new ConfigurationSource(is, file);
+                } catch (final FileNotFoundException ex) {
+                    // Ignore this error
+                }
+                if (source == null) {
+                    try {
+                        final URL url = new URL(path);
+                        source = new ConfigurationSource(url.openStream(), path);
+                    } catch (final MalformedURLException mue) {
+                        // Ignore this error
+                    } catch (final IOException ioe) {
+                        // Ignore this error
+                    }
+                }
+
+                try {
+                    if (source != null) {
+                        return new XMLConfiguration(source);
+                    }
+                } catch (final Exception ex) {
+                    // Ignore this error.
+                }
+                System.err.println("Unable to process configuration at " + path + ", using
default.");
+            }
+            return super.getConfiguration(name, configLocation);
+        }
+    }
+    
+    protected final Logger logger;
+
+    protected static final int MAX_PORT = 65534;
+
+    private volatile boolean active = true;
+
+    public AbstractSocketServer(int port) {
+        this.logger = LogManager.getLogger(this.getClass().getName() + '.' + port);
+    }
+
+    protected boolean isActive() {
+        return this.active;
+    }
+
+    protected void setActive(boolean isActive) {
+        this.active = isActive;
+    }
+
+}

Propchange: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/AbstractSocketServer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/AbstractSocketServer.java
------------------------------------------------------------------------------
    svn:keywords = Id

Copied: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/TCPSocketServer.java
(from r1582054, logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/SocketServer.java)
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/TCPSocketServer.java?p2=logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/TCPSocketServer.java&p1=logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/SocketServer.java&r1=1582054&r2=1582057&rev=1582057&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/SocketServer.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/TCPSocketServer.java
Wed Mar 26 21:15:18 2014
@@ -47,13 +47,7 @@ import org.apache.logging.log4j.core.con
 /**
  * Listens for events over a socket connection.
  */
-public class SocketServer extends LogEventListener implements Runnable {
-
-    private final Logger logger;
-
-    private static final int MAX_PORT = 65534;
-
-    private volatile boolean isActive = true;
+public class TCPSocketServer extends AbstractSocketServer implements Runnable {
 
     private final ServerSocket server;
 
@@ -64,9 +58,9 @@ public class SocketServer extends LogEve
      * @param port to listen on.
      * @throws IOException If an error occurs.
      */
-    public SocketServer(final int port) throws IOException {
+    public TCPSocketServer(final int port) throws IOException {
+        super(port);
         this.server = new ServerSocket(port);
-        this.logger = LogManager.getLogger(this.getClass().getName() + '.' + port);
     }
      /**
      * Main startup for the server.
@@ -88,7 +82,7 @@ public class SocketServer extends LogEve
         if (args.length == 2 && args[1].length() > 0) {
             ConfigurationFactory.setConfigurationFactory(new ServerConfigurationFactory(args[1]));
         }
-        final SocketServer socketServer = new SocketServer(port);
+        final TCPSocketServer socketServer = new TCPSocketServer(port);
         final Thread serverThread = new Thread(socketServer);
         serverThread.start();
         final Charset enc = Charset.defaultCharset();
@@ -111,7 +105,7 @@ public class SocketServer extends LogEve
      * Shutdown the server.
      */
     public void shutdown() {
-        this.isActive = false;
+        setActive(false);
         Thread.currentThread().interrupt();
     }
 
@@ -120,7 +114,7 @@ public class SocketServer extends LogEve
      */
     @Override
     public void run() {
-        while (isActive) {
+        while (isActive()) {
             try {
                 // Accept incoming connections.
                 final Socket clientSocket = server.accept();
@@ -199,51 +193,4 @@ public class SocketServer extends LogEve
             }
         }
     }
-
-    /**
-     * Factory that creates a Configuration for the server.
-     */
-    private static class ServerConfigurationFactory extends XMLConfigurationFactory {
-
-        private final String path;
-
-        public ServerConfigurationFactory(final String path) {
-            this.path = path;
-        }
-
-        @Override
-        public Configuration getConfiguration(final String name, final URI configLocation)
{
-            if (path != null && path.length() > 0) {
-                File file = null;
-                ConfigurationSource source = null;
-                try {
-                    file = new File(path);
-                    final FileInputStream is = new FileInputStream(file);
-                    source = new ConfigurationSource(is, file);
-                } catch (final FileNotFoundException ex) {
-                    // Ignore this error
-                }
-                if (source == null) {
-                    try {
-                        final URL url = new URL(path);
-                        source = new ConfigurationSource(url.openStream(), path);
-                    } catch (final MalformedURLException mue) {
-                        // Ignore this error
-                    } catch (final IOException ioe) {
-                        // Ignore this error
-                    }
-                }
-
-                try {
-                    if (source != null) {
-                        return new XMLConfiguration(source);
-                    }
-                } catch (final Exception ex) {
-                    // Ignore this error.
-                }
-                System.err.println("Unable to process configuration at " + path + ", using
default.");
-            }
-            return super.getConfiguration(name, configLocation);
-        }
-    }
 }

Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/UDPSocketServer.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/UDPSocketServer.java?rev=1582057&r1=1582056&r2=1582057&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/UDPSocketServer.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/UDPSocketServer.java
Wed Mar 26 21:15:18 2014
@@ -32,10 +32,7 @@ import java.net.MalformedURLException;
 import java.net.URI;
 import java.net.URL;
 
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
 import org.apache.logging.log4j.core.LogEvent;
-import org.apache.logging.log4j.core.LogEventListener;
 import org.apache.logging.log4j.core.config.Configuration;
 import org.apache.logging.log4j.core.config.ConfigurationFactory;
 import org.apache.logging.log4j.core.config.xml.XMLConfiguration;
@@ -44,13 +41,7 @@ import org.apache.logging.log4j.core.con
 /**
  * Listens for events over a socket connection.
  */
-public class UDPSocketServer extends LogEventListener implements Runnable {
-
-    private final Logger logger;
-
-    private static final int MAX_PORT = 65534;
-
-    private volatile boolean isActive = true;
+public class UDPSocketServer extends AbstractSocketServer implements Runnable {
 
     private final DatagramSocket server;
 
@@ -66,8 +57,8 @@ public class UDPSocketServer extends Log
      *             If an error occurs.
      */
     public UDPSocketServer(final int port) throws IOException {
+        super(port);
         this.server = new DatagramSocket(port);
-        this.logger = LogManager.getLogger(this.getClass().getName() + '.' + port);
     }
 
     /**
@@ -115,7 +106,7 @@ public class UDPSocketServer extends Log
      * Shutdown the server.
      */
     public void shutdown() {
-        this.isActive = false;
+        this.setActive(false);
         Thread.currentThread().interrupt();
     }
 
@@ -124,7 +115,7 @@ public class UDPSocketServer extends Log
      */
     @Override
     public void run() {
-        while (isActive) {
+        while (isActive()) {
             try {
                 final byte[] buf = new byte[maxBufferSize];
                 final DatagramPacket packet = new DatagramPacket(buf, buf.length);
@@ -145,51 +136,4 @@ public class UDPSocketServer extends Log
             }
         }
     }
-
-    /**
-     * Factory that creates a Configuration for the server.
-     */
-    private static class ServerConfigurationFactory extends XMLConfigurationFactory {
-
-        private final String path;
-
-        public ServerConfigurationFactory(final String path) {
-            this.path = path;
-        }
-
-        @Override
-        public Configuration getConfiguration(final String name, final URI configLocation)
{
-            if (path != null && path.length() > 0) {
-                File file = null;
-                ConfigurationSource source = null;
-                try {
-                    file = new File(path);
-                    final FileInputStream is = new FileInputStream(file);
-                    source = new ConfigurationSource(is, file);
-                } catch (final FileNotFoundException ex) {
-                    // Ignore this error
-                }
-                if (source == null) {
-                    try {
-                        final URL url = new URL(path);
-                        source = new ConfigurationSource(url.openStream(), path);
-                    } catch (final MalformedURLException mue) {
-                        // Ignore this error
-                    } catch (final IOException ioe) {
-                        // Ignore this error
-                    }
-                }
-
-                try {
-                    if (source != null) {
-                        return new XMLConfiguration(source);
-                    }
-                } catch (final Exception ex) {
-                    // Ignore this error.
-                }
-                System.err.println("Unable to process configuration at " + path + ", using
default.");
-            }
-            return super.getConfiguration(name, configLocation);
-        }
-    }
 }

Modified: logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/AbstractSocketServerTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/AbstractSocketServerTest.java?rev=1582057&r1=1582056&r2=1582057&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/AbstractSocketServerTest.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/AbstractSocketServerTest.java
Wed Mar 26 21:15:18 2014
@@ -20,6 +20,7 @@ import static org.junit.Assert.assertNot
 import static org.junit.Assert.assertTrue;
 
 import java.io.IOException;
+import java.io.Serializable;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
@@ -28,6 +29,7 @@ import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.core.Appender;
 import org.apache.logging.log4j.core.Filter;
+import org.apache.logging.log4j.core.Layout;
 import org.apache.logging.log4j.core.LogEvent;
 import org.apache.logging.log4j.core.Logger;
 import org.apache.logging.log4j.core.LoggerContext;
@@ -106,8 +108,9 @@ public abstract class AbstractSocketServ
     protected void testServer(final String message1, final String message2) throws Exception
{
         final Filter socketFilter = new ThreadFilter(Filter.Result.NEUTRAL, Filter.Result.DENY);
         final Filter serverFilter = new ThreadFilter(Filter.Result.DENY, Filter.Result.NEUTRAL);
+        final Layout<? extends Serializable> socketLayout = createLayout();
         final SocketAppender appender = SocketAppender.createAppender("localhost", this.port,
this.protocol, "-1", null, "Test", null,
-                "false", null, socketFilter, null, null);
+                "false", socketLayout, socketFilter, null, null);
         appender.start();
         final ListAppender listApp = new ListAppender("Events", serverFilter, null, false,
false);
         listApp.start();
@@ -133,6 +136,10 @@ public abstract class AbstractSocketServ
         assertTrue("Incorrect event", events.get(1).getMessage().getFormattedMessage().equals(message2));
     }
 
+    protected Layout<? extends Serializable> createLayout() {
+        return null;
+    }
+
     @Test
     public void testShortMessages() throws Exception {
         testServer(MESSAGE_1, MESSAGE_2);

Modified: logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/TCPSocketServerTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/TCPSocketServerTest.java?rev=1582057&r1=1582056&r2=1582057&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/TCPSocketServerTest.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/TCPSocketServerTest.java
Wed Mar 26 21:15:18 2014
@@ -24,14 +24,14 @@ import org.junit.BeforeClass;
 public class TCPSocketServerTest extends AbstractSocketServerTest {
     private static final String PORT = "8198";
     private static final int PORT_NUM = Integer.parseInt(PORT);
-    private static SocketServer tcpSocketServer;
+    private static TCPSocketServer tcpSocketServer;
 
     private static Thread thread;
 
     @BeforeClass
     public static void setupClass() throws Exception {
         ((LoggerContext) LogManager.getContext(false)).reconfigure();
-        tcpSocketServer = new SocketServer(PORT_NUM);
+        tcpSocketServer = new TCPSocketServer(PORT_NUM);
         thread = new Thread(tcpSocketServer);
         thread.start();
     }

Modified: logging/log4j/log4j2/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/changes/changes.xml?rev=1582057&r1=1582056&r2=1582057&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/changes/changes.xml (original)
+++ logging/log4j/log4j2/trunk/src/changes/changes.xml Wed Mar 26 21:15:18 2014
@@ -63,6 +63,9 @@
       <action issue="LOG4J2-468" dev="rgoers" type="update">
         Add support to add a LoggerConfig. Document two ways to modify the configuration.
       </action>
+      <action issue="LOG4J2-582" dev="ggregory" type="update">
+        Rename org.apache.logging.log4j.core.net.SocketServer to TCPSocketServer and refactor
with UDP.
+      </action>
     </release>
     <release version="2.0-rc1" date="2014-02-16" description="Bug fixes and enhancements">
       <action dev="nickwilliams" type="delete">



Mime
View raw message