Package org.apache.log4j.net
Class XMLSocketReceiver
- java.lang.Object
-
- org.apache.log4j.spi.ComponentBase
-
- org.apache.log4j.plugins.PluginSkeleton
-
- org.apache.log4j.plugins.Receiver
-
- org.apache.log4j.net.XMLSocketReceiver
-
- All Implemented Interfaces:
java.lang.Runnable
,NetworkBased
,PortBased
,Pauseable
,Plugin
,Component
,org.apache.log4j.spi.OptionHandler
,Thresholdable
public class XMLSocketReceiver extends Receiver implements java.lang.Runnable, PortBased, Pauseable
XMLSocketReceiver receives a remote logging event via XML on a configured socket and "posts" it to a LoggerRepository as if the event were generated locally. This class is designed to receive events from the XMLSocketAppender class (or classes that send compatible events).This receiver supports log files created using log4j's XMLLayout, as well as java.util.logging XMLFormatter (via the org.apache.log4j.spi.Decoder interface).
By default, log4j's XMLLayout is supported (no need to specify a decoder in that case).
To configure this receiver to support java.util.logging's XMLFormatter, specify a 'decoder' param of org.apache.log4j.xml.UtilLoggingXMLDecoder.
Once the event has been "posted", it will be handled by the appenders currently configured in the LoggerRespository.
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
advertiseViaMulticastDNS
protected java.lang.String
decoder
static int
DEFAULT_PORT
private boolean
paused
protected int
port
private java.lang.Thread
rThread
private java.net.ServerSocket
serverSocket
private java.util.List<java.net.Socket>
socketList
private org.apache.log4j.net.ZeroConfSupport
zeroConf
static java.lang.String
ZONE
The MulticastDNS zone advertised by an XMLSocketReceiver-
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
Constructors Constructor Description XMLSocketReceiver()
XMLSocketReceiver(int _port)
XMLSocketReceiver(int _port, org.apache.log4j.spi.LoggerRepository _repository)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
activateOptions()
Starts the XMLSocketReceiver with the current options.private void
closeAllAcceptedSockets()
Closes all the connected sockets in the List.private void
closeServerSocket()
Closes the server socket, if created.void
doPost(org.apache.log4j.spi.LoggingEvent event)
Posts the logging event to a logger in the configured logger repository.private void
doShutdown()
Does the actual shutting down by closing the server socket and any connected sockets that have been created.java.lang.String
getDecoder()
int
getPort()
Get the port to receive logging events on.int
hashCode()
boolean
isAdvertiseViaMulticastDNS()
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.boolean
isPaused()
Get paused state.void
run()
Loop, accepting new socket connections.protected void
setActive(boolean b)
Sets the flag to indicate if receiver is active or not.void
setAdvertiseViaMulticastDNS(boolean advertiseViaMulticastDNS)
void
setDecoder(java.lang.String _decoder)
Specify the class name implementing org.apache.log4j.spi.Decoder that can process the file.void
setPaused(boolean b)
Set paused state.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, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.log4j.net.NetworkBased
getName, isActive
-
-
-
-
Field Detail
-
paused
private boolean paused
-
decoder
protected java.lang.String decoder
-
serverSocket
private java.net.ServerSocket serverSocket
-
socketList
private java.util.List<java.net.Socket> socketList
-
rThread
private java.lang.Thread rThread
-
DEFAULT_PORT
public static final int DEFAULT_PORT
- See Also:
- Constant Field Values
-
port
protected int port
-
advertiseViaMulticastDNS
private boolean advertiseViaMulticastDNS
-
zeroConf
private org.apache.log4j.net.ZeroConfSupport zeroConf
-
ZONE
public static final java.lang.String ZONE
The MulticastDNS zone advertised by an XMLSocketReceiver- See Also:
- Constant Field Values
-
-
Method Detail
-
getPort
public int getPort()
Get the port to receive logging events on.
-
setPort
public void setPort(int _port)
Set the port to receive logging events on.
-
getDecoder
public java.lang.String getDecoder()
-
setDecoder
public void setDecoder(java.lang.String _decoder)
Specify the class name implementing org.apache.log4j.spi.Decoder that can process the file.
-
isPaused
public boolean isPaused()
Description copied from interface:Pauseable
Get paused state.
-
setPaused
public void setPaused(boolean b)
Description copied from interface:Pauseable
Set paused state.
-
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:
isEquivalent
in interfacePlugin
- Overrides:
isEquivalent
in classPluginSkeleton
- Parameters:
testPlugin
- The plugin to test equivalency against.- Returns:
- boolean True if the testPlugin is equivalent to this plugin.
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
setActive
protected void setActive(boolean b)
Sets the flag to indicate if receiver is active or not.- Parameters:
b
- new value
-
activateOptions
public void activateOptions()
Starts the XMLSocketReceiver with the current options.- Specified by:
activateOptions
in interfaceorg.apache.log4j.spi.OptionHandler
-
setAdvertiseViaMulticastDNS
public void setAdvertiseViaMulticastDNS(boolean advertiseViaMulticastDNS)
-
isAdvertiseViaMulticastDNS
public boolean isAdvertiseViaMulticastDNS()
-
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.
-
run
public void run()
Loop, accepting new socket connections.- Specified by:
run
in interfacejava.lang.Runnable
-
-