org.apache.log4j.net

## Class SocketHubReceiver

- java.lang.Object
- - org.apache.log4j.spi.ComponentBase
  - - org.apache.log4j.plugins.PluginSkeleton
    - - org.apache.log4j.plugins.Receiver
      - - org.apache.log4j.net.SocketHubReceiver

- All Implemented Interfaces:
    EventListener, NetworkBased, PortBased, SocketNodeEventListener, Plugin, Component, org.apache.log4j.spi.OptionHandler, Thresholdable

      public class SocketHubReceiver
      extends Receiver
      implements SocketNodeEventListener, 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.

  Author:
    Mark Womack, Ceki Gülcü, Paul Smith (psmith@apache.org)

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected boolean` | `active` Active.
    `protected org.apache.log4j.net.SocketHubReceiver.Connector` | `connector` Connector.
    `protected String` | `host` Host.
    `protected int` | `port` Port.
    `protected int` | `reconnectionDelay` Reconnection delay.
    `protected SocketNode13` | `socketNode` Socket.
    `static String` | `ZONE` The MulticastDNS zone advertised by a SocketHubReceiver

    - ### 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

    Constructors
    Constructor and Description
    `SocketHubReceiver()` Create new instance.
    `SocketHubReceiver(String h, int p)` Create new instance.
    `SocketHubReceiver(String h, int p, org.apache.log4j.spi.LoggerRepository repo)` Create new instance.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `activateOptions()` Starts the SocketReceiver with the current options.
    `void` | `addSocketNodeEventListener(SocketNodeEventListener l)` Adds a SocketNodeEventListener to this receiver to be notified of SocketNode events.
    `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` | `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.
    `void` | `removeSocketNodeEventListener(SocketNodeEventListener l)` Removes a specific SocketNodeEventListener from this instance so that it will no longer be notified of SocketNode events.
    `protected void` | `setActive(boolean b)` Sets the flag to indicate if receiver is active or not.
    `void` | `setAdvertiseViaMulticastDNS(boolean advertiseViaMulticastDNS)`
    `void` | `setHost(String remoteHost)` Configures the Host property, this will require activateOptions to be called for this to take effect.
    `void` | `setPort(int p)` Set the remote port to connect to for logging events.
    `void` | `setPort(String remoteHost)` 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(Exception e)` Listen for a socketClosedEvent from the SocketNode.
    `void` | `socketOpened(String remoteInfo)` This method does nothing.

    - ### 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, 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

    - #### host

          protected String host

      Host.

    - #### port

          protected int port

      Port.

    - #### reconnectionDelay

          protected int reconnectionDelay

      Reconnection delay.

    - #### ZONE

          public static final String ZONE

      The MulticastDNS zone advertised by a SocketHubReceiver
      See Also:
        Constant Field Values

    - #### active

          protected boolean active

      Active.

    - #### connector

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

      Connector.

    - #### socketNode

          protected SocketNode13 socketNode

      Socket.

  - ### Constructor Detail

    - #### SocketHubReceiver

          public SocketHubReceiver()

      Create new instance.

    - #### SocketHubReceiver

          public SocketHubReceiver(String h,
                                   int p)

      Create new instance.
      Parameters:
        `h` - host
        `p` - port

    - #### SocketHubReceiver

          public SocketHubReceiver(String h,
                                   int p,
                                   org.apache.log4j.spi.LoggerRepository repo)

      Create new instance.
      Parameters:
        `h` - host
        `p` - port
        `repo` - logger repository

  - ### Method Detail

    - #### addSocketNodeEventListener

          public void addSocketNodeEventListener(SocketNodeEventListener l)

      Adds a SocketNodeEventListener to this receiver to be notified of SocketNode events.
      Parameters:
        `l` - listener

    - #### removeSocketNodeEventListener

          public void removeSocketNodeEventListener(SocketNodeEventListener l)

      Removes a specific SocketNodeEventListener from this instance so that it will no longer be notified of SocketNode events.
      Parameters:
        `l` - listener

    - #### getHost

          public String getHost()

      Get the remote host to connect to for logging events.
      Returns:
        host

    - #### setHost

          public void setHost(String remoteHost)

      Configures the Host property, this will require activateOptions to be called for this to take effect.
      Parameters:
        `remoteHost` - address of remote host.

    - #### setPort

          public void setPort(String remoteHost)

      Set the remote host to connect to for logging events. Equivalent to setHost.
      Parameters:
        `remoteHost` - address of remote host.

    - #### getPort

          public int getPort()

      Get the remote port to connect to for logging events.
      Specified by:
        `getPort` in interface `PortBased`
      Returns:
        port

    - #### setPort

          public void setPort(int p)

      Set the remote port to connect to for logging events.
      Parameters:
        `p` - port

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

      Parameters:
        `delay` - milliseconds to wait or zero to not reconnect.

    - #### getReconnectionDelay

          public int getReconnectionDelay()

      Returns value of the ReconnectionDelay option.
      Returns:
        value of reconnection delay option.

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

    - #### 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 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 `Plugin`

    - #### socketClosedEvent

          public void socketClosedEvent(Exception e)

      Listen for a socketClosedEvent from the SocketNode. Reopen the socket if this receiver is still active.
      Specified by:
        `socketClosedEvent` in interface `SocketNodeEventListener`
      Parameters:
        `e` - exception not used.

    - #### setAdvertiseViaMulticastDNS

          public void setAdvertiseViaMulticastDNS(boolean advertiseViaMulticastDNS)

    - #### isAdvertiseViaMulticastDNS

          public boolean isAdvertiseViaMulticastDNS()

    - #### socketOpened

          public void socketOpened(String remoteInfo)

      This method does nothing.
      Specified by:
        `socketOpened` in interface `SocketNodeEventListener`
      Parameters:
        `remoteInfo` - remote info.

Copyright © 2002-2018 Apache Software Foundation. All Rights Reserved.
Apache Logging, Apache Log4j, Log4j, Apache Chainsaw, Chainsaw, Apache, the Apache feather logo, the Apache Logging project logo, and the Apache Log4j logo are trademarks of The Apache Software Foundation.