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:
java.util.EventListener,Plugin,Component,Thresholdable,NetworkBased,PortBased,SocketNodeEventListener,org.apache.log4j.spi.OptionHandler
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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classSocketHubReceiver.ConnectorThe Connector will reconnect when the server becomes available again.
-
Field Summary
Fields Modifier and Type Field Description protected booleanactiveActive.private booleanadvertiseViaMulticastDNSprotected SocketHubReceiver.ConnectorconnectorConnector.(package private) static intDEFAULT_RECONNECTION_DELAYDefault reconnection delay.protected java.lang.StringhostHost.private java.util.ListlistenerListListener list.protected intportPort.protected intreconnectionDelayReconnection delay.protected SocketNode13socketNodeSocket.private org.apache.log4j.net.ZeroConfSupportzeroConfstatic java.lang.StringZONEThe MulticastDNS zone advertised by a SocketHubReceiver-
Fields 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
Constructors Constructor Description SocketHubReceiver()Create new instance.SocketHubReceiver(java.lang.String h, int p)Create new instance.SocketHubReceiver(java.lang.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 Description voidactivateOptions()Starts the SocketReceiver with the current options.voidaddSocketNodeEventListener(SocketNodeEventListener l)Adds a SocketNodeEventListener to this receiver to be notified of SocketNode events.private voidfireConnector(boolean isReconnect)Fire connectors.java.lang.StringgetHost()Get the remote host to connect to for logging events.intgetPort()Get the remote port to connect to for logging events.intgetReconnectionDelay()Returns value of the ReconnectionDelay option.booleanisAdvertiseViaMulticastDNS()booleanisEquivalent(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.voidremoveSocketNodeEventListener(SocketNodeEventListener l)Removes 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)voidsetHost(java.lang.String remoteHost)Configures 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.voidsetPort(java.lang.String remoteHost)Set 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 voidsetSocket(java.net.Socket newSocket)Set socket.voidshutdown()Called when the receiver should be stopped.voidsocketClosedEvent(java.lang.Exception e)Listen for a socketClosedEvent from the SocketNode.voidsocketOpened(java.lang.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 Detail
-
DEFAULT_RECONNECTION_DELAY
static final int DEFAULT_RECONNECTION_DELAY
Default reconnection delay.- See Also:
- Constant Field Values
-
host
protected java.lang.String host
Host.
-
port
protected int port
Port.
-
reconnectionDelay
protected int reconnectionDelay
Reconnection delay.
-
ZONE
public static final java.lang.String ZONE
The MulticastDNS zone advertised by a SocketHubReceiver- See Also:
- Constant Field Values
-
active
protected boolean active
Active.
-
connector
protected SocketHubReceiver.Connector connector
Connector.
-
socketNode
protected SocketNode13 socketNode
Socket.
-
listenerList
private java.util.List listenerList
Listener list.
-
advertiseViaMulticastDNS
private boolean advertiseViaMulticastDNS
-
zeroConf
private org.apache.log4j.net.ZeroConfSupport zeroConf
-
-
Constructor Detail
-
SocketHubReceiver
public SocketHubReceiver()
Create new instance.
-
SocketHubReceiver
public SocketHubReceiver(java.lang.String h, int p)Create new instance.- Parameters:
h- hostp- port
-
SocketHubReceiver
public SocketHubReceiver(java.lang.String h, int p, org.apache.log4j.spi.LoggerRepository repo)Create new instance.- Parameters:
h- hostp- portrepo- 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 java.lang.String getHost()
Get the remote host to connect to for logging events.- Returns:
- host
-
setHost
public void setHost(java.lang.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(java.lang.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.
-
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:
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
public void shutdown()
Called when the receiver should be stopped. Closes the socket
-
socketClosedEvent
public void socketClosedEvent(java.lang.Exception e)
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
private void setSocket(java.net.Socket newSocket)
Set socket.- Parameters:
newSocket- new value for socket.
-
setAdvertiseViaMulticastDNS
public void setAdvertiseViaMulticastDNS(boolean advertiseViaMulticastDNS)
-
isAdvertiseViaMulticastDNS
public boolean isAdvertiseViaMulticastDNS()
-
socketOpened
public void socketOpened(java.lang.String remoteInfo)
This method does nothing.- Specified by:
socketOpenedin interfaceSocketNodeEventListener- Parameters:
remoteInfo- remote info.
-
-