Log4j 2.0alpha-1

org.apache.log4j.net
Class SocketHubReceiver

java.lang.Object
  extended by org.apache.log4j.spi.ComponentBase
      extended by org.apache.log4j.plugins.PluginSkeleton
          extended by org.apache.log4j.plugins.Receiver
              extended by org.apache.log4j.net.SocketHubReceiver
All Implemented Interfaces:
java.util.EventListener, org.apache.log4j.net.NetworkBased, org.apache.log4j.net.PortBased, org.apache.log4j.net.SocketNodeEventListener, org.apache.log4j.plugins.Plugin, org.apache.log4j.spi.Component, org.apache.log4j.spi.OptionHandler, org.apache.log4j.spi.Thresholdable

public class SocketHubReceiver
extends Receiver
implements org.apache.log4j.net.SocketNodeEventListener, org.apache.log4j.net.PortBased

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).

Once the event has been "posted", it will be handled by the appenders currently configured in the LoggerRespository.

Since:
1.3
Author:
Mark Womack, Ceki Gülcü, Paul Smith

Field Summary
protected  boolean active
           
protected  org.apache.log4j.net.SocketHubReceiver.Connector connector
           
protected  java.lang.String host
           
protected  int port
           
protected  int reconnectionDelay
           
protected  java.net.Socket socket
           
 
Fields inherited from class org.apache.log4j.plugins.Receiver
thresholdLevel
 
Fields inherited from class org.apache.log4j.plugins.PluginSkeleton
name
 
Fields inherited from class org.apache.log4j.spi.ComponentBase
repository
 
Constructor Summary
SocketHubReceiver()
           
SocketHubReceiver(java.lang.String _host, int _port)
           
SocketHubReceiver(java.lang.String _host, int _port, org.apache.log4j.spi.LoggerRepository _repository)
           
 
Method Summary
 void activateOptions()
          Starts the SocketReceiver with the current options.
 void addSocketNodeEventListener(org.apache.log4j.net.SocketNodeEventListener l)
          Adds a SocketNodeEventListener to this receiver to be notified of SocketNode events
 java.lang.String getHost()
          Get the remote host to connect to for logging events.
 int getPort()
          Get the remote port to connect to for logging events.
 int getReconnectionDelay()
          Returns value of the ReconnectionDelay option.
 boolean isActive()
          Returns true if this receiver is active.
 boolean isEquivalent(org.apache.log4j.plugins.Plugin testPlugin)
          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.
 void removeSocketNodeEventListener(org.apache.log4j.net.SocketNodeEventListener l)
          Removes a specific SocketNodeEventListener from this instance so that it will no longer be notified of SocketNode events.
protected  void setActive(boolean _active)
          Sets the flag to indicate if receiver is active or not.
 void setHost(java.lang.String host)
          Configures the Host property, this will require activateOptions to be called for this to take effect.
 void setPort(int _port)
          Set the remote port to connect to for logging events.
 void setPort(java.lang.String _host)
          Set the remote host to connect to for logging events.
 void setReconnectionDelay(int delay)
          The ReconnectionDelay option takes a positive integer representing the number of milliseconds to wait between each failed connection attempt to the server.
 void shutdown()
          Called when the receiver should be stopped.
 void socketClosedEvent(java.lang.Exception e)
          Listen for a socketClosedEvent from the SocketNode.
 void socketOpened(java.lang.String remoteInfo)
           
 
Methods inherited from class org.apache.log4j.plugins.Receiver
doPost, getThreshold, isAsSevereAsThreshold, setThreshold
 
Methods inherited from class org.apache.log4j.plugins.PluginSkeleton
addPropertyChangeListener, addPropertyChangeListener, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getLoggerRepository, getName, removePropertyChangeListener, removePropertyChangeListener, setLoggerRepository, setName
 
Methods inherited from class org.apache.log4j.spi.ComponentBase
getLogger, getNonFloodingLogger, resetErrorCount
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.log4j.net.NetworkBased
getName
 

Field Detail

host

protected java.lang.String host

port

protected int port

reconnectionDelay

protected int reconnectionDelay

active

protected boolean active

connector

protected org.apache.log4j.net.SocketHubReceiver.Connector connector

socket

protected java.net.Socket socket
Constructor Detail

SocketHubReceiver

public SocketHubReceiver()

SocketHubReceiver

public SocketHubReceiver(java.lang.String _host,
                         int _port)

SocketHubReceiver

public SocketHubReceiver(java.lang.String _host,
                         int _port,
                         org.apache.log4j.spi.LoggerRepository _repository)
Method Detail

addSocketNodeEventListener

public void addSocketNodeEventListener(org.apache.log4j.net.SocketNodeEventListener l)
Adds a SocketNodeEventListener to this receiver to be notified of SocketNode events

Parameters:
l -

removeSocketNodeEventListener

public void removeSocketNodeEventListener(org.apache.log4j.net.SocketNodeEventListener l)
Removes a specific SocketNodeEventListener from this instance so that it will no longer be notified of SocketNode events.

Parameters:
l -

getHost

public java.lang.String getHost()
Get the remote host to connect to for logging events.


setHost

public void setHost(java.lang.String host)
Configures the Host property, this will require activateOptions to be called for this to take effect.

Parameters:
host -

setPort

public void setPort(java.lang.String _host)
Set the remote host to connect to for logging events.


getPort

public int getPort()
Get the remote port to connect to for logging events.

Specified by:
getPort in interface org.apache.log4j.net.PortBased

setPort

public void setPort(int _port)
Set the remote port to connect to for logging events.


setReconnectionDelay

public void setReconnectionDelay(int delay)
The ReconnectionDelay 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.

Setting this option to zero turns off reconnection capability.


getReconnectionDelay

public int getReconnectionDelay()
Returns value of the ReconnectionDelay option.


isEquivalent

public boolean isEquivalent(org.apache.log4j.plugins.Plugin testPlugin)
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.

Specified by:
isEquivalent in interface org.apache.log4j.plugins.Plugin
Overrides:
isEquivalent in class org.apache.log4j.plugins.PluginSkeleton
Parameters:
testPlugin - The plugin to test equivalency against.
Returns:
boolean True if the testPlugin is equivalent to this plugin.

isActive

public boolean isActive()
Returns true if this receiver is active.

Specified by:
isActive in interface org.apache.log4j.net.NetworkBased
Specified by:
isActive in interface org.apache.log4j.plugins.Plugin
Overrides:
isActive in class org.apache.log4j.plugins.PluginSkeleton

setActive

protected void setActive(boolean _active)
Sets the flag to indicate if receiver is active or not.


activateOptions

public void activateOptions()
Starts the SocketReceiver with the current options.

Specified by:
activateOptions in interface org.apache.log4j.spi.OptionHandler

shutdown

public void shutdown()
Called when the receiver should be stopped. Closes the socket

Specified by:
shutdown in interface org.apache.log4j.plugins.Plugin

socketClosedEvent

public void socketClosedEvent(java.lang.Exception e)
Listen for a socketClosedEvent from the SocketNode. Reopen the socket if this receiver is still active.

Specified by:
socketClosedEvent in interface org.apache.log4j.net.SocketNodeEventListener

socketOpened

public void socketOpened(java.lang.String remoteInfo)
Specified by:
socketOpened in interface org.apache.log4j.net.SocketNodeEventListener

Log4j 2.0alpha-1

Copyright 2000-2003 Apache Software Foundation.