Package org.apache.log4j.receivers.net
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 class
The Connector will reconnect when the server becomes available again. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected boolean
Active.private boolean
protected SocketHubReceiver.Connector
Connector.(package private) static final int
Default reconnection delay.protected String
Host.private List
Listener list.protected int
Port.protected int
Reconnection delay.protected SocketNode13
Socket.private org.apache.log4j.net.ZeroConfSupport
static final String
The MulticastDNS zone advertised by a SocketHubReceiverFields inherited from class org.apache.log4j.component.plugins.Receiver
thresholdLevel
Fields inherited from class org.apache.log4j.component.plugins.PluginSkeleton
name
Fields inherited from class org.apache.log4j.component.spi.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 TypeMethodDescriptionvoid
Starts the SocketReceiver with the current options.void
Adds a SocketNodeEventListener to this receiver to be notified of SocketNode events.private void
fireConnector
(boolean isReconnect) Fire connectors.getHost()
Get the remote host to connect to for logging events.int
getPort()
Get the remote port to connect to for logging events.int
Returns value of the ReconnectionDelay option.boolean
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
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
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
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.private void
Set socket.void
shutdown()
Called when the receiver should be stopped.void
Listen for a socketClosedEvent from the SocketNode.void
socketOpened
(String remoteInfo) This method does nothing.Methods inherited from class org.apache.log4j.component.plugins.Receiver
doPost, getThreshold, isAsSevereAsThreshold, setThreshold
Methods inherited from class org.apache.log4j.component.plugins.PluginSkeleton
addPropertyChangeListener, addPropertyChangeListener, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getLoggerRepository, getName, isActive, removePropertyChangeListener, removePropertyChangeListener, setLoggerRepository, setName
Methods inherited from class org.apache.log4j.component.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.receivers.net.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
The MulticastDNS zone advertised by a SocketHubReceiver- See Also:
-
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
Create new instance.- Parameters:
h
- hostp
- port
-
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
Get the remote host to connect to for logging events.- Returns:
- host
-
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
public int getPort()Get the remote port to connect to for logging events. -
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:
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.
-
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 interfaceorg.apache.log4j.spi.OptionHandler
-
shutdown
public void shutdown()Called when the receiver should be stopped. Closes the socket -
socketClosedEvent
Listen for a socketClosedEvent from the SocketNode. Reopen the socket if this receiver is still active.- Specified by:
socketClosedEvent
in interfaceSocketNodeEventListener
- Parameters:
e
- exception not used.
-
fireConnector
private void fireConnector(boolean isReconnect) Fire connectors.- Parameters:
isReconnect
- true if reconnect.
-
setSocket
Set socket.- Parameters:
newSocket
- new value for socket.
-
setAdvertiseViaMulticastDNS
public void setAdvertiseViaMulticastDNS(boolean advertiseViaMulticastDNS) -
isAdvertiseViaMulticastDNS
public boolean isAdvertiseViaMulticastDNS() -
socketOpened
This method does nothing.- Specified by:
socketOpened
in interfaceSocketNodeEventListener
- Parameters:
remoteInfo
- remote info.
-