- 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 classResourceLeakDetector.LevelRepresents 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 voidaddExclusions(Class<?> clz, String... methodNames)protected ObjectgetInitialHint(String resourceType)Create a hint object to be attached to an object tracked by this record.static ResourceLeakDetector.LevelgetLevel()Returns the current resource leak detection level.static booleanisEnabled()Returnstrueif resource leak detection is enabled.protected booleanneedReport()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 voidreportInstancesLeak(String resourceType)Deprecated.This method will no longer be invoked byResourceLeakDetector.protected voidreportTracedLeak(String resourceType, String records)This method is called when a traced leak is detected.protected voidreportUntracedLeak(String resourceType)This method is called when an untraced leak is detected.static voidsetLevel(ResourceLeakDetector.Level level)Sets the resource leak detection level.ResourceLeakTracker<T>track(T obj)Creates a newResourceLeakTrackerwhich 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()
Returnstrueif 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 newResourceLeakTrackerwhich is expected to be closed viaResourceLeakTracker.close(Object)when the related resource is deallocated.- Returns:
- the
ResourceLeakTrackerornull
-
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:
trueto 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.
-
-