Package org.apache.log4j.receivers.net
Class SocketReceiver
- java.lang.Object
-
- org.apache.log4j.component.spi.ComponentBase
-
- org.apache.log4j.component.plugins.PluginSkeleton
-
- org.apache.log4j.component.plugins.Receiver
-
- org.apache.log4j.receivers.net.SocketReceiver
-
- All Implemented Interfaces:
java.lang.Runnable,Pauseable,Plugin,Component,Thresholdable,NetworkBased,PortBased,org.apache.log4j.spi.OptionHandler
public class SocketReceiver extends Receiver implements java.lang.Runnable, PortBased, 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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classSocketReceiver.SocketDetailSocket detail.
-
Field Summary
Fields Modifier and Type Field Description private booleanadvertiseViaMulticastDNSprivate SocketNodeEventListenerlistenerListener.private java.util.ListlistenerListListeners.private booleanpausedPaused.protected intportPort.private java.lang.ThreadrThreadThread.private java.net.ServerSocketserverSocketServer socket.private java.util.VectorsocketListSocket list.private java.util.MapsocketMapsocket map.private org.apache.log4j.net.ZeroConfSupportzeroConfstatic java.lang.StringZONEThe MulticastDNS zone advertised by a SocketReceiver-
Fields inherited from class org.apache.log4j.component.plugins.Receiver
thresholdLevel
-
Fields inherited from class org.apache.log4j.component.plugins.PluginSkeleton
active, name
-
Fields inherited from class org.apache.log4j.component.spi.ComponentBase
repository
-
-
Constructor Summary
Constructors Constructor Description SocketReceiver()Create new instance.SocketReceiver(int p)Create new instance.SocketReceiver(int p, org.apache.log4j.spi.LoggerRepository repo)Create new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidactivateOptions()Starts the SocketReceiver with the current options.voidaddSocketNodeEventListener(SocketNodeEventListener l)Adds the listener to the list of listeners to be notified of the respective event.private voidcloseAllAcceptedSockets()Closes all the connected sockets in the List.private voidcloseServerSocket()Closes the server socket, if created.voiddoPost(org.apache.log4j.spi.LoggingEvent event)Posts the logging event to a logger in the configured logger repository.private voiddoShutdown()Does the actual shutting down by closing the server socket and any connected sockets that have been created.java.util.VectorgetConnectedSocketDetails()Returns a Vector of SocketDetail representing the IP/Domain name of the currently connected sockets that this receiver has been responsible for creating.SocketNodeEventListenergetListener()Deprecated.This receiver now supports multiple listenersintgetPort()Returns the Port # that this net based thing is using.booleanisAdvertiseViaMulticastDNS()booleanisEquivalent(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.booleanisPaused()Get paused state.voidremoveSocketNodeEventListener(SocketNodeEventListener l)Removes the registered Listener from this instances list of listeners.voidrun()Loop, accepting new socket connections.protected voidsetActive(boolean b)Sets the flag to indicate if receiver is active or not.voidsetAdvertiseViaMulticastDNS(boolean advertiseViaMulticastDNS)voidsetListener(SocketNodeEventListener l)Deprecated.This receiver now supports multiple listeners and so this method simply removes the listener (if there already) and readds it to the list.voidsetPaused(boolean b)Set paused state.voidsetPort(int p)voidshutdown()Called when the receiver should be stopped.-
Methods inherited from class org.apache.log4j.component.plugins.Receiver
getThreshold, isAsSevereAsThreshold, setThreshold
-
Methods inherited from class org.apache.log4j.component.plugins.PluginSkeleton
addPropertyChangeListener, addPropertyChangeListener, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getLoggerRepository, getName, isActive, removePropertyChangeListener, removePropertyChangeListener, setLoggerRepository, setName
-
Methods inherited from class org.apache.log4j.component.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.receivers.net.NetworkBased
getName, isActive
-
-
-
-
Field Detail
-
socketMap
private java.util.Map socketMap
socket map.
-
paused
private boolean paused
Paused.
-
rThread
private java.lang.Thread rThread
Thread.
-
port
protected int port
Port.
-
serverSocket
private java.net.ServerSocket serverSocket
Server socket.
-
socketList
private java.util.Vector socketList
Socket list.
-
ZONE
public static final java.lang.String ZONE
The MulticastDNS zone advertised by a SocketReceiver- See Also:
- Constant Field Values
-
listener
private SocketNodeEventListener listener
Listener.
-
listenerList
private java.util.List listenerList
Listeners.
-
advertiseViaMulticastDNS
private boolean advertiseViaMulticastDNS
-
zeroConf
private org.apache.log4j.net.ZeroConfSupport zeroConf
-
-
Constructor Detail
-
SocketReceiver
public SocketReceiver()
Create new instance.
-
SocketReceiver
public SocketReceiver(int p)
Create new instance.- Parameters:
p- port
-
SocketReceiver
public SocketReceiver(int p, org.apache.log4j.spi.LoggerRepository repo)Create new instance.- Parameters:
p- portrepo- logger repository
-
-
Method Detail
-
getPort
public int getPort()
Description copied from interface:PortBasedReturns the Port # that this net based thing is using.
-
setPort
public void setPort(int p)
-
isEquivalent
public boolean isEquivalent(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:
isEquivalentin interfacePlugin- Overrides:
isEquivalentin classPluginSkeleton- 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:
activateOptionsin interfaceorg.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.
-
doShutdown
private void doShutdown()
Does the actual shutting down by closing the server socket and any connected sockets that have been created.
-
closeServerSocket
private void closeServerSocket()
Closes the server socket, if created.
-
closeAllAcceptedSockets
private void closeAllAcceptedSockets()
Closes all the connected sockets in the List.
-
setActive
protected void setActive(boolean b)
Sets the flag to indicate if receiver is active or not.- Parameters:
b- new value
-
setAdvertiseViaMulticastDNS
public void setAdvertiseViaMulticastDNS(boolean advertiseViaMulticastDNS)
-
isAdvertiseViaMulticastDNS
public boolean isAdvertiseViaMulticastDNS()
-
run
public void run()
Loop, accepting new socket connections.- Specified by:
runin interfacejava.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 SocketNodeEventListener getListener()
Deprecated.This receiver now supports multiple listenersReturns the currently configured SocketNodeEventListener that will be automatically set for each SocketNode created.- Returns:
- SocketNodeEventListener currently configured
-
addSocketNodeEventListener
public void addSocketNodeEventListener(SocketNodeEventListener l)
Adds the listener to the list of listeners to be notified of the respective event.- Parameters:
l- the listener to add to the list
-
removeSocketNodeEventListener
public void removeSocketNodeEventListener(SocketNodeEventListener l)
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:
l- the SocketNodeEventListener to remove
-
setListener
public void setListener(SocketNodeEventListener l)
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 deprecatedSets the SocketNodeEventListener that will be used for each created SocketNode.- Parameters:
l- the listener to set on each creation of a SocketNode
-
isPaused
public boolean isPaused()
Get paused state.
-
setPaused
public void setPaused(boolean b)
Set paused state.
-
-