Class DelegateDestinationConnectionStrategy
java.lang.Object
ch.qos.logback.core.spi.ContextAwareBase
net.logstash.logback.appender.destination.DelegateDestinationConnectionStrategy
- All Implemented Interfaces:
ContextAware
,LifeCycle
,DestinationConnectionStrategy
public class DelegateDestinationConnectionStrategy
extends ContextAwareBase
implements DestinationConnectionStrategy, LifeCycle
A convenience class to make setting a
DestinationConnectionStrategy
cleaner in logback's xml configuration
when using the strategies provided by logstash-logback-encoder.
For example, instead of:
<appender name="tcp" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
<connectionStrategy class="net.logstash.logback.appender.destination.RoundRobinDestinationConnectionStrategy">
<connectionTTL>10 minutes</connectionTTL>
</connectionStrategy>
you can use:
<appender name="tcp" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
<connectionStrategy>
<roundRobin>
<connectionTTL>10 minutes</connectionTTL>
</roundRobin>
</connectionStrategy>
-
Field Summary
Fields inherited from class ch.qos.logback.core.spi.ContextAwareBase
context
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
connectFailed
(long connectionStartTimeInMillis, int failedDestinationIndex, int numDestinations) Called when a connection fails to the given failedDestinationIndex.void
connectSuccess
(long connectionStartTimeInMillis, int connectedDestinationIndex, int numDestinations) Called when a connection was successful to the given connectedDestinationIndex.boolean
int
selectNextDestinationIndex
(int previousDestinationIndex, int numDestinations) Returns the index of the destination to which to connect next.void
void
setRandom
(RandomDestinationConnectionStrategy strategy) void
boolean
shouldReconnect
(long currentTimeInMillis, int currentDestinationIndex, int numDestinations) Returns whether the connection should be reestablished.void
start()
void
stop()
Methods inherited from class ch.qos.logback.core.spi.ContextAwareBase
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, getDeclaredOrigin, getStatusManager, setContext
-
Constructor Details
-
DelegateDestinationConnectionStrategy
public DelegateDestinationConnectionStrategy()
-
-
Method Details
-
selectNextDestinationIndex
public int selectNextDestinationIndex(int previousDestinationIndex, int numDestinations) Description copied from interface:DestinationConnectionStrategy
Returns the index of the destination to which to connect next.- Specified by:
selectNextDestinationIndex
in interfaceDestinationConnectionStrategy
- Parameters:
previousDestinationIndex
- The previous destination index to which a connection was attempted (either success or failure)numDestinations
- The total number of destinations available.- Returns:
- the index of the destination to which to connect next.
-
connectSuccess
public void connectSuccess(long connectionStartTimeInMillis, int connectedDestinationIndex, int numDestinations) Description copied from interface:DestinationConnectionStrategy
Called when a connection was successful to the given connectedDestinationIndex.- Specified by:
connectSuccess
in interfaceDestinationConnectionStrategy
- Parameters:
connectionStartTimeInMillis
- The time in millis at which the connection was initiated (not completed).connectedDestinationIndex
- The index of the destination which was successfully connected.numDestinations
- The total number of destinations available.
-
connectFailed
public void connectFailed(long connectionStartTimeInMillis, int failedDestinationIndex, int numDestinations) Description copied from interface:DestinationConnectionStrategy
Called when a connection fails to the given failedDestinationIndex.- Specified by:
connectFailed
in interfaceDestinationConnectionStrategy
- Parameters:
connectionStartTimeInMillis
- The time in millis at which the connection was initiated (not completed).failedDestinationIndex
- The index of the destination which failed to connect.numDestinations
- The total number of destinations available.
-
shouldReconnect
public boolean shouldReconnect(long currentTimeInMillis, int currentDestinationIndex, int numDestinations) Description copied from interface:DestinationConnectionStrategy
Returns whether the connection should be reestablished.- Specified by:
shouldReconnect
in interfaceDestinationConnectionStrategy
- Parameters:
currentTimeInMillis
- The time in millis for which to reevaluate whether the connection should be reestablished.currentDestinationIndex
- The index of the destination which is currently connectednumDestinations
- The total number of destinations available.- Returns:
- true if the connection should be reestablished (to the destination returned by the next call to
DestinationConnectionStrategy.selectNextDestinationIndex(int, int)
, false otherwise.
-
start
public void start() -
stop
public void stop() -
isStarted
public boolean isStarted() -
setPreferPrimary
-
setRandom
-
setRoundRobin
-