You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by ca...@apache.org on 2007/04/12 17:41:15 UTC
svn commit: r527986 - in /logging/log4j/trunk/src/java/org/apache/log4j/net:
AddressBased.java NetworkBased.java PortBased.java SocketHubReceiver.java
SocketNode.java SocketNodeEventListener.java SocketReceiver.java
Author: carnold
Date: Thu Apr 12 08:41:14 2007
New Revision: 527986
URL: http://svn.apache.org/viewvc?view=rev&rev=527986
Log:
Bug 42092: Checkstyle fixes in o.a.l.net
Modified:
logging/log4j/trunk/src/java/org/apache/log4j/net/AddressBased.java
logging/log4j/trunk/src/java/org/apache/log4j/net/NetworkBased.java
logging/log4j/trunk/src/java/org/apache/log4j/net/PortBased.java
logging/log4j/trunk/src/java/org/apache/log4j/net/SocketHubReceiver.java
logging/log4j/trunk/src/java/org/apache/log4j/net/SocketNode.java
logging/log4j/trunk/src/java/org/apache/log4j/net/SocketNodeEventListener.java
logging/log4j/trunk/src/java/org/apache/log4j/net/SocketReceiver.java
Modified: logging/log4j/trunk/src/java/org/apache/log4j/net/AddressBased.java
URL: http://svn.apache.org/viewvc/logging/log4j/trunk/src/java/org/apache/log4j/net/AddressBased.java?view=diff&rev=527986&r1=527985&r2=527986
==============================================================================
--- logging/log4j/trunk/src/java/org/apache/log4j/net/AddressBased.java (original)
+++ logging/log4j/trunk/src/java/org/apache/log4j/net/AddressBased.java Thu Apr 12 08:41:14 2007
@@ -5,9 +5,9 @@
* 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.
@@ -19,17 +19,18 @@
/**
- * Net based entities that 'work with' an Address should consider implementing this
+ * Net based entities that 'work with' an Address
+ * should consider implementing this
* interface so that they can be treated generically.
*
- * @author Paul Smith <ps...@apache.org>
+ * @author Paul Smith (psmith@apache.org)
*
*/
-public interface AddressBased extends NetworkBased{
+public interface AddressBased extends NetworkBased {
/**
* Returns a String representation of the Address this instance
- * encompasses
+ * encompasses.
* @return String representation of the Address
*/
- public String getAddress();
+ String getAddress();
}
Modified: logging/log4j/trunk/src/java/org/apache/log4j/net/NetworkBased.java
URL: http://svn.apache.org/viewvc/logging/log4j/trunk/src/java/org/apache/log4j/net/NetworkBased.java?view=diff&rev=527986&r1=527985&r2=527986
==============================================================================
--- logging/log4j/trunk/src/java/org/apache/log4j/net/NetworkBased.java (original)
+++ logging/log4j/trunk/src/java/org/apache/log4j/net/NetworkBased.java Thu Apr 12 08:41:14 2007
@@ -1,15 +1,39 @@
+/*
+ * 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.log4j.net;
/**
* The parent of all the Network based interfaces.
- *
- *
- * @author Paul Smith <ps...@apache.org>
+ *
+ * @author Paul Smith (psmith@apache.org)
*
*/
public interface NetworkBased {
- public String getName();
-
- public boolean isActive();
+ /**
+ * Get name.
+ * @return name.
+ */
+ String getName();
+
+ /**
+ * Get if item is active.
+ * @return if true, item is active.
+ */
+ boolean isActive();
}
Modified: logging/log4j/trunk/src/java/org/apache/log4j/net/PortBased.java
URL: http://svn.apache.org/viewvc/logging/log4j/trunk/src/java/org/apache/log4j/net/PortBased.java?view=diff&rev=527986&r1=527985&r2=527986
==============================================================================
--- logging/log4j/trunk/src/java/org/apache/log4j/net/PortBased.java (original)
+++ logging/log4j/trunk/src/java/org/apache/log4j/net/PortBased.java Thu Apr 12 08:41:14 2007
@@ -5,9 +5,9 @@
* 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.
@@ -22,13 +22,13 @@
* Net based entities that 'work with' a Port should consider implementing this
* interface so that they can be treated generically.
*
- * @author Paul Smith <ps...@apache.org>
+ * @author Paul Smith (psmith@apache.org)
*
*/
public interface PortBased extends NetworkBased {
/**
- * Returns the Port # that this net based thing is using
+ * Returns the Port # that this net based thing is using.
* @return int port number
*/
- public int getPort();
+ int getPort();
}
Modified: logging/log4j/trunk/src/java/org/apache/log4j/net/SocketHubReceiver.java
URL: http://svn.apache.org/viewvc/logging/log4j/trunk/src/java/org/apache/log4j/net/SocketHubReceiver.java?view=diff&rev=527986&r1=527985&r2=527986
==============================================================================
--- logging/log4j/trunk/src/java/org/apache/log4j/net/SocketHubReceiver.java (original)
+++ logging/log4j/trunk/src/java/org/apache/log4j/net/SocketHubReceiver.java Thu Apr 12 08:41:14 2007
@@ -5,9 +5,9 @@
* 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.
@@ -30,94 +30,152 @@
/**
SocketHubReceiver receives a remote logging event on a configured
- socket and "posts" it to a LoggerRepository as if the event was
- generated locally. This class is designed to receive events from
+ socket and "posts" it to a LoggerRepository as if the event was
+ generated locally. This class is designed to receive events from
the SocketHubAppender class (or classes that send compatible events).
-
- <p>Once the event has been "posted", it will be handled by the
+
+ <p>Once the event has been "posted", it will be handled by the
appenders currently configured in the LoggerRespository.
-
+
@author Mark Womack
@author Ceki Gülcü
- @author Paul Smith <ps...@apache.org>
+ @author Paul Smith (psmith@apache.org)
@since 1.3
*/
public class SocketHubReceiver
extends Receiver implements SocketNodeEventListener, PortBased {
-
+
+ /**
+ * Default reconnection delay.
+ */
static final int DEFAULT_RECONNECTION_DELAY = 30000;
+ /**
+ * Host.
+ */
protected String host;
+
+ /**
+ * Port.
+ */
protected int port;
+ /**
+ * Reconnection delay.
+ */
protected int reconnectionDelay = DEFAULT_RECONNECTION_DELAY;
+
+ /**
+ * Active.
+ */
protected boolean active = false;
+
+ /**
+ * Connector.
+ */
protected Connector connector;
-
+
+ /**
+ * Socket.
+ */
protected Socket socket;
-
+
+ /**
+ * Listener list.
+ */
private List listenerList = Collections.synchronizedList(new ArrayList());
-
- public SocketHubReceiver() { }
-
- public SocketHubReceiver(String _host, int _port) {
- host = _host;
- port = _port;
- }
-
- public SocketHubReceiver(String _host, int _port, LoggerRepository _repository) {
- host = _host;
- port = _port;
- repository = _repository;
+
+ /**
+ * Create new instance.
+ */
+ public SocketHubReceiver() {
+ super();
+ }
+
+ /**
+ * Create new instance.
+ * @param h host
+ * @param p port
+ */
+ public SocketHubReceiver(final String h,
+ final int p) {
+ super();
+ host = h;
+ port = p;
+ }
+
+ /**
+ * Create new instance.
+ * @param h host
+ * @param p port
+ * @param repo logger repository
+ */
+ public SocketHubReceiver(final String h,
+ final int p,
+ final LoggerRepository repo) {
+ super();
+ host = h;
+ port = p;
+ repository = repo;
}
-
+
/**
* Adds a SocketNodeEventListener to this receiver to be notified
- * of SocketNode events
- * @param l
+ * of SocketNode events.
+ * @param l listener
*/
- public void addSocketNodeEventListener(SocketNodeEventListener l){
- listenerList.add(l);
+ public void addSocketNodeEventListener(final SocketNodeEventListener l) {
+ listenerList.add(l);
}
-
+
/**
* Removes a specific SocketNodeEventListener from this instance
* so that it will no longer be notified of SocketNode events.
- * @param l
+ * @param l listener
*/
- public void removeSocketNodeEventListener(SocketNodeEventListener l){
- listenerList.remove(l);
+ public void removeSocketNodeEventListener(
+ final SocketNodeEventListener l) {
+ listenerList.remove(l);
}
-
+
/**
- Get the remote host to connect to for logging events. */
+ Get the remote host to connect to for logging events.
+ @return host
+ */
public String getHost() {
return host;
}
-
+
/**
* Configures the Host property, this will require activateOptions
* to be called for this to take effect.
- * @param host
+ * @param remoteHost address of remote host.
*/
- public void setHost(String host){
- this.host = host;
+ public void setHost(final String remoteHost) {
+ this.host = remoteHost;
}
/**
- Set the remote host to connect to for logging events. */
- public void setPort(String _host) {
- host = _host;
+ Set the remote host to connect to for logging events.
+ Equivalent to setHost.
+ @param remoteHost address of remote host.
+ */
+ public void setPort(final String remoteHost) {
+ host = remoteHost;
}
-
+
/**
- Get the remote port to connect to for logging events. */
+ Get the remote port to connect to for logging events.
+ @return port
+ */
public int getPort() {
return port;
}
-
+
/**
- Set the remote port to connect to for logging events. */
- public void setPort(int _port) {
- port = _port;
+ Set the remote port to connect to for logging events.
+ @param p port
+ */
+ public void setPort(final int p) {
+ this.port = p;
}
/**
@@ -128,54 +186,59 @@
<p>Setting this option to zero turns off reconnection
capability.
+ @param delay milliseconds to wait or zero to not reconnect.
*/
- public void setReconnectionDelay(int delay) {
+ public void setReconnectionDelay(final int delay) {
int oldValue = this.reconnectionDelay;
this.reconnectionDelay = delay;
- firePropertyChange("reconnectionDelay", oldValue,this.reconnectionDelay);
+ firePropertyChange("reconnectionDelay", oldValue, this.reconnectionDelay);
}
/**
Returns value of the <b>ReconnectionDelay</b> option.
+ @return value of reconnection delay option.
*/
public int getReconnectionDelay() {
return reconnectionDelay;
}
-
+
/**
* Returns true if the receiver is the same class and they are
* configured for the same properties, and super class also considers
* them to be equivalent. This is used by PluginRegistry when determining
* if the a similarly configured receiver is being started.
- *
+ *
* @param testPlugin The plugin to test equivalency against.
* @return boolean True if the testPlugin is equivalent to this plugin.
*/
- public boolean isEquivalent(Plugin testPlugin) {
+ public boolean isEquivalent(final Plugin testPlugin) {
if (testPlugin != null && testPlugin instanceof SocketHubReceiver) {
- SocketHubReceiver sReceiver = (SocketHubReceiver)testPlugin;
+ SocketHubReceiver sReceiver = (SocketHubReceiver) testPlugin;
- return (port == sReceiver.getPort() &&
- host.equals(sReceiver.getHost()) &&
- reconnectionDelay == sReceiver.getReconnectionDelay() &&
- super.isEquivalent(testPlugin));
+ return (port == sReceiver.getPort()
+ && host.equals(sReceiver.getHost())
+ && reconnectionDelay == sReceiver.getReconnectionDelay()
+ && super.isEquivalent(testPlugin));
}
-
return false;
}
-
+
/**
- Returns true if this receiver is active. */
+ Returns true if this receiver is active.
+ @return true if receiver is active
+ */
public synchronized boolean isActive() {
return active;
}
-
+
/**
- Sets the flag to indicate if receiver is active or not. */
- protected synchronized void setActive(boolean _active) {
- active = _active;
+ Sets the flag to indicate if receiver is active or not.
+ @param b new value
+ */
+ protected synchronized void setActive(final boolean b) {
+ active = b;
}
-
+
/**
Starts the SocketReceiver with the current options. */
public void activateOptions() {
@@ -184,40 +247,48 @@
fireConnector(false);
}
}
-
+
/**
Called when the receiver should be stopped. Closes the socket */
public synchronized void shutdown() {
// mark this as no longer running
active = false;
-
+
// close the socket
try {
- if (socket != null)
+ if (socket != null) {
socket.close();
+ }
} catch (Exception e) {
// ignore for now
}
socket = null;
-
+
// stop the connector
- if(connector != null) {
+ if (connector != null) {
connector.interrupted = true;
connector = null; // allow gc
}
}
-
+
/**
Listen for a socketClosedEvent from the SocketNode. Reopen the
- socket if this receiver is still active. */
- public void socketClosedEvent(Exception e) {
- // we clear the connector object here so that it actually does reconnect if the
- // remote socket dies.
- connector = null;
+ socket if this receiver is still active.
+ @param e exception not used.
+ */
+ public void socketClosedEvent(final Exception e) {
+ // we clear the connector object here
+ // so that it actually does reconnect if the
+ // remote socket dies.
+ connector = null;
fireConnector(true);
}
-
- private synchronized void fireConnector(boolean isReconnect) {
+
+ /**
+ * Fire connectors.
+ * @param isReconnect true if reconnect.
+ */
+ private synchronized void fireConnector(final boolean isReconnect) {
if (active && connector == null) {
getLogger().debug("Starting a new connector thread.");
connector = new Connector(isReconnect);
@@ -226,22 +297,27 @@
connector.start();
}
}
-
- private synchronized void setSocket(Socket _socket) {
+
+ /**
+ * Set socket.
+ * @param newSocket new value for socket.
+ */
+ private synchronized void setSocket(final Socket newSocket) {
connector = null;
- socket = _socket;
+ socket = newSocket;
SocketNode node = new SocketNode(socket, this);
node.addSocketNodeEventListener(this);
- synchronized(listenerList){
- for (Iterator iter = listenerList.iterator(); iter.hasNext();) {
- SocketNodeEventListener listener = (SocketNodeEventListener) iter.next();
- node.addSocketNodeEventListener(listener);
- }
+ synchronized (listenerList) {
+ for (Iterator iter = listenerList.iterator(); iter.hasNext();) {
+ SocketNodeEventListener listener =
+ (SocketNodeEventListener) iter.next();
+ node.addSocketNodeEventListener(listener);
+ }
}
new Thread(node).start();
}
-
+
/**
The Connector will reconnect when the server becomes available
again. It does this by attempting to open a new connection every
@@ -252,45 +328,65 @@
connection is droppped.
@author Ceki Gülcü
- @since 0.8.4 */
- class Connector extends Thread {
+ */
+ private final class Connector extends Thread {
+ /**
+ * Interruption status.
+ */
boolean interrupted = false;
+ /**
+ * If true, then delay on next iteration.
+ */
boolean doDelay;
-
- public Connector(boolean isReconnect) {
+
+ /**
+ * Create new instance.
+ * @param isReconnect true if reconnecting.
+ */
+ public Connector(final boolean isReconnect) {
+ super();
doDelay = isReconnect;
}
-
+
+ /**
+ * Attempt to connect until interrupted.
+ */
public void run() {
- while(!interrupted) {
+ while (!interrupted) {
try {
- if (doDelay) {
- getLogger().debug("waiting for " + reconnectionDelay +
- " milliseconds before reconnecting.");
- sleep(reconnectionDelay);
- }
- doDelay = true;
- getLogger().debug("Attempting connection to "+ host);
- Socket socket = new Socket(host, port);
- setSocket(socket);
- getLogger().debug("Connection established. Exiting connector thread.");
- break;
- } catch(InterruptedException e) {
- getLogger().debug("Connector interrupted. Leaving loop.");
- return;
- } catch(java.net.ConnectException e) {
- getLogger().debug("Remote host {} refused connection.", host);
- } catch(IOException e) {
- getLogger().debug("Could not connect to {}. Exception is {}.", host, e);
- }
+ if (doDelay) {
+ getLogger().debug("waiting for " + reconnectionDelay
+ + " milliseconds before reconnecting.");
+ sleep(reconnectionDelay);
+ }
+ doDelay = true;
+ getLogger().debug("Attempting connection to " + host);
+ Socket s = new Socket(host, port);
+ setSocket(s);
+ getLogger().debug(
+ "Connection established. Exiting connector thread.");
+ break;
+ } catch (InterruptedException e) {
+ getLogger().debug("Connector interrupted. Leaving loop.");
+ return;
+ } catch (java.net.ConnectException e) {
+ getLogger().debug("Remote host {} refused connection.", host);
+ } catch (IOException e) {
+ getLogger().debug("Could not connect to {}. Exception is {}.",
+ host, e);
+ }
}
}
}
- public void socketOpened(String remoteInfo) {
+ /**
+ * This method does nothing.
+ * @param remoteInfo remote info.
+ */
+ public void socketOpened(final String remoteInfo) {
- // This method does nothing.
+ // This method does nothing.
}
-}
\ No newline at end of file
+}
Modified: logging/log4j/trunk/src/java/org/apache/log4j/net/SocketNode.java
URL: http://svn.apache.org/viewvc/logging/log4j/trunk/src/java/org/apache/log4j/net/SocketNode.java?view=diff&rev=527986&r1=527985&r2=527986
==============================================================================
--- logging/log4j/trunk/src/java/org/apache/log4j/net/SocketNode.java (original)
+++ logging/log4j/trunk/src/java/org/apache/log4j/net/SocketNode.java Thu Apr 12 08:41:14 2007
@@ -5,9 +5,9 @@
* 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.
@@ -45,29 +45,50 @@
local file and also resent them to a second socket node.
@author Ceki Gülcü
- @author Paul Smith <ps...@apache.org>
+ @author Paul Smith (psmith@apache.org)
@since 0.8.4
*/
public class SocketNode extends ComponentBase implements Runnable, Pauseable {
+ /**
+ * Paused state.
+ */
private boolean paused;
+ /**
+ * Socket.
+ */
private Socket socket;
+ /**
+ * Receiver.
+ */
private Receiver receiver;
+ /**
+ * List of listeners.
+ */
private List listenerList = Collections.synchronizedList(new ArrayList());
/**
- Constructor for socket and logger repository. */
- public SocketNode(Socket socket, LoggerRepository hierarchy) {
- this.socket = socket;
+ Constructor for socket and logger repository.
+ @param s socket
+ @param hierarchy logger repository
+ */
+ public SocketNode(final Socket s,
+ final LoggerRepository hierarchy) {
+ super();
+ this.socket = s;
this.repository = hierarchy;
}
/**
- Constructor for socket and reciever. */
- public SocketNode(Socket socket, Receiver receiver) {
- this.socket = socket;
- this.receiver = receiver;
+ Constructor for socket and receiver.
+ @param s socket
+ @param r receiver
+ */
+ public SocketNode(final Socket s, final Receiver r) {
+ super();
+ this.socket = s;
+ this.receiver = r;
}
/**
@@ -76,18 +97,20 @@
* @deprecated Now supports mutliple listeners, this method
* simply invokes the removeSocketNodeEventListener() to remove
* the listener, and then readds it.
+ * @param l listener
*/
- public void setListener(SocketNodeEventListener _listener) {
- removeSocketNodeEventListener(_listener);
- addSocketNodeEventListener(_listener);
+ public void setListener(final SocketNodeEventListener l) {
+ removeSocketNodeEventListener(l);
+ addSocketNodeEventListener(l);
}
/**
* Adds the listener to the list of listeners to be notified of the
- * respective event
+ * respective event.
* @param listener the listener to add to the list
*/
- public void addSocketNodeEventListener(SocketNodeEventListener listener) {
+ public void addSocketNodeEventListener(
+ final SocketNodeEventListener listener) {
listenerList.add(listener);
}
@@ -98,10 +121,14 @@
*
* @param listener the SocketNodeEventListener to remove
*/
- public void removeSocketNodeEventListener(SocketNodeEventListener listener) {
+ public void removeSocketNodeEventListener(
+ final SocketNodeEventListener listener) {
listenerList.remove(listener);
}
+ /**
+ * Deserialize events from socket until interrupted.
+ */
public void run() {
LoggingEvent event;
Logger remoteLogger;
@@ -186,45 +213,55 @@
}
// send event to listener, if configured
- if (listenerList.size()>0) {
+ if (listenerList.size() > 0) {
fireSocketClosedEvent(listenerException);
}
}
/**
- * Notifies all registered listeners regarding the closing of the Socket
- * @param listenerException
+ * Notifies all registered listeners regarding the closing of the Socket.
+ * @param listenerException listener exception
*/
- private void fireSocketClosedEvent(Exception listenerException) {
- synchronized(listenerList){
- for (Iterator iter = listenerList.iterator(); iter.hasNext();) {
- SocketNodeEventListener snel = (SocketNodeEventListener) iter.next();
- if (snel != null) {
- snel.socketClosedEvent(listenerException);
- }
- }
- }
+ private void fireSocketClosedEvent(final Exception listenerException) {
+ synchronized (listenerList) {
+ for (Iterator iter = listenerList.iterator(); iter.hasNext();) {
+ SocketNodeEventListener snel =
+ (SocketNodeEventListener) iter.next();
+ if (snel != null) {
+ snel.socketClosedEvent(listenerException);
+ }
+ }
+ }
}
/**
- * Notifies all registered listeners regarding the opening of a Socket
- * @param remoteInfo
- */
- private void fireSocketOpened(String remoteInfo) {
- synchronized(listenerList){
- for (Iterator iter = listenerList.iterator(); iter.hasNext();) {
- SocketNodeEventListener snel = (SocketNodeEventListener) iter.next();
- if (snel != null) {
- snel.socketOpened(remoteInfo);
- }
- }
- }
+ * Notifies all registered listeners regarding the opening of a Socket.
+ * @param remoteInfo remote info
+ */
+ private void fireSocketOpened(final String remoteInfo) {
+ synchronized (listenerList) {
+ for (Iterator iter = listenerList.iterator(); iter.hasNext();) {
+ SocketNodeEventListener snel =
+ (SocketNodeEventListener) iter.next();
+ if (snel != null) {
+ snel.socketOpened(remoteInfo);
+ }
+ }
+ }
}
- public void setPaused(boolean paused) {
- this.paused = paused;
+ /**
+ * Sets if node is paused.
+ * @param b new value
+ */
+ public void setPaused(final boolean b) {
+ this.paused = b;
}
+ /**
+ * Get if node is paused.
+ * @return true if pause.
+ */
public boolean isPaused() {
return this.paused;
}
Modified: logging/log4j/trunk/src/java/org/apache/log4j/net/SocketNodeEventListener.java
URL: http://svn.apache.org/viewvc/logging/log4j/trunk/src/java/org/apache/log4j/net/SocketNodeEventListener.java?view=diff&rev=527986&r1=527985&r2=527986
==============================================================================
--- logging/log4j/trunk/src/java/org/apache/log4j/net/SocketNodeEventListener.java (original)
+++ logging/log4j/trunk/src/java/org/apache/log4j/net/SocketNodeEventListener.java Thu Apr 12 08:41:14 2007
@@ -5,9 +5,9 @@
* 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.
@@ -25,18 +25,20 @@
instance is called back when the various events occur.
@author Mark Womack
- @author Paul Smith <ps...@apache.org>
+ @author Paul Smith (psmith@apache.org)
@since 1.3
*/
-public interface SocketNodeEventListener extends EventListener{
-
+public interface SocketNodeEventListener extends EventListener {
+
/**
* Called when the SocketNode is created and begins awaiting data.
- *
+ * @param remoteInfo remote info
*/
- public void socketOpened(String remoteInfo);
+ void socketOpened(String remoteInfo);
/**
- Called when the socket the node was given has been closed. */
- public void socketClosedEvent(Exception e);
+ Called when the socket the node was given has been closed.
+ @param e exception
+ */
+ void socketClosedEvent(Exception e);
}
Modified: logging/log4j/trunk/src/java/org/apache/log4j/net/SocketReceiver.java
URL: http://svn.apache.org/viewvc/logging/log4j/trunk/src/java/org/apache/log4j/net/SocketReceiver.java?view=diff&rev=527986&r1=527985&r2=527986
==============================================================================
--- logging/log4j/trunk/src/java/org/apache/log4j/net/SocketReceiver.java (original)
+++ logging/log4j/trunk/src/java/org/apache/log4j/net/SocketReceiver.java Thu Apr 12 08:41:14 2007
@@ -5,9 +5,9 @@
* 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.
@@ -46,43 +46,80 @@
appenders currently configured in the LoggerRespository.
@author Mark Womack
- @author Scott Deboy <sd...@apache.org>
- @author Paul Smith <ps...@apache.org>
+ @author Scott Deboy (sdeboy@apache.org)
+ @author Paul Smith (psmith@apache.org)
@since 1.3
*/
public class SocketReceiver extends Receiver implements Runnable, PortBased,
Pauseable {
+ /**
+ * socket map.
+ */
private Map socketMap = new HashMap();
+ /**
+ * Paused.
+ */
private boolean paused;
+ /**
+ * Thread.
+ */
private Thread rThread;
+ /**
+ * Port.
+ */
protected int port;
+ /**
+ * Server socket.
+ */
private ServerSocket serverSocket;
+ /**
+ * Socket list.
+ */
private Vector socketList = new Vector();
+ /**
+ * Listener.
+ */
private SocketNodeEventListener listener = null;
+ /**
+ * Listeners.
+ */
private List listenerList = Collections.synchronizedList(new ArrayList());
+ /**
+ * Create new instance.
+ */
public SocketReceiver() {
+ super();
}
- public SocketReceiver(int _port) {
- port = _port;
+ /**
+ * Create new instance.
+ * @param p port
+ */
+ public SocketReceiver(final int p) {
+ super();
+ port = p;
}
- public SocketReceiver(int _port, LoggerRepository _repository) {
- port = _port;
- repository = _repository;
+ /**
+ * Create new instance.
+ * @param p port
+ * @param repo logger repository
+ */
+ public SocketReceiver(final int p, final LoggerRepository repo) {
+ super();
+ this.port = p;
+ repository = repo;
}
- /**
- Get the port to receive logging events on. */
+ /** {@inheritDoc} */
public int getPort() {
return port;
}
- /**
- Set the port to receive logging events on. */
- public void setPort(int _port) {
- port = _port;
+ /** {@inheritDoc} */
+ public void setPort(final int p) {
+ port = p;
}
/**
@@ -90,11 +127,11 @@
* configured for the same properties, and super class also considers
* them to be equivalent. This is used by PluginRegistry when determining
* if the a similarly configured receiver is being started.
- *
+ *
* @param testPlugin The plugin to test equivalency against.
* @return boolean True if the testPlugin is equivalent to this plugin.
*/
- public boolean isEquivalent(Plugin testPlugin) {
+ public boolean isEquivalent(final Plugin testPlugin) {
if ((testPlugin != null) && testPlugin instanceof SocketReceiver) {
SocketReceiver sReceiver = (SocketReceiver) testPlugin;
@@ -215,17 +252,18 @@
while (!rThread.isInterrupted()) {
// if we have a socket, start watching it
if (socket != null) {
- getLogger().debug("socket not null - creating and starting socketnode");
+ getLogger().debug(
+ "socket not null - creating and starting socketnode");
socketList.add(socket);
SocketNode node = new SocketNode(socket, this);
- synchronized(listenerList){
- for (Iterator iter = listenerList.iterator(); iter
- .hasNext();) {
- SocketNodeEventListener listener = (SocketNodeEventListener) iter.next();
- node.addSocketNodeEventListener(listener);
-
- }
+ synchronized (listenerList) {
+ for (Iterator iter = listenerList.iterator();
+ iter.hasNext();) {
+ SocketNodeEventListener l =
+ (SocketNodeEventListener) iter.next();
+ node.addSocketNodeEventListener(l);
+ }
}
socketMap.put(socket, node);
new Thread(node).start();
@@ -268,7 +306,9 @@
public Vector getConnectedSocketDetails() {
Vector details = new Vector(socketList.size());
- for (Enumeration enumeration = socketList.elements(); enumeration.hasMoreElements();) {
+ for (Enumeration enumeration = socketList.elements();
+ enumeration.hasMoreElements();
+ ) {
Socket socket = (Socket) enumeration.nextElement();
details.add(
new SocketDetail(socket, (SocketNode) socketMap.get(socket)));
@@ -279,7 +319,7 @@
/**
* Returns the currently configured SocketNodeEventListener that
- * will be automatically set for each SocketNode created
+ * will be automatically set for each SocketNode created.
* @return SocketNodeEventListener currently configured
*
* @deprecated This receiver now supports multiple listeners
@@ -290,11 +330,12 @@
/**
* Adds the listener to the list of listeners to be notified of the
- * respective event
- * @param listener the listener to add to the list
+ * respective event.
+ * @param l the listener to add to the list
*/
- public void addSocketNodeEventListener(SocketNodeEventListener listener) {
- listenerList.add(listener);
+ public void addSocketNodeEventListener(
+ final SocketNodeEventListener l) {
+ listenerList.add(l);
}
/**
@@ -302,16 +343,17 @@
* listeners. If the listener has not been registered, then invoking
* this method has no effect.
*
- * @param listener the SocketNodeEventListener to remove
+ * @param l the SocketNodeEventListener to remove
*/
- public void removeSocketNodeEventListener(SocketNodeEventListener listener) {
- listenerList.remove(listener);
+ public void removeSocketNodeEventListener(
+ final SocketNodeEventListener l) {
+ listenerList.remove(l);
}
/**
* Sets the SocketNodeEventListener that will be used for each
- * created SocketNode
- * @param listener the listener to set on each creation of a SocketNode
+ * created SocketNode.
+ * @param l the listener to set on each creation of a SocketNode
* @deprecated This receiver now supports multiple listeners and
* so this method simply removes the listener (if there already)
* and readds it to the list.
@@ -319,61 +361,86 @@
* The passed listener will also be returned via the getListener()
* method still, but this is also deprecated
*/
- public void setListener(SocketNodeEventListener listener) {
- removeSocketNodeEventListener(listener);
- addSocketNodeEventListener(listener);
- this.listener = listener;
+ public void setListener(final SocketNodeEventListener l) {
+ removeSocketNodeEventListener(l);
+ addSocketNodeEventListener(l);
+ this.listener = l;
}
+ /** {@inheritDoc} */
public boolean isPaused() {
return paused;
}
- public void setPaused(boolean b) {
+ /** {@inheritDoc} */
+ public void setPaused(final boolean b) {
paused = b;
}
- public static class SocketDetail implements AddressBased, PortBased,
+ /**
+ * Socket detail.
+ */
+ public static final class SocketDetail implements AddressBased, PortBased,
Pauseable {
+ /**
+ * Address.
+ */
private String address;
+ /**
+ * Port.
+ */
private int port;
+ /**
+ * Socket node.
+ */
private SocketNode socketNode;
- private SocketDetail(Socket socket, SocketNode socketNode) {
+ /**
+ * Create new instance.
+ * @param socket socket
+ * @param node socket node
+ */
+ private SocketDetail(final Socket socket,
+ final SocketNode node) {
+ super();
this.address = socket.getInetAddress().getHostName();
this.port = socket.getPort();
- this.socketNode = socketNode;
+ this.socketNode = node;
}
+ /** {@inheritDoc} */
public String getAddress() {
return address;
}
+ /** {@inheritDoc} */
public int getPort() {
return port;
}
+ /** {@inheritDoc} */
public String getName() {
return "Socket";
}
+ /** {@inheritDoc} */
public boolean isActive() {
return true;
}
+ /** {@inheritDoc} */
public boolean isPaused() {
return socketNode.isPaused();
}
- public void setPaused(boolean paused) {
- socketNode.setPaused(paused);
+ /** {@inheritDoc} */
+ public void setPaused(final boolean b) {
+ socketNode.setPaused(b);
}
}
- /* (non-Javadoc)
- * @see org.apache.log4j.plugins.Receiver#doPost(org.apache.log4j.spi.LoggingEvent)
- */
- public void doPost(LoggingEvent event) {
- if(!isPaused()){
+ /** {@inheritDoc} */
+ public void doPost(final LoggingEvent event) {
+ if (!isPaused()) {
super.doPost(event);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org