logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1582357 - in /logging/log4j/log4j2/trunk/log4j-core/src: main/java/org/apache/logging/log4j/core/net/ test/java/org/apache/logging/log4j/core/net/
Date Thu, 27 Mar 2014 15:38:19 GMT
Author: ggregory
Date: Thu Mar 27 15:38:19 2014
New Revision: 1582357

URL: http://svn.apache.org/r1582357
Log:
[LOG4J2-583] TCP and UDP socket servers should be able to handle XML log events. Refactor
current code for XML and JSON. Fix generics warnings.

Modified:
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/AbstractLogEventInput.java
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/AbstractSocketServer.java
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/TCPSocketServer.java
    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/TcpJsonSocketServerTest.java
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/TcpSerializedSocketServerTest.java
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/TcpXmlSocketServerTest.java
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/UdpJsonSocketServerTest.java
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/UdpSerializedSocketServerTest.java
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/UdpXmlSocketServerTest.java

Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/AbstractLogEventInput.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/AbstractLogEventInput.java?rev=1582357&r1=1582356&r2=1582357&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/AbstractLogEventInput.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/AbstractLogEventInput.java
Thu Mar 27 15:38:19 2014
@@ -22,10 +22,12 @@ import java.io.InputStream;
 /**
  * Abstract class for implementations of {@link LogEventInput}.
  * 
- * @param <T>
+ * @param <T> The kind of input stream read
  */
 public abstract class AbstractLogEventInput<T extends InputStream> implements LogEventInput<T>
{
 
+    // @SuppressWarnings("unchecked"): The default is to return the same object as given.
+    @SuppressWarnings("unchecked")
     @Override
     public T wrapStream(final InputStream inputStream) throws IOException {
         return (T) inputStream;

Modified: 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=1582357&r1=1582356&r2=1582357&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/AbstractSocketServer.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/AbstractSocketServer.java
Thu Mar 27 15:38:19 2014
@@ -35,6 +35,8 @@ import org.apache.logging.log4j.core.hel
 
 /**
  * Abstract socket server for TCP and UDP implementations.
+ * 
+ * @param <T> The kind of input stream read
  */
 public abstract class AbstractSocketServer<T extends InputStream> extends LogEventListener
{
 
@@ -93,6 +95,12 @@ public abstract class AbstractSocketServ
 
     protected final LogEventInput<T> logEventInput;
 
+    /**
+     * Creates a new socket server.
+     * 
+     * @param port listen to this port
+     * @param logEventInput Use this input to read log events.
+     */
     public AbstractSocketServer(final int port, final LogEventInput<T> logEventInput)
{
         this.logger = LogManager.getLogger(this.getClass().getName() + '.' + port);
         this.logEventInput = Assert.requireNonNull(logEventInput, "LogEventInput");

Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/TCPSocketServer.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/TCPSocketServer.java?rev=1582357&r1=1582356&r2=1582357&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/TCPSocketServer.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/TCPSocketServer.java
Thu Mar 27 15:38:19 2014
@@ -21,6 +21,7 @@ import java.io.EOFException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
+import java.io.ObjectInputStream;
 import java.io.OptionalDataException;
 import java.net.ServerSocket;
 import java.net.Socket;
@@ -33,21 +34,21 @@ import org.apache.logging.log4j.core.con
 
 /**
  * Listens for events over a socket connection.
+ * 
+ * @param <T> The kind of input stream read
  */
-public class TCPSocketServer extends AbstractSocketServer implements Runnable {
+public class TCPSocketServer<T extends InputStream> extends AbstractSocketServer<T>
implements Runnable {
 
     /**
      * Thread that processes the events.
      */
     private class SocketHandler extends Thread {
-        private final LogEventInput logEventInput;
 
-        private final InputStream inputStream;
+        private final T inputStream;
 
         private volatile boolean shutdown = false;
 
-        public SocketHandler(final Socket socket, final LogEventInput logEventInput) throws
IOException {
-            this.logEventInput = logEventInput;
+        public SocketHandler(final Socket socket) throws IOException {
             this.inputStream = logEventInput.wrapStream(socket.getInputStream());
         }
 
@@ -91,8 +92,8 @@ public class TCPSocketServer extends Abs
      * @return a new a socket server
      * @throws IOException if an I/O error occurs when opening the socket.
      */
-    public static TCPSocketServer createJsonSocketServer(final int port) throws IOException
{
-        return new TCPSocketServer(port, new JSONLogEventInput());
+    public static TCPSocketServer<InputStream> createJsonSocketServer(final int port)
throws IOException {
+        return new TCPSocketServer<InputStream>(port, new JSONLogEventInput());
     }
 
     /**
@@ -102,8 +103,8 @@ public class TCPSocketServer extends Abs
      * @return a new a socket server
      * @throws IOException if an I/O error occurs when opening the socket.
      */
-    public static TCPSocketServer createSerializedSocketServer(final int port) throws IOException
{
-        return new TCPSocketServer(port, new SerializedLogEventInput());
+    public static TCPSocketServer<ObjectInputStream> createSerializedSocketServer(final
int port) throws IOException {
+        return new TCPSocketServer<ObjectInputStream>(port, new SerializedLogEventInput());
     }
 
     /**
@@ -113,8 +114,8 @@ public class TCPSocketServer extends Abs
      * @return a new a socket server
      * @throws IOException if an I/O error occurs when opening the socket.
      */
-    public static TCPSocketServer createXmlSocketServer(final int port) throws IOException
{
-        return new TCPSocketServer(port, new XMLLogEventInput());
+    public static TCPSocketServer<InputStream> createXmlSocketServer(final int port)
throws IOException {
+        return new TCPSocketServer<InputStream>(port, new XMLLogEventInput());
     }
 
     /**
@@ -138,8 +139,7 @@ public class TCPSocketServer extends Abs
         if (args.length == 2 && args[1].length() > 0) {
             ConfigurationFactory.setConfigurationFactory(new ServerConfigurationFactory(args[1]));
         }
-        final TCPSocketServer socketServer = TCPSocketServer.createSerializedSocketServer(port);
-        ;
+        final TCPSocketServer<ObjectInputStream> socketServer = TCPSocketServer.createSerializedSocketServer(port);
         final Thread serverThread = new Thread(socketServer);
         serverThread.start();
         final Charset enc = Charset.defaultCharset();
@@ -169,7 +169,7 @@ public class TCPSocketServer extends Abs
      * @param logEventInput the log even input
      * @throws IOException if an I/O error occurs when opening the socket.
      */
-    public TCPSocketServer(final int port, final LogEventInput logEventInput) throws IOException
{
+    public TCPSocketServer(final int port, final LogEventInput<T> logEventInput) throws
IOException {
         super(port, logEventInput);
         this.server = new ServerSocket(port);
     }
@@ -189,7 +189,7 @@ public class TCPSocketServer extends Abs
                 // If execution reaches this point, then it means that a client
                 // socket has been accepted.
 
-                final SocketHandler handler = new SocketHandler(clientSocket, this.logEventInput);
+                final SocketHandler handler = new SocketHandler(clientSocket);
                 handlers.put(Long.valueOf(handler.getId()), handler);
                 handler.start();
             } catch (final IOException ioe) {

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=1582357&r1=1582356&r2=1582357&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
Thu Mar 27 15:38:19 2014
@@ -20,7 +20,9 @@ import java.io.BufferedReader;
 import java.io.ByteArrayInputStream;
 import java.io.EOFException;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.InputStreamReader;
+import java.io.ObjectInputStream;
 import java.io.OptionalDataException;
 import java.net.DatagramPacket;
 import java.net.DatagramSocket;
@@ -29,8 +31,10 @@ import org.apache.logging.log4j.core.con
 
 /**
  * Listens for events over a socket connection.
+ * 
+ * @param <T> The kind of input stream read
  */
-public class UDPSocketServer extends AbstractSocketServer implements Runnable {
+public class UDPSocketServer<T extends InputStream> extends AbstractSocketServer<T>
implements Runnable {
 
     /**
      * Creates a socket server that reads JSON log events.
@@ -39,8 +43,8 @@ public class UDPSocketServer extends Abs
      * @return a new a socket server
      * @throws IOException if an I/O error occurs when opening the socket.
      */
-    public static UDPSocketServer createJsonSocketServer(final int port) throws IOException
{
-        return new UDPSocketServer(port, new JSONLogEventInput());
+    public static UDPSocketServer<InputStream> createJsonSocketServer(final int port)
throws IOException {
+        return new UDPSocketServer<InputStream> (port, new JSONLogEventInput());
     }
 
     /**
@@ -50,8 +54,8 @@ public class UDPSocketServer extends Abs
      * @return a new a socket server
      * @throws IOException if an I/O error occurs when opening the socket.
      */
-    public static UDPSocketServer createSerializedSocketServer(final int port) throws IOException
{
-        return new UDPSocketServer(port, new SerializedLogEventInput());
+    public static UDPSocketServer<ObjectInputStream>  createSerializedSocketServer(final
int port) throws IOException {
+        return new UDPSocketServer<ObjectInputStream> (port, new SerializedLogEventInput());
     }
 
     /**
@@ -61,8 +65,8 @@ public class UDPSocketServer extends Abs
      * @return a new a socket server
      * @throws IOException if an I/O error occurs when opening the socket.
      */
-    public static UDPSocketServer createXmlSocketServer(final int port) throws IOException
{
-        return new UDPSocketServer(port, new XMLLogEventInput());
+    public static UDPSocketServer<InputStream>  createXmlSocketServer(final int port)
throws IOException {
+        return new UDPSocketServer<InputStream> (port, new XMLLogEventInput());
     }
 
     private final DatagramSocket datagramSocket;
@@ -77,7 +81,7 @@ public class UDPSocketServer extends Abs
      * @param logEventInput
      * @throws IOException If an error occurs.
      */
-    public UDPSocketServer(final int port, final LogEventInput logEventInput) throws IOException
{
+    public UDPSocketServer(final int port, final LogEventInput<T> logEventInput) throws
IOException {
         super(port, logEventInput);
         this.datagramSocket = new DatagramSocket(port);
     }
@@ -103,7 +107,7 @@ public class UDPSocketServer extends Abs
         if (args.length == 2 && args[1].length() > 0) {
             ConfigurationFactory.setConfigurationFactory(new ServerConfigurationFactory(args[1]));
         }
-        final UDPSocketServer socketServer = UDPSocketServer.createSerializedSocketServer(port);
+        final UDPSocketServer<ObjectInputStream> socketServer = UDPSocketServer.createSerializedSocketServer(port);
         final Thread server = new Thread(socketServer);
         server.start();
         final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

Modified: logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/TcpJsonSocketServerTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/TcpJsonSocketServerTest.java?rev=1582357&r1=1582356&r2=1582357&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/TcpJsonSocketServerTest.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/TcpJsonSocketServerTest.java
Thu Mar 27 15:38:19 2014
@@ -16,6 +16,8 @@
  */
 package org.apache.logging.log4j.core.net;
 
+import java.io.InputStream;
+
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.core.Layout;
 import org.apache.logging.log4j.core.LoggerContext;
@@ -27,7 +29,7 @@ import org.junit.Ignore;
 public class TcpJsonSocketServerTest extends AbstractSocketServerTest {
     private static final String PORT = "8198";
     private static final int PORT_NUM = Integer.parseInt(PORT);
-    private static TCPSocketServer tcpSocketServer;
+    private static TCPSocketServer<InputStream> tcpSocketServer;
 
     private static Thread thread;
 

Modified: logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/TcpSerializedSocketServerTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/TcpSerializedSocketServerTest.java?rev=1582357&r1=1582356&r2=1582357&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/TcpSerializedSocketServerTest.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/TcpSerializedSocketServerTest.java
Thu Mar 27 15:38:19 2014
@@ -16,6 +16,7 @@
  */
 package org.apache.logging.log4j.core.net;
 
+import java.io.ObjectInputStream;
 import java.io.Serializable;
 
 import org.apache.logging.log4j.LogManager;
@@ -27,7 +28,7 @@ import org.junit.BeforeClass;
 public class TcpSerializedSocketServerTest extends AbstractSocketServerTest {
     private static final String PORT = "8198";
     private static final int PORT_NUM = Integer.parseInt(PORT);
-    private static TCPSocketServer tcpSocketServer;
+    private static TCPSocketServer<ObjectInputStream> tcpSocketServer;
 
     private static Thread thread;
 

Modified: logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/TcpXmlSocketServerTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/TcpXmlSocketServerTest.java?rev=1582357&r1=1582356&r2=1582357&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/TcpXmlSocketServerTest.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/TcpXmlSocketServerTest.java
Thu Mar 27 15:38:19 2014
@@ -16,6 +16,8 @@
  */
 package org.apache.logging.log4j.core.net;
 
+import java.io.InputStream;
+
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.core.Layout;
 import org.apache.logging.log4j.core.LoggerContext;
@@ -27,7 +29,7 @@ import org.junit.Ignore;
 public class TcpXmlSocketServerTest extends AbstractSocketServerTest {
     private static final String PORT = "8198";
     private static final int PORT_NUM = Integer.parseInt(PORT);
-    private static TCPSocketServer tcpSocketServer;
+    private static TCPSocketServer<InputStream> tcpSocketServer;
 
     private static Thread thread;
 

Modified: logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/UdpJsonSocketServerTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/UdpJsonSocketServerTest.java?rev=1582357&r1=1582356&r2=1582357&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/UdpJsonSocketServerTest.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/UdpJsonSocketServerTest.java
Thu Mar 27 15:38:19 2014
@@ -16,6 +16,7 @@
  */
 package org.apache.logging.log4j.core.net;
 
+import java.io.InputStream;
 import java.io.Serializable;
 
 import org.apache.logging.log4j.LogManager;
@@ -30,8 +31,7 @@ public class UdpJsonSocketServerTest ext
     private static final String PORT = "8199";
     private static final int PORT_NUM = Integer.parseInt(PORT);
     private static Thread thread;
-
-    private static UDPSocketServer udpSocketServer;
+    private static UDPSocketServer<InputStream> udpSocketServer;
 
     @BeforeClass
     public static void setupClass() throws Exception {

Modified: logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/UdpSerializedSocketServerTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/UdpSerializedSocketServerTest.java?rev=1582357&r1=1582356&r2=1582357&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/UdpSerializedSocketServerTest.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/UdpSerializedSocketServerTest.java
Thu Mar 27 15:38:19 2014
@@ -16,6 +16,7 @@
  */
 package org.apache.logging.log4j.core.net;
 
+import java.io.ObjectInputStream;
 import java.io.Serializable;
 
 import org.apache.logging.log4j.LogManager;
@@ -28,8 +29,7 @@ public class UdpSerializedSocketServerTe
     private static final String PORT = "8199";
     private static final int PORT_NUM = Integer.parseInt(PORT);
     private static Thread thread;
-
-    private static UDPSocketServer udpSocketServer;
+    private static UDPSocketServer<ObjectInputStream> udpSocketServer;
 
     @BeforeClass
     public static void setupClass() throws Exception {

Modified: logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/UdpXmlSocketServerTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/UdpXmlSocketServerTest.java?rev=1582357&r1=1582356&r2=1582357&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/UdpXmlSocketServerTest.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/UdpXmlSocketServerTest.java
Thu Mar 27 15:38:19 2014
@@ -16,6 +16,7 @@
  */
 package org.apache.logging.log4j.core.net;
 
+import java.io.InputStream;
 import java.io.Serializable;
 
 import org.apache.logging.log4j.LogManager;
@@ -30,8 +31,7 @@ public class UdpXmlSocketServerTest exte
     private static final String PORT = "8199";
     private static final int PORT_NUM = Integer.parseInt(PORT);
     private static Thread thread;
-
-    private static UDPSocketServer udpSocketServer;
+    private static UDPSocketServer<InputStream> udpSocketServer;
 
     @BeforeClass
     public static void setupClass() throws Exception {



Mime
View raw message