Package io.netty.util
Class ResourceLeakDetector<T>
- java.lang.Object
-
- io.netty.util.ResourceLeakDetector<T>
-
- Direct Known Subclasses:
LeakPresenceDetector
public class ResourceLeakDetector<T> extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceResourceLeakDetector.LeakListenerstatic classResourceLeakDetector.LevelRepresents 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 voidaddExclusions(java.lang.Class clz, java.lang.String... methodNames)protected java.lang.ObjectgetInitialHint(java.lang.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.booleanisRecordEnabled()Check whetherResourceLeakTracker.record()does anything for this detector.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.ResourceLeakopen(T obj)Deprecated.usetrack(Object)protected voidreportInstancesLeak(java.lang.String resourceType)Deprecated.This method will no longer be invoked byResourceLeakDetector.protected voidreportTracedLeak(java.lang.String resourceType, java.lang.String records)This method is called when a traced leak is detected.protected voidreportUntracedLeak(java.lang.String resourceType)This method is called when an untraced leak is detected.static voidsetEnabled(boolean enabled)Deprecated.UsesetLevel(Level)instead.voidsetLeakListener(ResourceLeakDetector.LeakListener leakListener)Set leak listener.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.ResourceLeakTracker<T>trackForcibly(T obj)Creates a newResourceLeakTrackerwhich 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()
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.
-
open
@Deprecated public final ResourceLeak open(T obj)
Deprecated.usetrack(Object)Creates a newResourceLeakwhich is expected to be closed viaResourceLeak.close()when the related resource is deallocated.- Returns:
- the
ResourceLeakornull
-
track
public 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
-
trackForcibly
public ResourceLeakTracker<T> trackForcibly(T obj)
Creates a newResourceLeakTrackerwhich is expected to be closed viaResourceLeakTracker.close(Object)when the related resource is deallocated.Unlike
track(Object), this method always returns a tracker, regardless of the detection settings.- Returns:
- the
ResourceLeakTracker
-
isRecordEnabled
public boolean isRecordEnabled()
Check whetherResourceLeakTracker.record()does anything for this detector.- Returns:
trueifResourceLeakTracker.record()should be called
-
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(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)
-
-