Top Description Fields Constructors Methods
ch.qos.logback.core.net

public abstract Class AbstractSocketAppender<E>

extends AppenderBase<E>
implements ExceptionHandler
Class Inheritance
All Implemented Interfaces
ch.qos.logback.core.net.SocketConnector.ExceptionHandler
Known Direct Subclasses
ch.qos.logback.core.net.AbstractSSLSocketAppender
Imports
java.io.IOException, .Serializable, java.net.ConnectException, .InetAddress, .Socket, .UnknownHostException, java.util.concurrent.BlockingDeque, .Future, .TimeUnit, javax.net.SocketFactory, ch.qos.logback.core.AppenderBase, ch.qos.logback.core.spi.PreSerializationTransformer, ch.qos.logback.core.util.CloseUtil, .Duration

An abstract base for module specific SocketAppender implementations in other logback modules.
Authors
Ceki Gülcü, Sébastien Pennec, Carl Harris, Sebastian Gröbler

Field Summary

Modifier and TypeField and Description
private int
private InetAddress
private SocketConnector
private static final int
DEFAULT_ACCEPT_CONNECTION_DELAY

Default timeout when waiting for the remote server to accept our connection.

private static final int
DEFAULT_EVENT_DELAY_TIMEOUT

Default timeout for how long to wait when inserting an event into the BlockingQueue.

public static final int
DEFAULT_PORT

The default port number of remote logging server (4560).

public static final int
DEFAULT_QUEUE_SIZE

Default size of the deque used to hold logging events that are destined for the remote peer.

public static final int
DEFAULT_RECONNECTION_DELAY

The default reconnection delay (30000 milliseconds or 30 seconds).

private BlockingDeque<E>
private Duration
private final ObjectWriterFactory
private String
private int
private final QueueFactory
private int
private Duration
private String
private volatile Socket
private Future<?>
Inherited from ch.qos.logback.core.AppenderBase:
namestarted

Constructor Summary

AccessConstructor and Description
protected
AbstractSocketAppender()

Constructs a new appender.

pack-priv
AbstractSocketAppender(QueueFactory queueFactory, ObjectWriterFactory objectWriterFactory)

Constructs a new appender using the given QueueFactory and ObjectWriterFactory.

Method Summary

Modifier and TypeMethod and Description
protected void
append(E event)

Implements abstract ch.qos.logback.core.AppenderBase.append.

public void
private void
private SocketConnector
createConnector(InetAddress address, int port, int initialDelay, long retryDelay)

private ObjectWriter
private void
public Duration
getEventDelayLimit()

Returns the value of the eventDelayLimit property.

public int
getPort()

Returns value of the Port property.

protected abstract PreSerializationTransformer<E>

Returns:

transformer object
getPST
()

Get the pre-serialization transformer that will be used to transform each event into a Serializable object before delivery to the remote receiver.

public int
getQueueSize()

Returns the value of the queueSize property.

public Duration
getReconnectionDelay()

Returns value of the reconnectionDelay property.

public String
getRemoteHost()

Returns value of the RemoteHost property.

protected SocketFactory
getSocketFactory()

Gets the default SocketFactory for the platform.

protected SocketConnector

Returns:

socket connector
newConnector
(InetAddress
target remote address
address
,
int
target remote port
port
,
long
delay before the first connection attempt
initialDelay
,
long
delay before a reconnection attempt
retryDelay
)

Creates a new SocketConnector.

protected abstract void
postProcessEvent(E
the event to post-process
event
)

Post-processes an event before it is serialized for delivery to the remote receiver.

pack-priv void
setAcceptConnectionTimeout(int
timeout value in milliseconds
acceptConnectionTimeout
)

Sets the timeout that controls how long we'll wait for the remote peer to accept our connection attempt.

public void
setEventDelayLimit(Duration
the event delay limit
eventDelayLimit
)

The eventDelayLimit takes a non-negative integer representing the number of milliseconds to allow the appender to block if the underlying BlockingQueue is full.

public void
setPort(int port)

The Port property takes a positive integer representing the port where the server is waiting for connections.

public void
setQueueSize(int
the deque size to set.
queueSize
)

The queueSize property takes a non-negative integer representing the number of logging events to retain for delivery to the remote receiver.

public void
setReconnectionDelay(Duration delay)

The reconnectionDelay property takes a positive Duration value representing the time to wait between each failed connection attempt to the server.

public void
setRemoteHost(String host)

The RemoteHost property takes the name of the host where a corresponding server is running.

private boolean
public void
public void
private void
Inherited from ch.qos.logback.core.AppenderBase:
addFilterclearAllFiltersdoAppendgetCopyOfAttachedFiltersListgetFilterChainDecisiongetNameisStartedsetNametoString

Field Detail

acceptConnectionTimeoutback to summary
private int acceptConnectionTimeout
addressback to summary
private InetAddress address
connectorback to summary
private SocketConnector connector
DEFAULT_ACCEPT_CONNECTION_DELAYback to summary
private static final int DEFAULT_ACCEPT_CONNECTION_DELAY

Default timeout when waiting for the remote server to accept our connection.

DEFAULT_EVENT_DELAY_TIMEOUTback to summary
private static final int DEFAULT_EVENT_DELAY_TIMEOUT

Default timeout for how long to wait when inserting an event into the BlockingQueue.

DEFAULT_PORTback to summary
public static final int DEFAULT_PORT

The default port number of remote logging server (4560).

DEFAULT_QUEUE_SIZEback to summary
public static final int DEFAULT_QUEUE_SIZE

Default size of the deque used to hold logging events that are destined for the remote peer.

DEFAULT_RECONNECTION_DELAYback to summary
public static final int DEFAULT_RECONNECTION_DELAY

The default reconnection delay (30000 milliseconds or 30 seconds).

dequeback to summary
private BlockingDeque<E> deque
eventDelayLimitback to summary
private Duration eventDelayLimit
objectWriterFactoryback to summary
private final ObjectWriterFactory objectWriterFactory
peerIdback to summary
private String peerId
portback to summary
private int port
queueFactoryback to summary
private final QueueFactory queueFactory
queueSizeback to summary
private int queueSize
reconnectionDelayback to summary
private Duration reconnectionDelay
remoteHostback to summary
private String remoteHost
socketback to summary
private volatile Socket socket
taskback to summary
private Future<?> task

Constructor Detail

AbstractSocketAppenderback to summary
protected AbstractSocketAppender()

Constructs a new appender.

AbstractSocketAppenderback to summary
pack-priv AbstractSocketAppender(QueueFactory queueFactory, ObjectWriterFactory objectWriterFactory)

Constructs a new appender using the given QueueFactory and ObjectWriterFactory.

Method Detail

appendback to summary
protected void append(E event)

Implements abstract ch.qos.logback.core.AppenderBase.append.

Annotations
@Override
connectionFailedback to summary
public void connectionFailed(SocketConnector connector, Exception ex)

Implements ch.qos.logback.core.net.SocketConnector.ExceptionHandler.connectionFailed.

connectSocketAndDispatchEventsback to summary
private void connectSocketAndDispatchEvents()
createConnectorback to summary
private SocketConnector createConnector(InetAddress address, int port, int initialDelay, long retryDelay)
createObjectWriterForSocketback to summary
private ObjectWriter createObjectWriterForSocket() throws IOException
dispatchEventsback to summary
private void dispatchEvents(ObjectWriter objectWriter) throws InterruptedException, IOException
getEventDelayLimitback to summary
public Duration getEventDelayLimit()

Returns the value of the eventDelayLimit property.

getPortback to summary
public int getPort()

Returns value of the Port property.

getPSTback to summary
protected abstract PreSerializationTransformer<E> getPST()

Get the pre-serialization transformer that will be used to transform each event into a Serializable object before delivery to the remote receiver.

Returns:PreSerializationTransformer<E>

transformer object

getQueueSizeback to summary
public int getQueueSize()

Returns the value of the queueSize property.

getReconnectionDelayback to summary
public Duration getReconnectionDelay()

Returns value of the reconnectionDelay property.

getRemoteHostback to summary
public String getRemoteHost()

Returns value of the RemoteHost property.

getSocketFactoryback to summary
protected SocketFactory getSocketFactory()

Gets the default SocketFactory for the platform.

Subclasses may override to provide a custom socket factory.

newConnectorback to summary
protected SocketConnector newConnector(InetAddress address, int port, long initialDelay, long retryDelay)

Creates a new SocketConnector.

The default implementation creates an instance of DefaultSocketConnector. A subclass may override to provide a different SocketConnector implementation.

Parameters
address:InetAddress

target remote address

port:int

target remote port

initialDelay:long

delay before the first connection attempt

retryDelay:long

delay before a reconnection attempt

Returns:SocketConnector

socket connector

postProcessEventback to summary
protected abstract void postProcessEvent(E event)

Post-processes an event before it is serialized for delivery to the remote receiver.

Parameters
event:E

the event to post-process

setAcceptConnectionTimeoutback to summary
pack-priv void setAcceptConnectionTimeout(int acceptConnectionTimeout)

Sets the timeout that controls how long we'll wait for the remote peer to accept our connection attempt.

This property is configurable primarily to support instrumentation for unit testing.

Parameters
acceptConnectionTimeout:int

timeout value in milliseconds

setEventDelayLimitback to summary
public void setEventDelayLimit(Duration eventDelayLimit)

The eventDelayLimit takes a non-negative integer representing the number of milliseconds to allow the appender to block if the underlying BlockingQueue is full. Once this limit is reached, the event is dropped.

Parameters
eventDelayLimit:Duration

the event delay limit

setPortback to summary
public void setPort(int port)

The Port property takes a positive integer representing the port where the server is waiting for connections.

setQueueSizeback to summary
public void setQueueSize(int queueSize)

The queueSize property takes a non-negative integer representing the number of logging events to retain for delivery to the remote receiver. When the deque size is zero, event delivery to the remote receiver is synchronous. When the deque size is greater than zero, the append(Object) method returns immediately after enqueing the event, assuming that there is space available in the deque. Using a non-zero deque length can improve performance by eliminating delays caused by transient network delays.

Parameters
queueSize:int

the deque size to set.

setReconnectionDelayback to summary
public void setReconnectionDelay(Duration delay)

The reconnectionDelay property takes a positive Duration value representing the time to wait between each failed connection attempt to the server. The default value of this option is to 30 seconds.

Setting this option to zero turns off reconnection capability.

setRemoteHostback to summary
public void setRemoteHost(String host)

The RemoteHost property takes the name of the host where a corresponding server is running.

socketConnectionCouldBeEstablishedback to summary
private boolean socketConnectionCouldBeEstablished() throws InterruptedException
startback to summary
public void start()

Overrides ch.qos.logback.core.AppenderBase.start.

Implements ch.qos.logback.core.spi.LifeCycle.start.

stopback to summary
public void stop()

Overrides ch.qos.logback.core.AppenderBase.stop.

Implements ch.qos.logback.core.spi.LifeCycle.stop.

Annotations
@Override
tryReAddingEventToFrontOfQueueback to summary
private void tryReAddingEventToFrontOfQueue(E event)