Package io.netty.util
Class ResourceLeakDetector<T>
- java.lang.Object
-
- io.netty.util.ResourceLeakDetector<T>
-
public class ResourceLeakDetector<T> extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
ResourceLeakDetector.LeakListener
static class
ResourceLeakDetector.Level
Represents the level of resource leak detection.
-
Constructor Summary
Constructors Constructor Description ResourceLeakDetector(java.lang.Class<?> resourceType)
ResourceLeakDetector(java.lang.Class<?> resourceType, int samplingInterval)
This should not be used directly by users ofResourceLeakDetector
.ResourceLeakDetector(java.lang.Class<?> resourceType, int samplingInterval, long maxActive)
Deprecated.ResourceLeakDetector(java.lang.String resourceType)
ResourceLeakDetector(java.lang.String resourceType, int samplingInterval, long maxActive)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static void
addExclusions(java.lang.Class clz, java.lang.String... methodNames)
protected java.lang.Object
getInitialHint(java.lang.String resourceType)
Create a hint object to be attached to an object tracked by this record.static ResourceLeakDetector.Level
getLevel()
Returns the current resource leak detection level.static boolean
isEnabled()
Returnstrue
if resource leak detection is enabled.protected boolean
needReport()
When the return value istrue
,reportTracedLeak(java.lang.String, java.lang.String)
andreportUntracedLeak(java.lang.String)
will be called once a leak is detected, otherwise not.ResourceLeak
open(T obj)
Deprecated.usetrack(Object)
protected void
reportInstancesLeak(java.lang.String resourceType)
Deprecated.This method will no longer be invoked byResourceLeakDetector
.protected void
reportTracedLeak(java.lang.String resourceType, java.lang.String records)
This method is called when a traced leak is detected.protected void
reportUntracedLeak(java.lang.String resourceType)
This method is called when an untraced leak is detected.static void
setEnabled(boolean enabled)
Deprecated.UsesetLevel(Level)
instead.void
setLeakListener(ResourceLeakDetector.LeakListener leakListener)
Set leak listener.static void
setLevel(ResourceLeakDetector.Level level)
Sets the resource leak detection level.ResourceLeakTracker<T>
track(T obj)
Creates a newResourceLeakTracker
which is expected to be closed viaResourceLeakTracker.close(Object)
when the related resource is deallocated.ResourceLeakTracker<T>
trackForcibly(T obj)
Creates a newResourceLeakTracker
which is expected to be closed viaResourceLeakTracker.close(Object)
when the related resource is deallocated.
-
-
-
Constructor Detail
-
ResourceLeakDetector
@Deprecated public ResourceLeakDetector(java.lang.Class<?> resourceType)
-
ResourceLeakDetector
@Deprecated public ResourceLeakDetector(java.lang.String resourceType)
-
ResourceLeakDetector
@Deprecated public ResourceLeakDetector(java.lang.Class<?> resourceType, int samplingInterval, long maxActive)
Deprecated.UseResourceLeakDetector(Class, int)
.This should not be used directly by users of
ResourceLeakDetector
. Please useResourceLeakDetectorFactory.newResourceLeakDetector(Class)
orResourceLeakDetectorFactory.newResourceLeakDetector(Class, int, long)
- Parameters:
maxActive
- This is deprecated and will be ignored.
-
ResourceLeakDetector
public ResourceLeakDetector(java.lang.Class<?> resourceType, int samplingInterval)
This should not be used directly by users ofResourceLeakDetector
. Please useResourceLeakDetectorFactory.newResourceLeakDetector(Class)
orResourceLeakDetectorFactory.newResourceLeakDetector(Class, int, long)
-
ResourceLeakDetector
@Deprecated public ResourceLeakDetector(java.lang.String resourceType, int samplingInterval, long maxActive)
- Parameters:
maxActive
- This is deprecated and will be ignored.
-
-
Method Detail
-
setEnabled
@Deprecated public static void setEnabled(boolean enabled)
Deprecated.UsesetLevel(Level)
instead.
-
isEnabled
public static boolean isEnabled()
Returnstrue
if resource leak detection is enabled.
-
setLevel
public static void setLevel(ResourceLeakDetector.Level level)
Sets the resource leak detection level.
-
getLevel
public static ResourceLeakDetector.Level getLevel()
Returns the current resource leak detection level.
-
open
@Deprecated public final ResourceLeak open(T obj)
Deprecated.usetrack(Object)
Creates a newResourceLeak
which is expected to be closed viaResourceLeak.close()
when the related resource is deallocated.- Returns:
- the
ResourceLeak
ornull
-
track
public final ResourceLeakTracker<T> track(T obj)
Creates a newResourceLeakTracker
which is expected to be closed viaResourceLeakTracker.close(Object)
when the related resource is deallocated.- Returns:
- the
ResourceLeakTracker
ornull
-
trackForcibly
public ResourceLeakTracker<T> trackForcibly(T obj)
Creates a newResourceLeakTracker
which is expected to be closed viaResourceLeakTracker.close(Object)
when the related resource is deallocated. Unliketrack(Object)
, this method always returns a tracker, regardless of the detection settings.- Returns:
- the
ResourceLeakTracker
-
needReport
protected boolean needReport()
When the return value istrue
,reportTracedLeak(java.lang.String, java.lang.String)
andreportUntracedLeak(java.lang.String)
will be called once a leak is detected, otherwise not.- Returns:
true
to enable leak reporting.
-
reportTracedLeak
protected void reportTracedLeak(java.lang.String resourceType, java.lang.String records)
This method is called when a traced leak is detected. It can be overridden for tracking how many times leaks have been detected.
-
reportUntracedLeak
protected void reportUntracedLeak(java.lang.String resourceType)
This method is called when an untraced leak is detected. It can be overridden for tracking how many times leaks have been detected.
-
reportInstancesLeak
@Deprecated protected void reportInstancesLeak(java.lang.String resourceType)
Deprecated.This method will no longer be invoked byResourceLeakDetector
.
-
getInitialHint
protected java.lang.Object getInitialHint(java.lang.String resourceType)
Create a hint object to be attached to an object tracked by this record. Similar to the additional information supplied toResourceLeakTracker.record(Object)
, will be printed alongside the stack trace of the creation of the resource.
-
setLeakListener
public void setLeakListener(ResourceLeakDetector.LeakListener leakListener)
Set leak listener. Previous listener will be replaced.
-
addExclusions
public static void addExclusions(java.lang.Class clz, java.lang.String... methodNames)
-
-