Package ch.qos.logback.classic.net
Class SocketReceiver
- java.lang.Object
-
- ch.qos.logback.core.spi.ContextAwareBase
-
- ch.qos.logback.classic.net.ReceiverBase
-
- ch.qos.logback.classic.net.SocketReceiver
-
- All Implemented Interfaces:
SocketConnector.ExceptionHandler,ContextAware,LifeCycle,java.lang.Runnable
- Direct Known Subclasses:
SSLSocketReceiver
public class SocketReceiver extends ReceiverBase implements java.lang.Runnable, SocketConnector.ExceptionHandler
A component that receives serializedILoggingEventobjects from a remote appender over aSocket.
-
-
Field Summary
Fields Modifier and Type Field Description private intacceptConnectionTimeoutprivate java.net.InetAddressaddressprivate java.util.concurrent.Future<java.net.Socket>connectorTaskprivate static intDEFAULT_ACCEPT_CONNECTION_DELAYprivate intportprivate java.lang.StringreceiverIdprivate intreconnectionDelayprivate java.lang.StringremoteHostprivate java.net.Socketsocket-
Fields inherited from class ch.qos.logback.core.spi.ContextAwareBase
context
-
-
Constructor Summary
Constructors Constructor Description SocketReceiver()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private java.util.concurrent.Future<java.net.Socket>activateConnector(SocketConnector connector)voidconnectionFailed(SocketConnector connector, java.lang.Exception ex)private SocketConnectorcreateConnector(java.net.InetAddress address, int port, int initialDelay, int retryDelay)private voiddispatchEvents(LoggerContext lc)protected java.lang.RunnablegetRunnableTask()Provides the runnable task this receiver will execute.protected javax.net.SocketFactorygetSocketFactory()protected SocketConnectornewConnector(java.net.InetAddress address, int port, int initialDelay, int retryDelay)protected voidonStop()Allows a subclass to participate in receiver shutdown.voidrun()voidsetAcceptConnectionTimeout(int acceptConnectionTimeout)voidsetPort(int port)voidsetReconnectionDelay(int reconnectionDelay)voidsetRemoteHost(java.lang.String remoteHost)protected booleanshouldStart()Determines whether this receiver should start.private java.net.SocketwaitForConnectorToReturnASocket()-
Methods inherited from class ch.qos.logback.classic.net.ReceiverBase
isStarted, start, stop
-
Methods inherited from class ch.qos.logback.core.spi.ContextAwareBase
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, getDeclaredOrigin, getStatusManager, setContext
-
-
-
-
Field Detail
-
DEFAULT_ACCEPT_CONNECTION_DELAY
private static final int DEFAULT_ACCEPT_CONNECTION_DELAY
- See Also:
- Constant Field Values
-
remoteHost
private java.lang.String remoteHost
-
address
private java.net.InetAddress address
-
port
private int port
-
reconnectionDelay
private int reconnectionDelay
-
acceptConnectionTimeout
private int acceptConnectionTimeout
-
receiverId
private java.lang.String receiverId
-
socket
private volatile java.net.Socket socket
-
connectorTask
private java.util.concurrent.Future<java.net.Socket> connectorTask
-
-
Method Detail
-
shouldStart
protected boolean shouldStart()
Determines whether this receiver should start.Subclasses will implement this method to do any subclass-specific validation. The subclass's
ReceiverBase.getRunnableTask()method will be invoked (and the task returned will be submitted to the executor) if and only if this method returnstrue- Specified by:
shouldStartin classReceiverBase- Returns:
- flag indicating whether this receiver should start
-
onStop
protected void onStop()
Allows a subclass to participate in receiver shutdown.- Specified by:
onStopin classReceiverBase
-
getRunnableTask
protected java.lang.Runnable getRunnableTask()
Description copied from class:ReceiverBaseProvides the runnable task this receiver will execute.- Specified by:
getRunnableTaskin classReceiverBase- Returns:
- runnable task
-
run
public void run()
- Specified by:
runin interfacejava.lang.Runnable
-
createConnector
private SocketConnector createConnector(java.net.InetAddress address, int port, int initialDelay, int retryDelay)
-
activateConnector
private java.util.concurrent.Future<java.net.Socket> activateConnector(SocketConnector connector)
-
waitForConnectorToReturnASocket
private java.net.Socket waitForConnectorToReturnASocket() throws java.lang.InterruptedException- Throws:
java.lang.InterruptedException
-
dispatchEvents
private void dispatchEvents(LoggerContext lc)
-
connectionFailed
public void connectionFailed(SocketConnector connector, java.lang.Exception ex)
- Specified by:
connectionFailedin interfaceSocketConnector.ExceptionHandler
-
newConnector
protected SocketConnector newConnector(java.net.InetAddress address, int port, int initialDelay, int retryDelay)
-
getSocketFactory
protected javax.net.SocketFactory getSocketFactory()
-
setRemoteHost
public void setRemoteHost(java.lang.String remoteHost)
-
setPort
public void setPort(int port)
-
setReconnectionDelay
public void setReconnectionDelay(int reconnectionDelay)
-
setAcceptConnectionTimeout
public void setAcceptConnectionTimeout(int acceptConnectionTimeout)
-
-