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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate final classThe Connector will reconnect when the server becomes available again. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanActive.private booleanprotected SocketHubReceiver.ConnectorConnector.(package private) static final intDefault reconnection delay.protected StringHost.private ListListener list.protected intPort.protected intReconnection delay.protected SocketNode13Socket.private org.apache.log4j.net.ZeroConfSupportstatic 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.private voidfireConnector(boolean isReconnect) Fire connectors.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.private voidSet socket.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
-
DEFAULT_RECONNECTION_DELAY
static final int DEFAULT_RECONNECTION_DELAYDefault reconnection delay.- See Also:
-
host
Host. -
port
protected int portPort. -
reconnectionDelay
protected int reconnectionDelayReconnection delay. -
ZONE
-
active
protected boolean activeActive. -
connector
Connector. -
socketNode
Socket. -
listenerList
Listener list. -
advertiseViaMulticastDNS
private boolean advertiseViaMulticastDNS -
zeroConf
private org.apache.log4j.net.ZeroConfSupport zeroConf
-
-
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.
-
fireConnector
private void fireConnector(boolean isReconnect) Fire connectors.- Parameters:
isReconnect- true if reconnect.
-
setSocket
-
setAdvertiseViaMulticastDNS
public void setAdvertiseViaMulticastDNS(boolean advertiseViaMulticastDNS) -
isAdvertiseViaMulticastDNS
public boolean isAdvertiseViaMulticastDNS() -
socketOpened
This method does nothing.- Specified by:
socketOpenedin interfaceSocketNodeEventListener- Parameters:
remoteInfo- remote info.
-