ch.qos.logback.core.net

## Class AbstractSocketAppender<E>

- java.lang.Object
- - ch.qos.logback.core.spi.ContextAwareBase
  - - ch.qos.logback.core.AppenderBase<E>
    - - ch.qos.logback.core.net.AbstractSocketAppender<E>

All Implemented Interfaces:
  Appender<E>, SocketConnector.ExceptionHandler, ContextAware, FilterAttachable<E>, LifeCycle, java.lang.Runnable

Direct Known Subclasses:
  AbstractSSLSocketAppender, SocketAppender

    public abstract class AbstractSocketAppender<E>
    extends AppenderBase<E>
    implements java.lang.Runnable, SocketConnector.ExceptionHandler

An abstract base for module specific `SocketAppender` implementations in other logback modules.

Author:
  Ceki Gülcü, Sébastien Pennec, Carl Harris

### Field Summary

Fields
`static int` `DEFAULT_PORT` The default port number of remote logging server (4560).
`static int` `DEFAULT_QUEUE_SIZE` Default size of the queue used to hold logging events that are destined for the remote peer.
`static int` `DEFAULT_RECONNECTION_DELAY` The default reconnection delay (30000 milliseconds or 30 seconds).

### Fields inherited from class ch.qos.logback.core.AppenderBase

`name, started`

### Fields inherited from class ch.qos.logback.core.spi.ContextAwareBase

`context`

### Constructor Summary

Constructors
`protected` `AbstractSocketAppender()` Constructs a new appender.
`protected` `AbstractSocketAppender(java.lang.String remoteHost, int port)` Deprecated.

### Method Summary

Methods
`protected void` `append(E event)`
`void` `connectionFailed(SocketConnector connector, java.lang.Exception ex)`
`protected static java.net.InetAddress` `getAddressByName(java.lang.String host)` Deprecated.
`int` `getPort()` Returns value of the Port property.
`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.
`int` `getQueueSize()` Returns the value of the queueSize property.
`int` `getReconnectionDelay()` Returns value of the reconnectionDelay property.
`java.lang.String` `getRemoteHost()` Returns value of the RemoteHost property.
`protected javax.net.SocketFactory` `getSocketFactory()` Gets the default `SocketFactory` for the platform.
`protected SocketConnector` `newConnector(java.net.InetAddress address, int port, int initialDelay, int retryDelay)` Creates a new `SocketConnector`.
`protected abstract void` `postProcessEvent(E event)` Post-processes an event before it is serialized for delivery to the remote receiver.
`void` `run()`
`void` `setPort(int port)` The Port property takes a positive integer representing the port where the server is waiting for connections.
`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.
`void` `setReconnectionDelay(int delay)` The reconnectionDelay property takes a positive integer representing the number of milliseconds to wait between each failed connection attempt to the server.
`void` `setRemoteHost(java.lang.String host)` The RemoteHost property takes the name of of the host where a corresponding server is running.
`void` `start()`
`void` `stop()`

### Methods inherited from class ch.qos.logback.core.AppenderBase

`addFilter, clearAllFilters, doAppend, getCopyOfAttachedFiltersList, getFilterChainDecision, getName, isStarted, setName, toString`

### Methods inherited from class ch.qos.logback.core.spi.ContextAwareBase

`addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, getDeclaredOrigin, getStatusManager, setContext`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Methods inherited from interface ch.qos.logback.core.spi.ContextAware

`addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, setContext`

### Field Detail

#### DEFAULT_PORT

    public static final int DEFAULT_PORT

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

See Also:
  Constant Field Values

#### DEFAULT_RECONNECTION_DELAY

    public static final int DEFAULT_RECONNECTION_DELAY

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

See Also:
  Constant Field Values

#### DEFAULT_QUEUE_SIZE

    public static final int DEFAULT_QUEUE_SIZE

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

See Also:
  Constant Field Values

### Constructor Detail

#### AbstractSocketAppender

    protected AbstractSocketAppender()

Constructs a new appender.

#### AbstractSocketAppender

    @Deprecated
    protected AbstractSocketAppender(java.lang.String remoteHost,
                                     int port)

Deprecated.
Constructs a new appender that will connect to the given remote host and port.

This constructor was introduced primarily to allow the encapsulation of the this class to be improved in a manner that is least disruptive to existing subclasses. This constructor will be removed in future release.

Parameters:
  `remoteHost` - target remote host
  `port` - target port on remote host

### Method Detail

#### start

    public void start()

Specified by:
  `start` in interface `LifeCycle`
Overrides:
  `start` in class `AppenderBase<E>`

#### stop

    public void stop()

Specified by:
  `stop` in interface `LifeCycle`
Overrides:
  `stop` in class `AppenderBase<E>`

#### append

    protected void append(E event)

Specified by:
  `append` in class `AppenderBase<E>`

#### run

    public final void run()

Specified by:
  `run` in interface `java.lang.Runnable`

#### connectionFailed

    public void connectionFailed(SocketConnector connector,
                        java.lang.Exception ex)

Specified by:
  `connectionFailed` in interface `SocketConnector.ExceptionHandler`

#### newConnector

    protected SocketConnector newConnector(java.net.InetAddress address,
                               int port,
                               int initialDelay,
                               int 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` - target remote address
  `port` - target remote port
  `initialDelay` - delay before the first connection attempt
  `retryDelay` - delay before a reconnection attempt
Returns:
  socket connector

#### getSocketFactory

    protected javax.net.SocketFactory getSocketFactory()

Gets the default `SocketFactory` for the platform.

Subclasses may override to provide a custom socket factory.

#### postProcessEvent

    protected abstract void postProcessEvent(E event)

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

Parameters:
  `event` - the event to post-process

#### getPST

    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:
  transformer object

#### getAddressByName

    @Deprecated
    protected static java.net.InetAddress getAddressByName(java.lang.String host)

Deprecated.

#### setRemoteHost

    public void setRemoteHost(java.lang.String host)

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

#### getRemoteHost

    public java.lang.String getRemoteHost()

Returns value of the RemoteHost property.

#### setPort

    public void setPort(int port)

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

#### getPort

    public int getPort()

Returns value of the Port property.

#### setReconnectionDelay

    public void setReconnectionDelay(int delay)

The reconnectionDelay property 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.

#### getReconnectionDelay

    public int getReconnectionDelay()

Returns value of the reconnectionDelay property.

#### setQueueSize

    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 queue size is zero, event delivery to the remote receiver is synchronous. When the queue size is greater than zero, the `append(Object)` method returns immediately after enqueing the event, assuming that there is space available in the queue. Using a non-zero queue length can improve performance by eliminating delays caused by transient network delays. If the queue is full when the `append(Object)` method is called, the event is summarily and silently dropped.

Parameters:
  `queueSize` - the queue size to set.

#### getQueueSize

    public int getQueueSize()

Returns the value of the queueSize property.