Skip to content

Commit

Permalink
Level initialization cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
doom369 authored and Scottmitch committed Jan 19, 2017
1 parent 9a4aa61 commit 0e654f7
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions common/src/main/java/io/netty/util/ResourceLeakDetector.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import java.lang.ref.ReferenceQueue;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.EnumSet;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicBoolean;

Expand Down Expand Up @@ -66,7 +65,23 @@ public enum Level {
* Enables paranoid resource leak detection which reports where the leaked object was accessed recently,
* at the cost of the highest possible overhead (for testing purposes only).
*/
PARANOID
PARANOID;

/**
* Returns level based on string value. Accepts also string that represents ordinal number of enum.
*
* @param levelStr - level string : DISABLED, SIMPLE, ADVANCED, PARANOID. Ignores case.
* @return corresponding level or SIMPLE level in case of no match.
*/
static Level parseLevel(String levelStr) {
String trimmedLevelStr = levelStr.trim();
for (Level l : values()) {
if (trimmedLevelStr.equalsIgnoreCase(l.name()) || trimmedLevelStr.equals(String.valueOf(l.ordinal()))) {
return l;
}
}
return DEFAULT_LEVEL;
}
}

private static Level level;
Expand All @@ -88,16 +103,11 @@ public enum Level {
Level defaultLevel = disabled? Level.DISABLED : DEFAULT_LEVEL;

// First read old property name
String levelStr = SystemPropertyUtil.get(PROP_LEVEL_OLD, defaultLevel.name()).trim().toUpperCase();
String levelStr = SystemPropertyUtil.get(PROP_LEVEL_OLD, defaultLevel.name());

// If new property name is present, use it
levelStr = SystemPropertyUtil.get(PROP_LEVEL, levelStr).trim().toUpperCase();
Level level = DEFAULT_LEVEL;
for (Level l: EnumSet.allOf(Level.class)) {
if (levelStr.equals(l.name()) || levelStr.equals(String.valueOf(l.ordinal()))) {
level = l;
}
}
levelStr = SystemPropertyUtil.get(PROP_LEVEL, levelStr);
Level level = Level.parseLevel(levelStr);

MAX_RECORDS = SystemPropertyUtil.getInt(PROP_MAX_RECORDS, DEFAULT_MAX_RECORDS);

Expand Down

0 comments on commit 0e654f7

Please sign in to comment.