Replace String protocol method with type-safe enum Protocol.

Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/89000250
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/89000250
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/89000250

Branch: refs/heads/LOG4J2-649
Commit: 89000250a087f21238247adabc55602bb5815a8b
Parents: ec0bb19
Author: ggregory <ggreg...@apache.org>
Authored: Tue Dec 1 18:25:01 2015 -0800
Committer: ggregory <ggreg...@apache.org>
Committed: Tue Dec 1 18:25:01 2015 -0800

----------------------------------------------------------------------
 .../apache/logging/log4j/core/appender/SocketAppender.java  | 7 +++----
 .../logging/log4j/core/appender/SocketAppenderTest.java     | 9 +++++----
 .../log4j/core/net/server/AbstractSocketServerTest.java     | 5 +++--
 .../log4j/core/net/server/SslXmlSocketServerTest.java       | 3 ++-
 .../log4j/core/net/server/TcpJsonSocketServerTest.java      | 3 ++-
 .../core/net/server/TcpSerializedSocketServerTest.java      | 3 ++-
 .../log4j/core/net/server/TcpXmlSocketServerTest.java       | 3 ++-
 .../log4j/core/net/server/UdpJsonSocketServerTest.java      | 3 ++-
 .../core/net/server/UdpSerializedSocketServerTest.java      | 3 ++-
 .../log4j/core/net/server/UdpXmlSocketServerTest.java       | 3 ++-
 10 files changed, 25 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/89000250/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/SocketAppender.java
----------------------------------------------------------------------
diff --git 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/SocketAppender.java
 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/SocketAppender.java
index 949eba8..60f3c17 100644
--- 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/SocketAppender.java
+++ 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/SocketAppender.java
@@ -79,7 +79,7 @@ public class SocketAppender extends 
AbstractOutputStreamAppender<AbstractSocketM
      *        The name of the host to connect to.
      * @param portNum
      *        The port to connect to on the target host.
-     * @param protocolStr
+     * @param protocolIn
      *        The Protocol to use.
      * @param sslConfig
      *        The SSL configuration file for TCP/SSL, ignored for UPD.
@@ -111,7 +111,7 @@ public class SocketAppender extends 
AbstractOutputStreamAppender<AbstractSocketM
             // @formatter:off
             @PluginAttribute("host") final String host,
             @PluginAttribute("port") final String portNum,
-            @PluginAttribute("protocol") final String protocolStr,
+            @PluginAttribute("protocol") final Protocol protocolIn,
             @PluginElement("SSL") final SslConfiguration sslConfig,
             @PluginAttribute(value = "connectTimeoutMillis", defaultInt = 0) 
final int connectTimeoutMillis,
             @PluginAliases("reconnectionDelay") // deprecated
@@ -139,8 +139,7 @@ public class SocketAppender extends 
AbstractOutputStreamAppender<AbstractSocketM
             return null;
         }
 
-        final Protocol protocol = EnglishEnums.valueOf(Protocol.class,
-                protocolStr != null ? protocolStr : Protocol.TCP.name());
+        final Protocol protocol = protocolIn != null ? protocolIn : 
Protocol.TCP;
         if (protocol == Protocol.UDP) {
             isFlush = true;
         }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/89000250/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/SocketAppenderTest.java
----------------------------------------------------------------------
diff --git 
a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/SocketAppenderTest.java
 
b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/SocketAppenderTest.java
index 472fb18..150ae70 100644
--- 
a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/SocketAppenderTest.java
+++ 
b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/SocketAppenderTest.java
@@ -42,6 +42,7 @@ import org.apache.logging.log4j.core.Appender;
 import org.apache.logging.log4j.core.LogEvent;
 import org.apache.logging.log4j.core.Logger;
 import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.net.Protocol;
 import org.apache.logging.log4j.test.AvailablePortFinder;
 import org.junit.After;
 import org.junit.AfterClass;
@@ -103,7 +104,7 @@ public class SocketAppenderTest {
     @Test
     public void testTcpAppender() throws Exception {
 
-        final SocketAppender appender = 
SocketAppender.createAppender("localhost", PORT, "tcp", null, 0, "-1",
+        final SocketAppender appender = 
SocketAppender.createAppender("localhost", PORT, Protocol.TCP, null, 0, "-1",
                 "false", "Test", null, null, null, null, null, null);
         appender.start();
 
@@ -151,7 +152,7 @@ public class SocketAppenderTest {
     @Test
     public void testUdpAppender() throws Exception {
 
-        final SocketAppender appender = 
SocketAppender.createAppender("localhost", PORT, "udp", null, 0, "-1",
+        final SocketAppender appender = 
SocketAppender.createAppender("localhost", PORT, Protocol.UDP, null, 0, "-1",
                 "false", "Test", null, null, null, null, null, null);
         appender.start();
 
@@ -169,7 +170,7 @@ public class SocketAppenderTest {
     @Test
     public void testTcpAppenderDeadlock() throws Exception {
 
-        final SocketAppender appender = 
SocketAppender.createAppender("localhost", DYN_PORT, "tcp", null, 0,
+        final SocketAppender appender = 
SocketAppender.createAppender("localhost", DYN_PORT, Protocol.TCP, null, 0,
                 "100", "false", "Test", null, null, null, null, null, null);
         appender.start();
         // set appender on root and set level to debug
@@ -188,7 +189,7 @@ public class SocketAppenderTest {
     @Test
     public void testTcpAppenderNoWait() throws Exception {
 
-        final SocketAppender appender = 
SocketAppender.createAppender("localhost", ERROR_PORT, "tcp", null, 0,
+        final SocketAppender appender = 
SocketAppender.createAppender("localhost", ERROR_PORT, Protocol.TCP, null, 0,
                 "100", "true", "Test", null, "false", null, null, null, null);
         appender.start();
         // set appender on root and set level to debug

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/89000250/log4j-core/src/test/java/org/apache/logging/log4j/core/net/server/AbstractSocketServerTest.java
----------------------------------------------------------------------
diff --git 
a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/server/AbstractSocketServerTest.java
 
b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/server/AbstractSocketServerTest.java
index f72a244..18f450a 100644
--- 
a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/server/AbstractSocketServerTest.java
+++ 
b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/server/AbstractSocketServerTest.java
@@ -35,6 +35,7 @@ import org.apache.logging.log4j.core.appender.SocketAppender;
 import org.apache.logging.log4j.core.layout.JsonLayout;
 import org.apache.logging.log4j.core.layout.PatternLayout;
 import org.apache.logging.log4j.core.layout.XmlLayout;
+import org.apache.logging.log4j.core.net.Protocol;
 import org.apache.logging.log4j.test.AvailablePortFinder;
 import org.apache.logging.log4j.test.appender.ListAppender;
 import org.junit.After;
@@ -66,11 +67,11 @@ public abstract class AbstractSocketServerTest {
 
     protected final String port;
 
-    protected final String protocol;
+    protected final Protocol protocol;
 
     private final Logger rootLogger = 
ctx.getLogger(AbstractSocketServerTest.class.getSimpleName());
 
-    protected AbstractSocketServerTest(final String protocol, final String 
port, final boolean expectLengthException) {
+    protected AbstractSocketServerTest(final Protocol protocol, final String 
port, final boolean expectLengthException) {
         this.protocol = protocol;
         this.port = port;
         this.expectLengthException = expectLengthException;

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/89000250/log4j-core/src/test/java/org/apache/logging/log4j/core/net/server/SslXmlSocketServerTest.java
----------------------------------------------------------------------
diff --git 
a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/server/SslXmlSocketServerTest.java
 
b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/server/SslXmlSocketServerTest.java
index 853e5df..3eafa45 100644
--- 
a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/server/SslXmlSocketServerTest.java
+++ 
b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/server/SslXmlSocketServerTest.java
@@ -25,6 +25,7 @@ import org.apache.logging.log4j.core.Filter;
 import org.apache.logging.log4j.core.Layout;
 import org.apache.logging.log4j.core.LoggerContext;
 import org.apache.logging.log4j.core.appender.SocketAppender;
+import org.apache.logging.log4j.core.net.Protocol;
 import org.apache.logging.log4j.core.net.ssl.KeyStoreConfiguration;
 import org.apache.logging.log4j.core.net.ssl.SslConfiguration;
 import org.apache.logging.log4j.core.net.ssl.StoreConfigurationException;
@@ -79,7 +80,7 @@ public class SslXmlSocketServerTest extends 
AbstractSocketServerTest {
     }
 
     public SslXmlSocketServerTest() {
-        super("SSL", PORT, false);
+        super(Protocol.SSL, PORT, false);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/89000250/log4j-core/src/test/java/org/apache/logging/log4j/core/net/server/TcpJsonSocketServerTest.java
----------------------------------------------------------------------
diff --git 
a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/server/TcpJsonSocketServerTest.java
 
b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/server/TcpJsonSocketServerTest.java
index 3f579c0..6420e7e 100644
--- 
a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/server/TcpJsonSocketServerTest.java
+++ 
b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/server/TcpJsonSocketServerTest.java
@@ -21,6 +21,7 @@ import java.io.InputStream;
 
 import org.apache.logging.log4j.core.Layout;
 import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.net.Protocol;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 
@@ -50,7 +51,7 @@ public class TcpJsonSocketServerTest extends 
AbstractSocketServerTest {
     }
 
     public TcpJsonSocketServerTest() {
-        super("tcp", PORT, false);
+        super(Protocol.TCP, PORT, false);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/89000250/log4j-core/src/test/java/org/apache/logging/log4j/core/net/server/TcpSerializedSocketServerTest.java
----------------------------------------------------------------------
diff --git 
a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/server/TcpSerializedSocketServerTest.java
 
b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/server/TcpSerializedSocketServerTest.java
index 460703c..645701b 100644
--- 
a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/server/TcpSerializedSocketServerTest.java
+++ 
b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/server/TcpSerializedSocketServerTest.java
@@ -22,6 +22,7 @@ import java.io.Serializable;
 
 import org.apache.logging.log4j.core.Layout;
 import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.net.Protocol;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 
@@ -51,7 +52,7 @@ public class TcpSerializedSocketServerTest extends 
AbstractSocketServerTest {
     }
 
     public TcpSerializedSocketServerTest() {
-        super("tcp", PORT, false);
+        super(Protocol.TCP, PORT, false);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/89000250/log4j-core/src/test/java/org/apache/logging/log4j/core/net/server/TcpXmlSocketServerTest.java
----------------------------------------------------------------------
diff --git 
a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/server/TcpXmlSocketServerTest.java
 
b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/server/TcpXmlSocketServerTest.java
index 677121e..2290cbd 100644
--- 
a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/server/TcpXmlSocketServerTest.java
+++ 
b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/server/TcpXmlSocketServerTest.java
@@ -22,6 +22,7 @@ import java.nio.charset.Charset;
 
 import org.apache.logging.log4j.core.Layout;
 import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.net.Protocol;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 
@@ -53,7 +54,7 @@ public class TcpXmlSocketServerTest extends 
AbstractSocketServerTest {
     }
 
     public TcpXmlSocketServerTest() {
-        super("tcp", PORT, false);
+        super(Protocol.TCP, PORT, false);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/89000250/log4j-core/src/test/java/org/apache/logging/log4j/core/net/server/UdpJsonSocketServerTest.java
----------------------------------------------------------------------
diff --git 
a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/server/UdpJsonSocketServerTest.java
 
b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/server/UdpJsonSocketServerTest.java
index c9ff94b..3f33b14 100644
--- 
a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/server/UdpJsonSocketServerTest.java
+++ 
b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/server/UdpJsonSocketServerTest.java
@@ -21,6 +21,7 @@ import java.io.Serializable;
 
 import org.apache.logging.log4j.core.Layout;
 import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.net.Protocol;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 
@@ -46,7 +47,7 @@ public class UdpJsonSocketServerTest extends 
AbstractSocketServerTest {
     }
 
     public UdpJsonSocketServerTest() {
-        super("udp", PORT, true);
+        super(Protocol.UDP, PORT, true);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/89000250/log4j-core/src/test/java/org/apache/logging/log4j/core/net/server/UdpSerializedSocketServerTest.java
----------------------------------------------------------------------
diff --git 
a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/server/UdpSerializedSocketServerTest.java
 
b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/server/UdpSerializedSocketServerTest.java
index ad49838..718aa57 100644
--- 
a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/server/UdpSerializedSocketServerTest.java
+++ 
b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/server/UdpSerializedSocketServerTest.java
@@ -21,6 +21,7 @@ import java.io.Serializable;
 
 import org.apache.logging.log4j.core.Layout;
 import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.net.Protocol;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 
@@ -46,7 +47,7 @@ public class UdpSerializedSocketServerTest extends 
AbstractSocketServerTest {
     }
 
     public UdpSerializedSocketServerTest() {
-        super("udp", PORT, true);
+        super(Protocol.UDP, PORT, true);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/89000250/log4j-core/src/test/java/org/apache/logging/log4j/core/net/server/UdpXmlSocketServerTest.java
----------------------------------------------------------------------
diff --git 
a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/server/UdpXmlSocketServerTest.java
 
b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/server/UdpXmlSocketServerTest.java
index 526567a..fa54766 100644
--- 
a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/server/UdpXmlSocketServerTest.java
+++ 
b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/server/UdpXmlSocketServerTest.java
@@ -22,6 +22,7 @@ import java.nio.charset.Charset;
 
 import org.apache.logging.log4j.core.Layout;
 import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.net.Protocol;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 
@@ -49,7 +50,7 @@ public class UdpXmlSocketServerTest extends 
AbstractSocketServerTest {
     }
 
     public UdpXmlSocketServerTest() {
-        super("udp", PORT, true);
+        super(Protocol.UDP, PORT, true);
     }
 
     @Override

Reply via email to