Skip to content

Commit

Permalink
[netty#1612] Allow to disable resource leak detection via API
Browse files Browse the repository at this point in the history
  • Loading branch information
Norman Maurer committed Jul 22, 2013
1 parent ada07cb commit 2bbad8e
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion common/src/main/java/io/netty/util/ResourceLeakDetector.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public final class ResourceLeakDetector<T> {

private static final boolean DISABLED = SystemPropertyUtil.getBoolean("io.netty.noResourceLeakDetection", false);

private static volatile boolean disabled = DISABLED;

public static final boolean ENABLED = !DISABLED;

private static final InternalLogger logger = InternalLoggerFactory.getInstance(ResourceLeakDetector.class);
Expand All @@ -47,6 +49,20 @@ public boolean close() {
}
};

/**
* Allow to disable resource leak detection
*/
public static void setDisabled(boolean disabled) {
ResourceLeakDetector.disabled = disabled;
}

/**
* Returns {@code true} if resource leak detection is turned off.
*/
public static boolean isDisabled() {
return disabled;
}

/** the linked list of active resources */
private final DefaultResourceLeak head = new DefaultResourceLeak(null);
private final DefaultResourceLeak tail = new DefaultResourceLeak(null);
Expand Down Expand Up @@ -94,7 +110,7 @@ public ResourceLeakDetector(String resourceType, int samplingInterval, long maxA
}

public ResourceLeak open(T obj) {
if (DISABLED || leakCheckCnt ++ % samplingInterval != 0) {
if (disabled || leakCheckCnt ++ % samplingInterval != 0) {
return NOOP;
}

Expand Down

0 comments on commit 2bbad8e

Please sign in to comment.