The version of Apache log4j used by SoundHelix.
Clone
HTTPS:
git clone https://vervis.peers.community/repos/aEp6o
SSH:
git clone USERNAME@vervis.peers.community:aEp6o
Branches
Tags
- 1.3alpha-7
- CHAINSAW_2_SANDBOX_MERGE
- CORE_VERSION
- LEVEL_REPLACES_PRIORITY
- PREALPHA_1_3_AS_OF_2004_05_12
- PRE_CHAINSAW_MODEL_CONVERSION
- PRE_UGLI_MOVE
- TAG_CHAINSAW2_MOVE
- log4j-1.2.17
- log4j-1.2.17-rc1
- v1.3alpha8
- v1.3alpha8-temp
- v1_2_1
- v1_2_10-recalled
- v1_2_11
- v1_2_11_rc1
- v1_2_11rc3
- v1_2_12
- v1_2_12_rc1
- v1_2_12_rc2
- v1_2_12_rc3
- v1_2_12_rc4
- v1_2_12_rc5
- v1_2_12_rc6
- v1_2_13
- v1_2_13_rc1
- v1_2_13_rc2
- v1_2_13_site_update
- v1_2_14
- v1_2_14_maven
- v1_2_14_rc1
- v1_2_14_site_update
- v1_2_15
- v1_2_15_rc1
- v1_2_15_rc2
- v1_2_15_rc3
- v1_2_15_rc4
- v1_2_15_rc5
- v1_2_15_rc6
- v1_2_16
- v1_2_16_rc1
- v1_2_16_rc2
- v1_2_17
- v1_2_17-rc1
- v1_2_17_rc1
- v1_2_17_rc2
- v1_2_17_rc3
- v1_2_2
- v1_2_3
- v1_2_4
- v1_2_6
- v1_2_7
- v1_2_9
- v1_2_alpha0
- v1_2_alpha7
- v1_2beta1
- v1_2final
- v1_3alpha_1
- v1_3alpha_6
- v_1_0
- v_1_0_1
- v_1_0_4
- v_1_1
- v_1_1_1
- v_1_1_2
- v_1_1_3
- v_1_1_b1
- v_1_1b2
- v_1_1b3
- v_1_1b5
- v_1_1b6
- v_1_1b7
- v_1_2beta3
SocketHubReceiver.java
/*
* Copyright 1999-2006 The Apache Software Foundation.
*
* Licensed 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;
import java.io.IOException;
import java.net.Socket;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import org.apache.log4j.plugins.Plugin;
import org.apache.log4j.plugins.Receiver;
import org.apache.log4j.spi.LoggerRepository;
/**
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
the SocketHubAppender class (or classes that send compatible events).
<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 <psmith@apache.org>
@since 1.3
*/
public class SocketHubReceiver
extends Receiver implements SocketNodeEventListener, PortBased {
static final int DEFAULT_RECONNECTION_DELAY = 30000;
protected String host;
protected int port;
protected int reconnectionDelay = DEFAULT_RECONNECTION_DELAY;
protected boolean active = false;
protected Connector connector;
protected Socket socket;
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;
}
/**
* Adds a SocketNodeEventListener to this receiver to be notified
* of SocketNode events
* @param l
*/
public void addSocketNodeEventListener(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
*/
public void removeSocketNodeEventListener(SocketNodeEventListener l){
listenerList.remove(l);
}
/**
Get the remote host to connect to for logging events. */
public String getHost() {
return host;
}
/**
* Configures the Host property, this will require activateOptions
* to be called for this to take effect.
* @param host
*/
public void setHost(String host){
this.host = host;
}
/**
Set the remote host to connect to for logging events. */
public void setPort(String _host) {
host = _host;
}
/**
Get the remote port to connect to for logging events. */
public int getPort() {
return port;
}
/**
Set the remote port to connect to for logging events. */
public void setPort(int _port) {
port = _port;
}
/**
The <b>ReconnectionDelay</b> option takes a positive integer
representing the number of milliseconds to wait between each
failed connection attempt to the server. The default value of
this option is 30000 which corresponds to 30 seconds.
<p>Setting this option to zero turns off reconnection
capability.
*/
public void setReconnectionDelay(int delay) {
int oldValue = this.reconnectionDelay;
this.reconnectionDelay = delay;
firePropertyChange("reconnectionDelay", oldValue,this.reconnectionDelay);
}
/**
Returns value of the <b>ReconnectionDelay</b> 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) {
if (testPlugin != null && testPlugin instanceof SocketHubReceiver) {
SocketHubReceiver sReceiver = (SocketHubReceiver)testPlugin;
return (port == sReceiver.getPort() &&
host.equals(sReceiver.getHost()) &&
reconnectionDelay == sReceiver.getReconnectionDelay() &&
super.isEquivalent(testPlugin));
}
return false;
}
/**
Returns true if this 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;
}
/**
Starts the SocketReceiver with the current options. */
public void activateOptions() {
if (!isActive()) {
setActive(true);
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)
socket.close();
} catch (Exception e) {
// ignore for now
}
socket = null;
// stop the connector
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;
fireConnector(true);
}
private synchronized void fireConnector(boolean isReconnect) {
if (active && connector == null) {
getLogger().debug("Starting a new connector thread.");
connector = new Connector(isReconnect);
connector.setDaemon(true);
connector.setPriority(Thread.MIN_PRIORITY);
connector.start();
}
}
private synchronized void setSocket(Socket _socket) {
connector = null;
socket = _socket;
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);
}
}
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
<code>reconnectionDelay</code> milliseconds.
<p>It stops trying whenever a connection is established. It will
restart to try reconnect to the server when previpously open
connection is droppped.
@author Ceki Gülcü
@since 0.8.4 */
class Connector extends Thread {
boolean interrupted = false;
boolean doDelay;
public Connector(boolean isReconnect) {
doDelay = isReconnect;
}
public void run() {
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);
}
}
}
}
public void socketOpened(String remoteInfo) {
// This method does nothing.
}
}