- java.lang.Object
-
- io.netty5.util.ResourceLeakDetector<T>
-
public class ResourceLeakDetector<T> extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ResourceLeakDetector.Level
Represents the level of resource leak detection.
-
Constructor Summary
Constructors Constructor Description ResourceLeakDetector(Class<?> resourceType, int samplingInterval)
This should not be used directly by users ofResourceLeakDetector
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static void
addExclusions(Class<?> clz, String... methodNames)
protected Object
getInitialHint(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.protected void
reportInstancesLeak(String resourceType)
Deprecated.This method will no longer be invoked byResourceLeakDetector
.protected void
reportTracedLeak(String resourceType, String records)
This method is called when a traced leak is detected.protected void
reportUntracedLeak(String resourceType)
This method is called when an untraced leak is detected.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.
-
-
-
Constructor Detail
-
ResourceLeakDetector
public ResourceLeakDetector(Class<?> resourceType, int samplingInterval)
This should not be used directly by users ofResourceLeakDetector
. Please useResourceLeakDetectorFactory.newResourceLeakDetector(Class)
orResourceLeakDetectorFactory.newResourceLeakDetector(Class, int)
-
-
Method Detail
-
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.
-
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
-
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(String resourceType, 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(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(String resourceType)
Deprecated.This method will no longer be invoked byResourceLeakDetector
.
-
getInitialHint
protected Object getInitialHint(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.
-
-