Skip to content

Commit

Permalink
[UNDERTOW-1794] Add properties to allow set retry count/delay
Browse files Browse the repository at this point in the history
  • Loading branch information
baranowb committed May 14, 2024
1 parent 0402edc commit db0351a
Showing 1 changed file with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
Expand All @@ -52,6 +54,8 @@ public class DefaultAccessLogReceiver implements AccessLogReceiver, Runnable, Cl
private static final String DEFAULT_LOG_SUFFIX = "log";
private static final int DEFAULT_RETRY_COUNT = 150;
private static final int DEFAULT_RETRY_DELAY = 200;
public static final String DEFAULT_RETRY_COUNT_PROPERTY = "io.undertow.accesslog.logreceiver.retryCount";
public static final String DEFAULT_RETRY_DELAY_PROPERTY = "io.undertow.accesslog.logreceiver.retryDelay";

private final Executor logWriteExecutor;

Expand Down Expand Up @@ -82,8 +86,8 @@ public class DefaultAccessLogReceiver implements AccessLogReceiver, Runnable, Cl
private boolean initialRun = true;
private final boolean rotate;
private final LogFileHeaderGenerator fileHeaderGenerator;
private final int closeRetryCount = DEFAULT_RETRY_COUNT;
private final int closeRetryDelay = DEFAULT_RETRY_DELAY;
private final int closeRetryCount;
private final int closeRetryDelay;

public DefaultAccessLogReceiver(final Executor logWriteExecutor, final File outputDirectory, final String logBaseName) {
this(logWriteExecutor, outputDirectory.toPath(), logBaseName, null);
Expand All @@ -109,6 +113,7 @@ public DefaultAccessLogReceiver(final Executor logWriteExecutor, final Path outp
this(logWriteExecutor, outputDirectory, logBaseName, logNameSuffix, rotate, null);
}

@SuppressWarnings({ "removal", "deprecation" })
public DefaultAccessLogReceiver(final Executor logWriteExecutor, final Path outputDirectory, final String logBaseName, final String logNameSuffix, boolean rotate, LogFileHeaderGenerator fileHeader) {
this.logWriteExecutor = logWriteExecutor;
this.outputDirectory = outputDirectory;
Expand All @@ -119,6 +124,24 @@ public DefaultAccessLogReceiver(final Executor logWriteExecutor, final Path outp
this.pendingMessages = new ConcurrentLinkedDeque<>();
this.defaultLogFile = outputDirectory.resolve(logBaseName + this.logNameSuffix);
calculateChangeOverPoint();

String property = System.getSecurityManager() == null ? System.getProperty(DEFAULT_RETRY_COUNT_PROPERTY)
: AccessController.doPrivileged(new PrivilegedAction<String>() {
@Override
public String run() {
return System.getProperty(DEFAULT_RETRY_COUNT_PROPERTY);
}
});
this.closeRetryCount = property == null ? DEFAULT_RETRY_COUNT : Integer.parseInt(property);

property = System.getSecurityManager() == null ? System.getProperty(DEFAULT_RETRY_DELAY_PROPERTY)
: AccessController.doPrivileged(new PrivilegedAction<String>() {
@Override
public String run() {
return System.getProperty(DEFAULT_RETRY_DELAY_PROPERTY);
}
});
this.closeRetryDelay = property == null ? DEFAULT_RETRY_DELAY : Integer.parseInt(property);
}

private void calculateChangeOverPoint() {
Expand Down

0 comments on commit db0351a

Please # to comment.