You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rg...@apache.org on 2011/12/30 17:52:49 UTC
svn commit: r1225860 - in
/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core:
layout/ net/
Author: rgoers
Date: Fri Dec 30 16:52:48 2011
New Revision: 1225860
URL: http://svn.apache.org/viewvc?rev=1225860&view=rev
Log:
Fixed almost all checkstyle errors
Modified:
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/layout/RFC5424Layout.java
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/AbstractJMSManager.java
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/AbstractJMSReceiver.java
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/AbstractSocketManager.java
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/DatagramOutputStream.java
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/DatagramSocketManager.java
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/Facility.java
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/JMSQueueManager.java
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/JMSQueueReceiver.java
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/JMSTopicManager.java
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/JMSTopicReceiver.java
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/Priority.java
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/Protocol.java
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/Severity.java
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/SocketServer.java
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/TCPSocketManager.java
Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/layout/RFC5424Layout.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/layout/RFC5424Layout.java?rev=1225860&r1=1225859&r2=1225860&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/layout/RFC5424Layout.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/layout/RFC5424Layout.java Fri Dec 30 16:52:48 2011
@@ -268,7 +268,7 @@ public final class RFC5424Layout extends
int millis = cal.get(Calendar.MILLISECOND);
if (millis != 0) {
buf.append(".");
- pad((int) ((float) millis / 10F), THREE_DIGITS, buf);
+ pad(millis, THREE_DIGITS, buf);
}
int tzmin = (cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET)) / MILLIS_PER_MINUTE;
Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/AbstractJMSManager.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/AbstractJMSManager.java?rev=1225860&r1=1225859&r2=1225860&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/AbstractJMSManager.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/AbstractJMSManager.java Fri Dec 30 16:52:48 2011
@@ -32,14 +32,29 @@ import java.io.Serializable;
import java.util.Properties;
/**
- *
+ * Base Class for Managers of JMS connections.
*/
public abstract class AbstractJMSManager extends AbstractManager {
+ /**
+ * The Constructor.
+ * @param name The name of the Appender.
+ */
public AbstractJMSManager(String name) {
super(name);
}
+ /**
+ * Create the InitialContext.
+ * @param factoryName The fully qualified class name of the InitialContextFactory.
+ * @param providerURL The URL of the provider to use.
+ * @param urlPkgPrefixes A colon-separated list of package prefixes for the class name of the factory class that
+ * will create a URL context factory
+ * @param securityPrincipalName The name of the identity of the Principal.
+ * @param securityCredentials The security credentials of the Principal.
+ * @return the InitialContext.
+ * @throws NamingException if a naming error occurs.
+ */
protected static Context createContext(String factoryName, String providerURL, String urlPkgPrefixes,
String securityPrincipalName, String securityCredentials)
throws NamingException {
@@ -49,15 +64,32 @@ public abstract class AbstractJMSManager
return new InitialContext(props);
}
+ /**
+ * Looks up the name in the context.
+ * @param ctx The Context.
+ * @param name The name to locate.
+ * @return The object to be located.
+ * @throws NamingException If an error occurs locating the name.
+ */
protected static Object lookup(Context ctx, String name) throws NamingException {
try {
return ctx.lookup(name);
- } catch(NameNotFoundException e) {
+ } catch (NameNotFoundException e) {
LOGGER.error("Could not find name [" + name + "].");
throw e;
}
}
+ /**
+ * Sets up the properties to pass to the InitialContext.
+ * @param factoryName The fully qualified class name of the InitialContextFactory.
+ * @param providerURL The URL of the provider to use.
+ * @param urlPkgPrefixes A colon-separated list of package prefixes for the class name of the factory class that
+ * will create a URL context factory
+ * @param securityPrincipalName The name of the identity of the Principal.
+ * @param securityCredentials The security credentials of the Principal.
+ * @return The Properties.
+ */
protected static Properties getEnvironment(String factoryName, String providerURL, String urlPkgPrefixes,
String securityPrincipalName, String securityCredentials) {
Properties props = new Properties();
@@ -72,23 +104,34 @@ public abstract class AbstractJMSManager
if (urlPkgPrefixes != null) {
props.put(Context.URL_PKG_PREFIXES, urlPkgPrefixes);
}
- if (securityPrincipalName != null) {
- props.put(Context.SECURITY_PRINCIPAL, securityPrincipalName);
- if (securityCredentials != null) {
- props.put(Context.SECURITY_CREDENTIALS, securityCredentials);
- } else {
- LOGGER.warn("SecurityPrincipalName has been set without SecurityCredentials. " +
+ if (securityPrincipalName != null) {
+ props.put(Context.SECURITY_PRINCIPAL, securityPrincipalName);
+ if (securityCredentials != null) {
+ props.put(Context.SECURITY_CREDENTIALS, securityCredentials);
+ } else {
+ LOGGER.warn("SecurityPrincipalName has been set without SecurityCredentials. " +
"This is likely to cause problems.");
- }
- }
+ }
+ }
return props;
}
return null;
}
- public abstract void send(Serializable Object) throws Exception;
-
-
+ /**
+ * Send the message.
+ * @param object The Object to sent.
+ * @throws Exception if an error occurs.
+ */
+ public abstract void send(Serializable object) throws Exception;
+
+ /**
+ * Send the Object.
+ * @param object The Object to send.
+ * @param session The Session.
+ * @param producer The MessageProducer.
+ * @throws Exception if an error occurs.
+ */
public synchronized void send(Serializable object, Session session, MessageProducer producer) throws Exception {
try {
Message msg;
Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/AbstractJMSReceiver.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/AbstractJMSReceiver.java?rev=1225860&r1=1225859&r2=1225860&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/AbstractJMSReceiver.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/AbstractJMSReceiver.java Fri Dec 30 16:52:48 2011
@@ -32,9 +32,15 @@ import javax.naming.NamingException;
*/
public abstract class AbstractJMSReceiver extends AbstractServer implements javax.jms.MessageListener {
-
+ /**
+ * Logger to capture diagnostics.
+ */
protected Logger logger = LogManager.getLogger(this.getClass().getName());
+ /**
+ * Listener that receives the event.
+ * @param message The received message.
+ */
public void onMessage(javax.jms.Message message) {
try {
@@ -51,7 +57,13 @@ public abstract class AbstractJMSReceive
}
}
-
+ /**
+ * Looks up an object from the Context.
+ * @param ctx The Context.
+ * @param name The name of the object to locate.
+ * @return The object.
+ * @throws NamingException if an error occurs.
+ */
protected Object lookup(Context ctx, String name) throws NamingException {
try {
return ctx.lookup(name);
Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/AbstractSocketManager.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/AbstractSocketManager.java?rev=1225860&r1=1225859&r2=1225860&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/AbstractSocketManager.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/AbstractSocketManager.java Fri Dec 30 16:52:48 2011
@@ -26,10 +26,27 @@ import java.net.InetAddress;
*/
public abstract class AbstractSocketManager extends OutputStreamManager {
+ /**
+ * The internet address of the host.
+ */
protected final InetAddress address;
+ /**
+ * The name of the host.
+ */
protected final String host;
+ /**
+ * The port on the host.
+ */
protected final int port;
+ /**
+ * The Constructor.
+ * @param name The unique name of this connection.
+ * @param os The OutputStream to manage.
+ * @param addr The internet address.
+ * @param host The target host name.
+ * @param port The target port number.
+ */
public AbstractSocketManager(String name, OutputStream os, InetAddress addr, String host, int port) {
super(os, name);
this.address = addr;
Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/DatagramOutputStream.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/DatagramOutputStream.java?rev=1225860&r1=1225859&r2=1225860&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/DatagramOutputStream.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/DatagramOutputStream.java Fri Dec 30 16:52:48 2011
@@ -29,36 +29,45 @@ import java.net.SocketException;
import java.net.UnknownHostException;
/**
- *
+ * OutputStream for UDP connections.
*/
public class DatagramOutputStream extends OutputStream {
+ /**
+ * Allow subclasses access to the status logger without creating another instance.
+ */
+ protected static final Logger LOGGER = StatusLogger.getLogger();
+
+ private static final int SHIFT_1 = 8;
+ private static final int SHIFT_2 = 16;
+ private static final int SHIFT_3 = 24;
+
private DatagramSocket ds;
private InetAddress address;
private int port;
private byte[] data;
- /**
- * Allow subclasses access to the status logger without creating another instance.
+ /**
+ * The Constructor.
+ * @param host The host to connect to.
+ * @param port The port on the host.
*/
- protected static final Logger logger = StatusLogger.getLogger();
-
public DatagramOutputStream(String host, int port) {
this.port = port;
try {
address = InetAddress.getByName(host);
} catch (UnknownHostException ex) {
String msg = "Could not find host " + host;
- logger.error(msg, ex);
+ LOGGER.error(msg, ex);
throw new AppenderRuntimeException(msg, ex);
}
try {
ds = new DatagramSocket();
- } catch(SocketException ex) {
+ } catch (SocketException ex) {
String msg = "Could not instantiate DatagramSocket to " + host;
- logger.error(msg, ex);
+ LOGGER.error(msg, ex);
throw new AppenderRuntimeException(msg, ex);
}
}
@@ -70,7 +79,7 @@ public class DatagramOutputStream extend
@Override
public synchronized void write(int i) throws IOException {
- copy(new byte[] { (byte)(i >>> 24),(byte)(i >>> 16),(byte)(i >>> 8),(byte)i}, 0, 4);
+ copy(new byte[] {(byte) (i >>> SHIFT_3), (byte) (i >>> SHIFT_2), (byte) (i >>> SHIFT_1), (byte) i}, 0, 4);
}
@Override
Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/DatagramSocketManager.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/DatagramSocketManager.java?rev=1225860&r1=1225859&r2=1225860&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/DatagramSocketManager.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/DatagramSocketManager.java Fri Dec 30 16:52:48 2011
@@ -21,12 +21,29 @@ import org.apache.logging.log4j.core.app
import java.io.OutputStream;
/**
- *
+ * Socket Manager for UDP connections.
*/
public class DatagramSocketManager extends AbstractSocketManager {
private static ManagerFactory factory = new DatagramSocketManagerFactory();
+ /**
+ * The Constructor.
+ * @param os The OutputStream.
+ * @param name The unique name of the connection.
+ * @param host The host to connect to.
+ * @param port The port on the host.
+ */
+ protected DatagramSocketManager(OutputStream os, String name, String host, int port) {
+ super(name, os, null, host, port);
+ }
+
+ /**
+ * Obtain a SocketManager.
+ * @param host The host to connect to.
+ * @param port The port on the host.
+ * @return A DatagramSocketManager.
+ */
public static DatagramSocketManager getSocketManager(String host, int port) {
if (host == null || host.length() == 0) {
throw new IllegalArgumentException("A host name is required");
@@ -34,18 +51,16 @@ public class DatagramSocketManager exten
if (port <= 0) {
throw new IllegalArgumentException("A port value is required");
}
- return (DatagramSocketManager) getManager("UDP:" + host +":" + port, factory,
+ return (DatagramSocketManager) getManager("UDP:" + host + ":" + port, factory,
new FactoryData(host, port));
}
- public DatagramSocketManager(OutputStream os, String name, String host, int port) {
- super(name, os, null, host, port);
- }
-
-
+ /**
+ * Data for the factory.
+ */
private static class FactoryData {
- String host;
- int port;
+ private String host;
+ private int port;
public FactoryData(String host, int port) {
this.host = host;
@@ -53,6 +68,9 @@ public class DatagramSocketManager exten
}
}
+ /**
+ * Factory to create the DatagramSocketManager.
+ */
private static class DatagramSocketManagerFactory implements ManagerFactory<DatagramSocketManager, FactoryData> {
public DatagramSocketManager createManager(String name, FactoryData data) {
Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/Facility.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/Facility.java?rev=1225860&r1=1225859&r2=1225860&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/Facility.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/Facility.java Fri Dec 30 16:52:48 2011
@@ -48,29 +48,53 @@ package org.apache.logging.log4j.core.ne
* 23 local use 7 (local7)<br>
*/
public enum Facility {
+ /** Kernel messages. */
KERN(0),
+ /** User level messages. */
USER(1),
+ /** Mail system. */
MAIL(2),
+ /** System daemons. */
DAEMON(3),
+ /** Security/Authorization messages. */
AUTH(4),
+ /** Messages generated by syslogd. */
SYSLOG(5),
+ /** Line printer subsystem. */
LPR(6),
+ /** Network news subsystem. */
NEWS(7),
+ /** UUCP subsystem. */
UUCP(8),
+ /** Clock daemon. */
CRON(9),
+ /** Security/Authorization messages. */
AUTHPRIV(10),
+ /** FTP daemon. */
FTP(11),
+ /** NTP subsystem. */
NTP(12),
+ /** Log audit. */
LOG_AUDIT(13),
+ /** Log alert. */
LOG_ALERT(14),
+ /** Clock daemon. */
CLOCK(15),
+ /** Local use 0. */
LOCAL0(16),
+ /** Local use 1. */
LOCAL1(17),
+ /** Local use 2. */
LOCAL2(18),
+ /** Local use 3. */
LOCAL3(19),
+ /** Local use 4. */
LOCAL4(20),
+ /** Local use 5. */
LOCAL5(21),
+ /** Local use 6. */
LOCAL6(22),
+ /** Local use 7. */
LOCAL7(23);
private final int code;
@@ -79,11 +103,20 @@ public enum Facility {
this.code = code;
}
+ /**
+ * Retrieve the value of the enumeration.
+ * @return The value associated with the enumeration.
+ */
public int getCode() {
return this.code;
}
- public boolean equals(String name) {
+ /**
+ * Determine if this enumeration matches the specified name (ignoring case).
+ * @param name The name to check.
+ * @return true if the name matches this enumeration, ignoring case.
+ */
+ public boolean isEqual(String name) {
return this.name().equalsIgnoreCase(name);
}
Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/JMSQueueManager.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/JMSQueueManager.java?rev=1225860&r1=1225859&r2=1225860&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/JMSQueueManager.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/JMSQueueManager.java Fri Dec 30 16:52:48 2011
@@ -30,17 +30,44 @@ import javax.naming.NamingException;
import java.io.Serializable;
/**
- *
+ * Manager for a JMS Queue.
*/
public class JMSQueueManager extends AbstractJMSManager {
+ private static ManagerFactory factory = new JMSQueueManagerFactory();
+
private QueueConnection queueConnection;
private QueueSession queueSession;
private QueueSender queueSender;
+ /**
+ * The Constructor.
+ * @param name The unique name of the connection.
+ * @param conn The QueueConnection.
+ * @param sess The QueueSession.
+ * @param sender The QueueSender.
+ */
+ protected JMSQueueManager(String name, QueueConnection conn, QueueSession sess, QueueSender sender) {
+ super(name);
+ this.queueConnection = conn;
+ this.queueSession = sess;
+ this.queueSender = sender;
+ }
- private static ManagerFactory factory = new JMSTopicManagerFactory();
-
+ /**
+ * Obtain a JMSQueueManager.
+ * @param factoryName The fully qualified class name of the InitialContextFactory.
+ * @param providerURL The URL of the provider to use.
+ * @param urlPkgPrefixes A colon-separated list of package prefixes for the class name of the factory class that
+ * will create a URL context factory
+ * @param securityPrincipalName The name of the identity of the Principal.
+ * @param securityCredentials The security credentials of the Principal.
+ * @param factoryBindingName The name to locate in the Context that provides the QueueConnectionFactory.
+ * @param queueBindingName The name to use to locate the Queue.
+ * @param userName The userid to use to create the Queue Connection.
+ * @param password The password to use to create the Queue Connection.
+ * @return The JMSQueueManager.
+ */
public static JMSQueueManager getJMSQueueManager(String factoryName, String providerURL, String urlPkgPrefixes,
String securityPrincipalName, String securityCredentials,
String factoryBindingName, String queueBindingName,
@@ -60,13 +87,6 @@ public class JMSQueueManager extends Abs
securityPrincipalName, securityCredentials, factoryBindingName, queueBindingName, userName, password));
}
- public JMSQueueManager(String name, QueueConnection conn, QueueSession sess, QueueSender sender) {
- super(name);
- this.queueConnection = conn;
- this.queueSession = sess;
- this.queueSender = sender;
- }
-
@Override
public void send(Serializable object) throws Exception {
super.send(object, queueSession, queueSender);
@@ -86,17 +106,19 @@ public class JMSQueueManager extends Abs
}
}
-
+ /**
+ * Data for the factory.
+ */
private static class FactoryData {
- String factoryName;
- String providerURL;
- String urlPkgPrefixes;
- String securityPrincipalName;
- String securityCredentials;
- String factoryBindingName;
- String queueBindingName;
- String userName;
- String password;
+ private String factoryName;
+ private String providerURL;
+ private String urlPkgPrefixes;
+ private String securityPrincipalName;
+ private String securityCredentials;
+ private String factoryBindingName;
+ private String queueBindingName;
+ private String userName;
+ private String password;
public FactoryData(String factoryName, String providerURL, String urlPkgPrefixes, String securityPrincipalName,
String securityCredentials, String factoryBindingName, String queueBindingName,
@@ -113,7 +135,10 @@ public class JMSQueueManager extends Abs
}
}
- private static class JMSTopicManagerFactory implements ManagerFactory<JMSQueueManager, FactoryData> {
+ /**
+ * Factory to create the JMSQueueManager.
+ */
+ private static class JMSQueueManagerFactory implements ManagerFactory<JMSQueueManager, FactoryData> {
public JMSQueueManager createManager(String name, FactoryData data) {
try {
@@ -133,9 +158,9 @@ public class JMSQueueManager extends Abs
return new JMSQueueManager(name, conn, sess, sender);
} catch (NamingException ex) {
-
+ LOGGER.error("Unable to locate resource", ex);
} catch (JMSException jmsex) {
-
+ LOGGER.error("Unable to establish connection", jmsex);
}
return null;
Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/JMSQueueReceiver.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/JMSQueueReceiver.java?rev=1225860&r1=1225859&r2=1225860&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/JMSQueueReceiver.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/JMSQueueReceiver.java Fri Dec 30 16:52:48 2011
@@ -35,6 +35,39 @@ import java.io.InputStreamReader;
*/
public class JMSQueueReceiver extends AbstractJMSReceiver {
+ /**
+ * Constructor.
+ * @param qcfBindingName The QueueConnectionFactory binding name.
+ * @param queueBindingName The Queue binding name.
+ * @param username The userid to connect to the queue.
+ * @param password The password to connect to the queue.
+ */
+ public JMSQueueReceiver(String qcfBindingName, String queueBindingName, String username, String password) {
+
+ try {
+ Context ctx = new InitialContext();
+ QueueConnectionFactory queueConnectionFactory;
+ queueConnectionFactory = (QueueConnectionFactory) lookup(ctx, qcfBindingName);
+ QueueConnection queueConnection = queueConnectionFactory.createQueueConnection(username, password);
+ queueConnection.start();
+ QueueSession queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ Queue queue = (Queue) ctx.lookup(queueBindingName);
+ QueueReceiver queueReceiver = queueSession.createReceiver(queue);
+ queueReceiver.setMessageListener(this);
+ } catch (JMSException e) {
+ logger.error("Could not read JMS message.", e);
+ } catch (NamingException e) {
+ logger.error("Could not read JMS message.", e);
+ } catch (RuntimeException e) {
+ logger.error("Could not read JMS message.", e);
+ }
+ }
+
+ /**
+ * Main startup for the receiver.
+ * @param args The command line arguments.
+ * @throws Exception if an error occurs.
+ */
public static void main(String[] args) throws Exception {
if (args.length != 4) {
usage("Wrong number of arguments.");
@@ -60,26 +93,6 @@ public class JMSQueueReceiver extends Ab
}
}
- public JMSQueueReceiver(String qcfBindingName, String queueBindingName, String username, String password) {
-
- try {
- Context ctx = new InitialContext();
- QueueConnectionFactory queueConnectionFactory;
- queueConnectionFactory = (QueueConnectionFactory) lookup(ctx,qcfBindingName);
- QueueConnection queueConnection = queueConnectionFactory.createQueueConnection(username, password);
- queueConnection.start();
- QueueSession queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
- Queue queue = (Queue) ctx.lookup(queueBindingName);
- QueueReceiver queueReceiver = queueSession.createReceiver(queue);
- queueReceiver.setMessageListener(this);
- } catch (JMSException e) {
- logger.error("Could not read JMS message.", e);
- } catch (NamingException e) {
- logger.error("Could not read JMS message.", e);
- } catch (RuntimeException e) {
- logger.error("Could not read JMS message.", e);
- }
- }
private static void usage(String msg) {
System.err.println(msg);
Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/JMSTopicManager.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/JMSTopicManager.java?rev=1225860&r1=1225859&r2=1225860&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/JMSTopicManager.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/JMSTopicManager.java Fri Dec 30 16:52:48 2011
@@ -30,17 +30,44 @@ import javax.naming.NamingException;
import java.io.Serializable;
/**
- *
+ * Manager for JMS Topic connections.
*/
public class JMSTopicManager extends AbstractJMSManager {
+ private static ManagerFactory factory = new JMSTopicManagerFactory();
+
private TopicConnection topicConnection;
private TopicSession topicSession;
private TopicPublisher topicPublisher;
+ /**
+ * Constructor.
+ * @param name The unique name of the connection.
+ * @param conn The TopicConnection.
+ * @param sess The TopicSession.
+ * @param pub The TopicPublisher.
+ */
+ public JMSTopicManager(String name, TopicConnection conn, TopicSession sess, TopicPublisher pub) {
+ super(name);
+ this.topicConnection = conn;
+ this.topicSession = sess;
+ this.topicPublisher = pub;
+ }
- private static ManagerFactory factory = new JMSTopicManagerFactory();
-
+ /**
+ * Obtain a JSMTopicManager.
+ * @param factoryName The fully qualified class name of the InitialContextFactory.
+ * @param providerURL The URL of the provider to use.
+ * @param urlPkgPrefixes A colon-separated list of package prefixes for the class name of the factory class that
+ * will create a URL context factory
+ * @param securityPrincipalName The name of the identity of the Principal.
+ * @param securityCredentials The security credentials of the Principal.
+ * @param factoryBindingName The name to locate in the Context that provides the TopicConnectionFactory.
+ * @param topicBindingName The name to use to locate the Topic.
+ * @param userName The userid to use to create the Topic Connection.
+ * @param password The password to use to create the Topic Connection.
+ * @return A JMSTopicManager.
+ */
public static JMSTopicManager getJMSTopicManager(String factoryName, String providerURL, String urlPkgPrefixes,
String securityPrincipalName, String securityCredentials,
String factoryBindingName, String topicBindingName,
@@ -60,12 +87,6 @@ public class JMSTopicManager extends Abs
securityPrincipalName, securityCredentials, factoryBindingName, topicBindingName, userName, password));
}
- public JMSTopicManager(String name, TopicConnection conn, TopicSession sess, TopicPublisher pub) {
- super(name);
- this.topicConnection = conn;
- this.topicSession = sess;
- this.topicPublisher = pub;
- }
@Override
public void send(Serializable object) throws Exception {
@@ -86,17 +107,19 @@ public class JMSTopicManager extends Abs
}
}
-
+ /**
+ * Data for the factory.
+ */
private static class FactoryData {
- String factoryName;
- String providerURL;
- String urlPkgPrefixes;
- String securityPrincipalName;
- String securityCredentials;
- String factoryBindingName;
- String topicBindingName;
- String userName;
- String password;
+ private String factoryName;
+ private String providerURL;
+ private String urlPkgPrefixes;
+ private String securityPrincipalName;
+ private String securityCredentials;
+ private String factoryBindingName;
+ private String topicBindingName;
+ private String userName;
+ private String password;
public FactoryData(String factoryName, String providerURL, String urlPkgPrefixes, String securityPrincipalName,
String securityCredentials, String factoryBindingName, String topicBindingName,
@@ -113,6 +136,9 @@ public class JMSTopicManager extends Abs
}
}
+ /**
+ * Factory to create a JMSTopicManager.
+ */
private static class JMSTopicManagerFactory implements ManagerFactory<JMSTopicManager, FactoryData> {
public JMSTopicManager createManager(String name, FactoryData data) {
Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/JMSTopicReceiver.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/JMSTopicReceiver.java?rev=1225860&r1=1225859&r2=1225860&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/JMSTopicReceiver.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/JMSTopicReceiver.java Fri Dec 30 16:52:48 2011
@@ -35,6 +35,38 @@ import java.io.InputStreamReader;
*/
public class JMSTopicReceiver extends AbstractJMSReceiver {
+ /**
+ * Constructor.
+ * @param tcfBindingName The TopicConnectionFactory binding name.
+ * @param topicBindingName The Topic binding name.
+ * @param username The userid to connect to the topic.
+ * @param password The password to connect to the topic.
+ */
+ public JMSTopicReceiver(String tcfBindingName, String topicBindingName, String username, String password) {
+ try {
+ Context ctx = new InitialContext();
+ TopicConnectionFactory topicConnectionFactory;
+ topicConnectionFactory = (TopicConnectionFactory) lookup(ctx, tcfBindingName);
+ TopicConnection topicConnection = topicConnectionFactory.createTopicConnection(username, password);
+ topicConnection.start();
+ TopicSession topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+ Topic topic = (Topic) ctx.lookup(topicBindingName);
+ TopicSubscriber topicSubscriber = topicSession.createSubscriber(topic);
+ topicSubscriber.setMessageListener(this);
+ } catch (JMSException e) {
+ logger.error("Could not read JMS message.", e);
+ } catch (NamingException e) {
+ logger.error("Could not read JMS message.", e);
+ } catch (RuntimeException e) {
+ logger.error("Could not read JMS message.", e);
+ }
+ }
+
+ /**
+ * Main startup for the receiver.
+ * @param args The command line arguments.
+ * @throws Exception if an error occurs.
+ */
public static void main(String[] args) throws Exception {
if (args.length != 4) {
usage("Wrong number of arguments.");
@@ -60,26 +92,6 @@ public class JMSTopicReceiver extends Ab
}
}
- public JMSTopicReceiver(String tcfBindingName, String topicBindingName, String username, String password) {
- try {
- Context ctx = new InitialContext();
- TopicConnectionFactory topicConnectionFactory;
- topicConnectionFactory = (TopicConnectionFactory) lookup(ctx, tcfBindingName);
- TopicConnection topicConnection = topicConnectionFactory.createTopicConnection(username, password);
- topicConnection.start();
- TopicSession topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
- Topic topic = (Topic) ctx.lookup(topicBindingName);
- TopicSubscriber topicSubscriber = topicSession.createSubscriber(topic);
- topicSubscriber.setMessageListener(this);
- } catch (JMSException e) {
- logger.error("Could not read JMS message.", e);
- } catch (NamingException e) {
- logger.error("Could not read JMS message.", e);
- } catch (RuntimeException e) {
- logger.error("Could not read JMS message.", e);
- }
- }
-
private static void usage(String msg) {
System.err.println(msg);
System.err.println("Usage: java " + JMSTopicReceiver.class.getName()
Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/Priority.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/Priority.java?rev=1225860&r1=1225859&r2=1225860&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/Priority.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/Priority.java Fri Dec 30 16:52:48 2011
@@ -26,27 +26,51 @@ public class Priority {
private final Facility facility;
private final Severity severity;
+ /**
+ * The Constructor.
+ * @param facility The Facility.
+ * @param severity The Severity.
+ */
public Priority(Facility facility, Severity severity) {
this.facility = facility;
this.severity = severity;
}
+ /**
+ * Return the priority value based on the Facility and Log Level.
+ * @param facility The Facility.
+ * @param level The Level.
+ * @return The integer value of the priority.
+ */
public static int getPriority(Facility facility, Level level) {
return facility.getCode() << 3 + Severity.getSeverity(level).getCode();
}
+ /**
+ * Return the Facility.
+ * @return the Facility.
+ */
public Facility getFacility() {
return facility;
}
+ /**
+ * Return the Severity.
+ * @return the Severity.
+ */
public Severity getSeverity() {
return severity;
}
+ /**
+ * Return the value of this Priority.
+ * @return the value of this Priority.
+ */
public int getValue() {
return facility.getCode() << 3 + severity.getCode();
}
+ @Override
public String toString() {
return Integer.toString(getValue());
}
Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/Protocol.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/Protocol.java?rev=1225860&r1=1225859&r2=1225860&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/Protocol.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/Protocol.java Fri Dec 30 16:52:48 2011
@@ -20,9 +20,9 @@ package org.apache.logging.log4j.core.ne
* Enumeration of the supported protocols.
*/
public enum Protocol {
- /** TCP Protocol */
+ /** TCP Protocol. */
TCP,
- /** UDP Protocol */
+ /** UDP Protocol. */
UDP;
/**
@@ -30,7 +30,7 @@ public enum Protocol {
* @param name The enumeration name to check.
* @return true if this enumeration has the specified name.
*/
- public boolean equals(String name) {
+ public boolean isEqual(String name) {
return this.name().equalsIgnoreCase(name);
}
}
Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/Severity.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/Severity.java?rev=1225860&r1=1225859&r2=1225860&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/Severity.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/Severity.java Fri Dec 30 16:52:48 2011
@@ -19,7 +19,7 @@ package org.apache.logging.log4j.core.ne
import org.apache.logging.log4j.Level;
/**
- * Severity values used by the Syslog system
+ * Severity values used by the Syslog system.
*
* Numerical Severity<br>
* Code<br>
@@ -34,13 +34,21 @@ import org.apache.logging.log4j.Level;
* 7 Debug: debug-level messages
*/
public enum Severity {
+ /** System is unusable. */
EMERG(0),
+ /** Action must be taken immediately. */
ALERT(1),
+ /** Critical conditions. */
CRITICAL(2),
+ /** Error conditions. */
ERROR(3),
+ /** Warning conditions. */
WARNING(4),
+ /** Normal but significant conditions. */
NOTICE(5),
+ /** Informational messages. */
INFO(6),
+ /** Debug level messages. */
DEBUG(7);
private final int code;
@@ -62,7 +70,7 @@ public enum Severity {
* @param name the name to match.
* @return true if the name matches, false otherwise.
*/
- public boolean equals(String name) {
+ public boolean isEqual(String name) {
return this.name().equalsIgnoreCase(name);
}
Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/SocketServer.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/SocketServer.java?rev=1225860&r1=1225859&r2=1225860&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/SocketServer.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/SocketServer.java Fri Dec 30 16:52:48 2011
@@ -45,18 +45,36 @@ import java.util.concurrent.ConcurrentHa
import java.util.concurrent.ConcurrentMap;
/**
- *
+ * Listens for events over a socket connection.
*/
public class SocketServer extends AbstractServer implements Runnable {
private static Logger logger;
+ private static final int MAX_PORT = 65534;
+
private boolean isActive = true;
private ServerSocket server;
private ConcurrentMap<Long, SocketHandler> handlers = new ConcurrentHashMap<Long, SocketHandler>();
+ /**
+ * Constructor.
+ * @param port to listen on.
+ * @throws IOException If an error occurs.
+ */
+ public SocketServer(int port) throws IOException {
+ server = new ServerSocket(port);
+ if (logger == null) {
+ logger = LogManager.getLogger(getClass().getName());
+ }
+ }
+ /**
+ * Main startup for the server.
+ * @param args The command line arguments.
+ * @throws Exception if an error occurs.
+ */
public static void main(String[] args) throws Exception {
if (args.length < 1 || args.length > 2) {
System.err.println("Incorrect number of arguments");
@@ -64,7 +82,7 @@ public class SocketServer extends Abstra
return;
}
int port = Integer.parseInt(args[0]);
- if (port <= 0 || port > 65535) {
+ if (port <= 0 || port >= MAX_PORT) {
System.err.println("Invalid port number");
printUsage();
return;
@@ -91,23 +109,20 @@ public class SocketServer extends Abstra
System.out.println("Usage: ServerSocket port configFilePath");
}
- public SocketServer(int port) throws IOException {
- server = new ServerSocket(port);
- if (logger == null) {
- logger = LogManager.getLogger(getClass().getName());
- }
- }
-
+ /**
+ * Shutdown the server.
+ */
public void shutdown() {
this.isActive = false;
Thread.currentThread().interrupt();
}
+ /**
+ * Accept incoming events and processes them.
+ */
public void run() {
- while(isActive)
- {
- try
- {
+ while (isActive) {
+ try {
// Accept incoming connections.
Socket clientSocket = server.accept();
@@ -118,9 +133,7 @@ public class SocketServer extends Abstra
SocketHandler handler = new SocketHandler(clientSocket);
handlers.put(handler.getId(), handler);
handler.start();
- }
- catch(IOException ioe)
- {
+ } catch (IOException ioe) {
System.out.println("Exception encountered on accept. Ignoring. Stack Trace :");
ioe.printStackTrace();
}
@@ -136,6 +149,9 @@ public class SocketServer extends Abstra
}
}
+ /**
+ * Thread that processes the events.
+ */
private class SocketHandler extends Thread {
private final ObjectInputStream ois;
@@ -155,7 +171,7 @@ public class SocketServer extends Abstra
boolean closed = false;
try {
try {
- while(!shutdown) {
+ while (!shutdown) {
LogEvent event = (LogEvent) ois.readObject();
if (event != null) {
log(event);
@@ -183,6 +199,9 @@ public class SocketServer extends Abstra
}
}
+ /**
+ * Factory that creates a Configuration for the server.
+ */
private static class ServerConfigurationFactory extends XMLConfigurationFactory {
private final String path;
Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/TCPSocketManager.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/TCPSocketManager.java?rev=1225860&r1=1225859&r2=1225860&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/TCPSocketManager.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/net/TCPSocketManager.java Fri Dec 30 16:52:48 2011
@@ -28,9 +28,19 @@ import java.net.Socket;
import java.net.UnknownHostException;
/**
- *
+ * Manager of TCP Socket connections.
*/
public class TCPSocketManager extends AbstractSocketManager {
+ /**
+ The default reconnection delay (30000 milliseconds or 30 seconds).
+ */
+ public static final int DEFAULT_RECONNECTION_DELAY = 30000;
+ /**
+ The default port number of remote logging server (4560).
+ */
+ private static final int DEFAULT_PORT = 4560;
+
+ private static ManagerFactory factory = new TCPSocketManagerFactory();
private final int reconnectionDelay;
@@ -41,17 +51,30 @@ public class TCPSocketManager extends Ab
private final boolean retry;
/**
- The default port number of remote logging server (4560).
+ * The Constructor.
+ * @param name The unique name of this connection.
+ * @param os The OutputStream.
+ * @param sock The Socket.
+ * @param addr The internet address of the host.
+ * @param host The name of the host.
+ * @param port The port number on the host.
+ * @param delay Reconnection interval.
*/
- private static final int DEFAULT_PORT = 4560;
+ public TCPSocketManager(String name, OutputStream os, Socket sock, InetAddress addr, String host, int port,
+ int delay) {
+ super(name, os, addr, host, port);
+ this.reconnectionDelay = delay;
+ this.socket = sock;
+ retry = delay > 0;
+ }
/**
- The default reconnection delay (30000 milliseconds or 30 seconds).
+ * Obtain a TCPSocketManager.
+ * @param host The host to connect to.
+ * @param port The port on the host.
+ * @param delay The interval to pause between retries.
+ * @return A TCPSocketManager.
*/
- public static final int DEFAULT_RECONNECTION_DELAY = 30000;
-
- private static ManagerFactory factory = new TCPSocketManagerFactory();
-
public static TCPSocketManager getSocketManager(String host, int port, int delay) {
if (host == null || host.length() == 0) {
throw new IllegalArgumentException("A host name is required");
@@ -62,16 +85,7 @@ public class TCPSocketManager extends Ab
if (delay == 0) {
delay = DEFAULT_RECONNECTION_DELAY;
}
- return (TCPSocketManager) getManager("TCP:" + host +":" + port, factory, new FactoryData(host, port, delay));
- }
-
-
- public TCPSocketManager(String name, OutputStream os, Socket sock, InetAddress addr, String host, int port,
- int delay) {
- super(name, os, addr, host, port);
- this.reconnectionDelay = delay;
- this.socket = sock;
- retry = delay > 0;
+ return (TCPSocketManager) getManager("TCP:" + host + ":" + port, factory, new FactoryData(host, port, delay));
}
@Override
@@ -101,9 +115,12 @@ public class TCPSocketManager extends Ab
}
}
+ /**
+ * Handles recoonecting to a Thread.
+ */
private class Reconnector extends Thread {
- boolean shutdown = false;
+ private boolean shutdown = false;
private final Object owner;
@@ -144,10 +161,13 @@ public class TCPSocketManager extends Ab
}
}
+ /**
+ * Data for the factory.
+ */
private static class FactoryData {
- String host;
- int port;
- int delay;
+ private String host;
+ private int port;
+ private int delay;
public FactoryData(String host, int port, int delay) {
this.host = host;
@@ -156,6 +176,9 @@ public class TCPSocketManager extends Ab
}
}
+ /**
+ * Factory to create a TCPSocketManager.
+ */
private static class TCPSocketManagerFactory implements ManagerFactory<TCPSocketManager, FactoryData> {
public TCPSocketManager createManager(String name, FactoryData data) {
@@ -172,5 +195,4 @@ public class TCPSocketManager extends Ab
return null;
}
}
-
}