remkop commented on code in PR #824:
URL: https://github.com/apache/logging-log4j2/pull/824#discussion_r852928498
##########
log4j-core/src/main/java/org/apache/logging/log4j/core/async/DefaultAsyncWaitStrategyFactory.java:
##########
@@ -0,0 +1,79 @@
+package org.apache.logging.log4j.core.async;
+
+import com.lmax.disruptor.BlockingWaitStrategy;
+import com.lmax.disruptor.BusySpinWaitStrategy;
+import com.lmax.disruptor.SleepingWaitStrategy;
+import com.lmax.disruptor.TimeoutBlockingWaitStrategy;
+import com.lmax.disruptor.WaitStrategy;
+import com.lmax.disruptor.YieldingWaitStrategy;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.status.StatusLogger;
+import org.apache.logging.log4j.util.PropertiesUtil;
+import org.apache.logging.log4j.util.Strings;
+
+import java.util.concurrent.TimeUnit;
+
+class DefaultAsyncWaitStrategyFactory implements AsyncWaitStrategyFactory {
+ static final String DEFAULT_WAIT_STRATEGY_CLASSNAME =
TimeoutBlockingWaitStrategy.class.getName();
+ private static final Logger LOGGER = StatusLogger.getLogger();
+ private final String propertyName;
+
+ public DefaultAsyncWaitStrategyFactory(String propertyName) {
+ this.propertyName = propertyName;
+ }
+
+ @Override
+ public WaitStrategy createWaitStrategy() {
+ final String strategy =
PropertiesUtil.getProperties().getStringProperty(propertyName, "TIMEOUT");
+ LOGGER.trace("DefaultAsyncWaitStrategyFactory property {}={}",
propertyName, strategy);
+ final String strategyUp = Strings.toRootUpperCase(strategy);
+ // String (not enum) is deliberately used here to avoid
IllegalArgumentException being thrown. In case of
+ // incorrect property value, default WaitStrategy is created.
+ switch (strategyUp) {
Review Comment:
(This is actually existing code, moved into a new class, but that is just an
aside.) :-)
I do love enums myself but in this case it would not be useful to create one.
In case the user specifies an undefined value like "BLAHBLAH" we need to
handle that by falling back to the default WaitStrategy. If we have an enum we
would first need to convert the user-specified String value into an enum value,
and then catch the IllegalArgumentException for the undefined value and fall
back to the default.
Using an enum would give no benefit, but the resulting code would be more
clumsy than the current code.
That is why the implementation comment says "String (not enum) is
deliberately used here (...)".
So I prefer to leave it as is.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]