Log4j 2.0alpha-1

org.apache.log4j.net
Class SocketReceiver

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.SocketReceiver
All Implemented Interfaces:
java.lang.Runnable, org.apache.log4j.net.NetworkBased, org.apache.log4j.net.PortBased, org.apache.log4j.plugins.Pauseable, org.apache.log4j.plugins.Plugin, org.apache.log4j.spi.Component, org.apache.log4j.spi.OptionHandler, org.apache.log4j.spi.Thresholdable

public class SocketReceiver
extends Receiver
implements java.lang.Runnable, org.apache.log4j.net.PortBased, org.apache.log4j.plugins.Pauseable

SocketReceiver 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 SocketAppender 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, Scott Deboy , Paul Smith

Nested Class Summary
static class SocketReceiver.SocketDetail
           
 
Field Summary
protected  int port
           
 
Fields inherited from class org.apache.log4j.plugins.Receiver
thresholdLevel
 
Fields inherited from class org.apache.log4j.plugins.PluginSkeleton
active, name
 
Fields inherited from class org.apache.log4j.spi.ComponentBase
repository
 
Constructor Summary
SocketReceiver()
           
SocketReceiver(int _port)
           
SocketReceiver(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 listener)
          Adds the listener to the list of listeners to be notified of the respective event
 void doPost(org.apache.log4j.spi.LoggingEvent event)
          Posts the logging event to a logger in the configured logger repository.
 java.util.Vector getConnectedSocketDetails()
          Returns a Vector of SocketDetail representing the IP/Domain name of the currently connected sockets that this receiver has been responsible for creating.
 org.apache.log4j.net.SocketNodeEventListener getListener()
          Deprecated. This receiver now supports multiple listeners
 int getPort()
          Get the port to receive logging events on.
 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.
 boolean isPaused()
           
 void removeSocketNodeEventListener(org.apache.log4j.net.SocketNodeEventListener listener)
          Removes the registered Listener from this instances list of listeners.
 void run()
          Loop, accepting new socket connections.
 void setListener(org.apache.log4j.net.SocketNodeEventListener listener)
          Deprecated. This receiver now supports multiple listeners and so this method simply removes the listener (if there already) and readds it to the list. The passed listener will also be returned via the getListener() method still, but this is also deprecated
 void setPaused(boolean b)
           
 void setPort(int _port)
          Set the port to receive logging events on.
 void shutdown()
          Called when the receiver should be stopped.
 
Methods inherited from class org.apache.log4j.plugins.Receiver
getThreshold, isAsSevereAsThreshold, setThreshold
 
Methods inherited from class org.apache.log4j.plugins.PluginSkeleton
addPropertyChangeListener, addPropertyChangeListener, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getLoggerRepository, getName, isActive, 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, isActive
 

Field Detail

port

protected int port
Constructor Detail

SocketReceiver

public SocketReceiver()

SocketReceiver

public SocketReceiver(int _port)

SocketReceiver

public SocketReceiver(int _port,
                      org.apache.log4j.spi.LoggerRepository _repository)
Method Detail

getPort

public int getPort()
Get the port to receive logging events on.

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

setPort

public void setPort(int _port)
Set the port to receive logging events on.


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.

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 server socket and all of the open sockets.

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

run

public void run()
Loop, accepting new socket connections.

Specified by:
run in interface java.lang.Runnable

getConnectedSocketDetails

public java.util.Vector getConnectedSocketDetails()
Returns a Vector of SocketDetail representing the IP/Domain name of the currently connected sockets that this receiver has been responsible for creating.

Returns:
Vector of SocketDetails

getListener

public org.apache.log4j.net.SocketNodeEventListener getListener()
Deprecated. This receiver now supports multiple listeners

Returns the currently configured SocketNodeEventListener that will be automatically set for each SocketNode created

Returns:
SocketNodeEventListener currently configured

addSocketNodeEventListener

public void addSocketNodeEventListener(org.apache.log4j.net.SocketNodeEventListener listener)
Adds the listener to the list of listeners to be notified of the respective event

Parameters:
listener - the listener to add to the list

removeSocketNodeEventListener

public void removeSocketNodeEventListener(org.apache.log4j.net.SocketNodeEventListener listener)
Removes the registered Listener from this instances list of listeners. If the listener has not been registered, then invoking this method has no effect.

Parameters:
listener - the SocketNodeEventListener to remove

setListener

public void setListener(org.apache.log4j.net.SocketNodeEventListener listener)
Deprecated. This receiver now supports multiple listeners and so this method simply removes the listener (if there already) and readds it to the list. The passed listener will also be returned via the getListener() method still, but this is also deprecated

Sets the SocketNodeEventListener that will be used for each created SocketNode

Parameters:
listener - the listener to set on each creation of a SocketNode

isPaused

public boolean isPaused()
Specified by:
isPaused in interface org.apache.log4j.plugins.Pauseable

setPaused

public void setPaused(boolean b)
Specified by:
setPaused in interface org.apache.log4j.plugins.Pauseable

doPost

public void doPost(org.apache.log4j.spi.LoggingEvent event)
Description copied from class: Receiver
Posts the logging event to a logger in the configured logger repository.

Overrides:
doPost in class Receiver
Parameters:
event - the log event to post to the local log4j environment.

Log4j 2.0alpha-1

Copyright 2000-2003 Apache Software Foundation.