Skip to content

Commit

Permalink
Deprecate AbstractLogstashTcpSocketAppender#secondaryConnectionTTL (#634
Browse files Browse the repository at this point in the history
)

Deprecate `AbstractLogstashTcpSocketAppender#secondaryConnectionTTL` in a backward compatible way (emit a warning if the propery is set during configuration)

fixes #633
  • Loading branch information
brenuart committed Sep 7, 2021
1 parent 1ee1d9b commit 6e917b7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
Expand Up @@ -1173,15 +1173,32 @@ public Duration getReconnectionDelay() {
* @see PreferPrimaryDestinationConnectionStrategy#setSecondaryConnectionTTL(Duration)
* @param secondaryConnectionTTL the TTL of a connection when connected to a secondary destination
* @throws IllegalStateException if the {@link #connectionStrategy} is not a {@link PreferPrimaryDestinationConnectionStrategy}
*
* @deprecated use {@link PreferPrimaryDestinationConnectionStrategy#setSecondaryConnectionTTL(Duration)} instead.
*/
@Deprecated
public void setSecondaryConnectionTTL(Duration secondaryConnectionTTL) {
addWarn(
"Setting <secondaryConnectionTTL> directly on the appender is deprecated. "
+ "Instead you should explicitly set the connection strategy to <preferPrimary> and set its <secondaryConnectionTTL> property to the desired value.");

if (connectionStrategy instanceof PreferPrimaryDestinationConnectionStrategy) {
((PreferPrimaryDestinationConnectionStrategy) connectionStrategy).setSecondaryConnectionTTL(secondaryConnectionTTL);
} else {
throw new IllegalStateException(String.format("When setting the secondaryConnectionTTL, the strategy must be a %s. It is currently a %s", PreferPrimaryDestinationConnectionStrategy.class, connectionStrategy));
}
}

/**
* Convenience method for accessing {@link PreferPrimaryDestinationConnectionStrategy#getSecondaryConnectionTTL()}.
*
* @return the secondary connection TTL or {@code null} if the connection strategy is not a {@link PreferPrimaryDestinationConnectionStrategy}.
* @deprecated use {@link PreferPrimaryDestinationConnectionStrategy#getSecondaryConnectionTTL()} instead.
*
* @see #getConnectionStrategy()
* @see PreferPrimaryDestinationConnectionStrategy#getSecondaryConnectionTTL()
*/
@Deprecated
public Duration getSecondaryConnectionTTL() {
if (connectionStrategy instanceof PreferPrimaryDestinationConnectionStrategy) {
return ((PreferPrimaryDestinationConnectionStrategy) connectionStrategy).getSecondaryConnectionTTL();
Expand Down Expand Up @@ -1237,7 +1254,7 @@ public void setWriteBufferSize(int writeBufferSize) {
* Alias for {@link #getRingBufferSize()}.
*
* @return the size of the ring buffer
* @deprecated use {@link #getRingBufferSize()} instead
* @deprecated use {@link #getRingBufferSize()} instead.
*/
@Deprecated
public int getQueueSize() {
Expand Down
Expand Up @@ -61,6 +61,7 @@
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.BasicStatusManager;
import ch.qos.logback.core.encoder.Encoder;
import ch.qos.logback.core.status.OnConsoleStatusListener;
import ch.qos.logback.core.status.Status;
import ch.qos.logback.core.status.StatusManager;
import ch.qos.logback.core.util.Duration;
Expand All @@ -84,8 +85,6 @@ public class LogstashTcpSocketAppenderTest {
@InjectMocks
private final LogstashTcpSocketAppender appender = new TestableLogstashTcpSocketAppender();

private LoggerContext context = new LoggerContext();

private StatusManager statusManager = new BasicStatusManager();

@Mock
Expand Down Expand Up @@ -121,6 +120,13 @@ protected Future<?> scheduleReaderCallable(Callable<Void> readerCallable) {

@BeforeEach
public void setup() throws IOException {
// Output statuses on the console for easy debugging. Must be initialized early to capture
// warnings emitted by setter/getter methods before the appender is started.
OnConsoleStatusListener consoleListener = new OnConsoleStatusListener();
consoleListener.start();
statusManager.add(consoleListener);

LoggerContext context = new LoggerContext();
context.setStatusManager(statusManager);

when(socketFactory.createSocket()).thenReturn(socket);
Expand Down

0 comments on commit 6e917b7

Please sign in to comment.