logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1582204 - in /logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net: AbstractLogEventInput.java JSONLogEventInput.java LogEventInput.java SerializedLogEventInput.java TCPSocketServer.java XMLLogEventInput.java
Date Thu, 27 Mar 2014 06:06:20 GMT
Author: ggregory
Date: Thu Mar 27 06:06:20 2014
New Revision: 1582204

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

Added:
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/AbstractLogEventInput.java
  (with props)
Modified:
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/JSONLogEventInput.java
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/LogEventInput.java
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/SerializedLogEventInput.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/XMLLogEventInput.java

Added: 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=1582204&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/AbstractLogEventInput.java
(added)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/AbstractLogEventInput.java
Thu Mar 27 06:06:20 2014
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.core.net;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * Abstract class for implementations of {@link LogEventInput}.
+ * 
+ * @param <T>
+ */
+public abstract class AbstractLogEventInput<T extends InputStream> implements LogEventInput<T>
{
+
+    @Override
+    public T wrapStream(InputStream inputStream) throws IOException {
+        return (T) inputStream;
+    }
+
+}

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

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

Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/JSONLogEventInput.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/JSONLogEventInput.java?rev=1582204&r1=1582203&r2=1582204&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/JSONLogEventInput.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/JSONLogEventInput.java
Thu Mar 27 06:06:20 2014
@@ -24,7 +24,7 @@ import org.apache.logging.log4j.core.Log
 /**
  * Reads JSON {@link LogEvent}s.
  */
-public class JSONLogEventInput implements LogEventInput {
+public class JSONLogEventInput extends AbstractLogEventInput {
 
     @Override
     public LogEvent readLogEvent(InputStream inputStream) throws IOException {

Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/LogEventInput.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/LogEventInput.java?rev=1582204&r1=1582203&r2=1582204&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/LogEventInput.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/LogEventInput.java
Thu Mar 27 06:06:20 2014
@@ -23,15 +23,26 @@ import org.apache.logging.log4j.core.Log
 
 /**
  * Reads {@link LogEvent}s from an input stream.
+ * 
+ * @param <T> The kind of {@link InputStream} to wrap and read.
  */
-public interface LogEventInput {
+public interface LogEventInput<T extends InputStream> {
 
     /**
      * Reads a {@link LogEvent} from the given input stream.
      * 
      * @param inputStream the input stream to read
      * @return a LogEvent
-     * @throws IOException 
+     * @throws IOException
      */
-    LogEvent readLogEvent(InputStream inputStream) throws IOException;
+    LogEvent readLogEvent(T inputStream) throws IOException;
+
+    /**
+     * Wraps the given stream if needed.
+     * 
+     * @param inputStream the stream to wrap
+     * @return the wrapped stream or the given stream.
+     * @throws IOException
+     */
+    T wrapStream(InputStream inputStream) throws IOException;
 }

Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/SerializedLogEventInput.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/SerializedLogEventInput.java?rev=1582204&r1=1582203&r2=1582204&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/SerializedLogEventInput.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/SerializedLogEventInput.java
Thu Mar 27 06:06:20 2014
@@ -25,17 +25,19 @@ import org.apache.logging.log4j.core.Log
 /**
  * Reads serialized {@link LogEvent}s.
  */
-public class SerializedLogEventInput implements LogEventInput {
+public class SerializedLogEventInput extends AbstractLogEventInput<ObjectInputStream>
{
 
     @Override
-    public LogEvent readLogEvent(InputStream inputStream) throws IOException {
-        final ObjectInputStream ois = inputStream instanceof ObjectInputStream ? (ObjectInputStream)
inputStream : new ObjectInputStream(
-                inputStream);
+    public LogEvent readLogEvent(ObjectInputStream inputStream) throws IOException {
         try {
-            return (LogEvent) ois.readObject();
+            return (LogEvent) inputStream.readObject();
         } catch (ClassNotFoundException e) {
             throw new IOException(e);
         }
     }
 
+    @Override
+    public ObjectInputStream wrapStream(InputStream inputStream) throws IOException {
+        return new ObjectInputStream(inputStream);
+    }
 }

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=1582204&r1=1582203&r2=1582204&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 06:06:20 2014
@@ -48,8 +48,8 @@ public class TCPSocketServer extends Abs
         private volatile boolean shutdown = false;
 
         public SocketHandler(final Socket socket, LogEventInput logEventInput) throws IOException
{
-            this.inputStream = new ObjectInputStream(socket.getInputStream());
             this.logEventInput = logEventInput;
+            this.inputStream = logEventInput.wrapStream(socket.getInputStream());
         }
 
         @Override

Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/XMLLogEventInput.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/XMLLogEventInput.java?rev=1582204&r1=1582203&r2=1582204&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/XMLLogEventInput.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/XMLLogEventInput.java
Thu Mar 27 06:06:20 2014
@@ -24,7 +24,7 @@ import org.apache.logging.log4j.core.Log
 /**
  * Reads XML {@link LogEvent}s.
  */
-public class XMLLogEventInput implements LogEventInput {
+public class XMLLogEventInput extends AbstractLogEventInput {
 
     @Override
     public LogEvent readLogEvent(InputStream inputStream) throws IOException {



Mime
View raw message