Class SocketHubReceiver
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.SocketHubReceiver
- All Implemented Interfaces:
EventListener, Plugin, Component, Thresholdable, NetworkBased, PortBased, SocketNodeEventListener, org.apache.log4j.spi.OptionHandler
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
FieldsModifier and TypeFieldDescriptionprotected booleanActive.protected org.apache.log4j.receivers.net.SocketHubReceiver.ConnectorConnector.protected StringHost.protected intPort.protected intReconnection delay.protected SocketNode13Socket.static final StringThe MulticastDNS zone advertised by a SocketHubReceiverFields inherited from class Receiver
thresholdLevelFields inherited from class PluginSkeleton
nameFields inherited from class ComponentBase
repository -
Constructor Summary
ConstructorsConstructorDescriptionCreate 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
Modifier and TypeMethodDescriptionvoidStarts the SocketReceiver with the current options.voidAdds a SocketNodeEventListener to this receiver to be notified of SocketNode events.getHost()Get the remote host to connect to for logging events.intgetPort()Get the remote port to connect to for logging events.intReturns value of the ReconnectionDelay option.booleanbooleanisEquivalent(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.voidRemoves a specific SocketNodeEventListener from this instance so that it will no longer be notified of SocketNode events.protected voidsetActive(boolean b) Sets the flag to indicate if receiver is active or not.voidsetAdvertiseViaMulticastDNS(boolean advertiseViaMulticastDNS) voidConfigures the Host property, this will require activateOptions to be called for this to take effect.voidsetPort(int p) Set the remote port to connect to for logging events.voidSet the remote host to connect to for logging events.voidsetReconnectionDelay(int delay) The ReconnectionDelay option takes a positive integer representing the number of milliseconds to wait between each failed connection attempt to the server.voidshutdown()Called when the receiver should be stopped.voidListen for a socketClosedEvent from the SocketNode.voidsocketOpened(String remoteInfo) This method does nothing.Methods inherited from class Receiver
doPost, getThreshold, isAsSevereAsThreshold, setThresholdMethods inherited from class PluginSkeleton
addPropertyChangeListener, addPropertyChangeListener, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getLoggerRepository, getName, isActive, removePropertyChangeListener, removePropertyChangeListener, setLoggerRepository, setNameMethods inherited from class ComponentBase
getLogger, getNonFloodingLogger, resetErrorCountMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface NetworkBased
getName, isActive
-
Field Details
-
host
Host. -
port
protected int portPort. -
reconnectionDelay
protected int reconnectionDelayReconnection delay. -
ZONE
-
active
protected boolean activeActive. -
connector
protected org.apache.log4j.receivers.net.SocketHubReceiver.Connector connectorConnector. -
socketNode
Socket.
-
-
Constructor Details
-
SocketHubReceiver
public SocketHubReceiver()Create new instance. -
SocketHubReceiver
-
SocketHubReceiver
Create new instance.- Parameters:
h- hostp- portrepo- logger repository
-
-
Method Details
-
addSocketNodeEventListener
Adds a SocketNodeEventListener to this receiver to be notified of SocketNode events.- Parameters:
l- listener
-
removeSocketNodeEventListener
Removes a specific SocketNodeEventListener from this instance so that it will no longer be notified of SocketNode events.- Parameters:
l- listener
-
getHost
-
setHost
Configures the Host property, this will require activateOptions to be called for this to take effect.- Parameters:
remoteHost- address of remote host.
-
setPort
Set the remote host to connect to for logging events. Equivalent to setHost.- Parameters:
remoteHost- address of remote host.
-
getPort
-
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
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.
-
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:
activateOptionsin interfaceorg.apache.log4j.spi.OptionHandler
-
shutdown
-
socketClosedEvent
Listen for a socketClosedEvent from the SocketNode. Reopen the socket if this receiver is still active.- Specified by:
socketClosedEventin interfaceSocketNodeEventListener- Parameters:
e- exception not used.
-
setAdvertiseViaMulticastDNS
public void setAdvertiseViaMulticastDNS(boolean advertiseViaMulticastDNS) -
isAdvertiseViaMulticastDNS
public boolean isAdvertiseViaMulticastDNS() -
socketOpened
This method does nothing.- Specified by:
socketOpenedin interfaceSocketNodeEventListener- Parameters:
remoteInfo- remote info.
-