Class XMLSocketReceiver

All Implemented Interfaces:
Runnable, NetworkBased, PortBased, Pauseable, Plugin, Component, org.apache.log4j.spi.OptionHandler, Thresholdable

public class XMLSocketReceiver extends Receiver implements 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 Details

    • paused

      private boolean paused
    • decoder

      protected String decoder
    • serverSocket

      private ServerSocket serverSocket
    • socketList

      private List<Socket> socketList
    • rThread

      private Thread rThread
    • DEFAULT_PORT

      public static final int DEFAULT_PORT
      See Also:
    • port

      protected int port
    • advertiseViaMulticastDNS

      private boolean advertiseViaMulticastDNS
    • zeroConf

      private org.apache.log4j.net.ZeroConfSupport zeroConf
    • ZONE

      public static final String ZONE
      The MulticastDNS zone advertised by an XMLSocketReceiver
      See Also:
  • Constructor Details

    • XMLSocketReceiver

      public XMLSocketReceiver()
    • XMLSocketReceiver

      public XMLSocketReceiver(int _port)
    • XMLSocketReceiver

      public XMLSocketReceiver(int _port, org.apache.log4j.spi.LoggerRepository _repository)
  • Method Details

    • getPort

      public int getPort()
      Get the port to receive logging events on.
      Specified by:
      getPort in interface PortBased
      Returns:
      int port number
    • setPort

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

      public String getDecoder()
    • setDecoder

      public void setDecoder(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.
      Specified by:
      isPaused in interface Pauseable
      Returns:
      paused state.
    • setPaused

      public void setPaused(boolean b)
      Description copied from interface: Pauseable
      Set paused state.
      Specified by:
      setPaused in interface Pauseable
      Parameters:
      b - new value
    • 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 interface Plugin
      Overrides:
      isEquivalent in class PluginSkeleton
      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 class 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 interface org.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.
      Specified by:
      shutdown in interface Plugin
    • 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 interface Runnable
    • 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.