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 ClassesModifier and TypeClassDescriptionprivate static final classstatic interfacestatic enumRepresents the level of resource leak detection.private static class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final java.util.Set<ResourceLeakDetector.DefaultResourceLeak<?>> the collection of active resourcesprivate static final ResourceLeakDetector.Levelprivate static final intprivate static final intprivate static final booleanprivate static final java.util.concurrent.atomic.AtomicReference<java.lang.String[]> Will be notified once a leak is detected.private static ResourceLeakDetector.Levelprivate static final InternalLoggerprivate static final java.lang.Stringprivate static final java.lang.Stringprivate static final java.lang.Stringprivate static final java.lang.Stringprivate static final java.lang.Stringprivate final java.lang.ref.ReferenceQueue<java.lang.Object> private final java.util.Set<java.lang.String> private final java.lang.String(package private) static final intprivate final intprivate static final intprivate static final boolean -
Constructor Summary
ConstructorsConstructorDescriptionResourceLeakDetector(java.lang.Class<?> resourceType) Deprecated.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
Modifier and TypeMethodDescriptionstatic voidaddExclusions(java.lang.Class clz, java.lang.String... methodNames) private voidprotected 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 booleanReturnstrueif resource leak detection is enabled.booleanCheck whetherResourceLeakTracker.record()does anything for this detector.protected booleanWhen the return value istrue,reportTracedLeak(String, String)andreportUntracedLeak(String)will be called once a leak is detected, otherwise not.final ResourceLeakDeprecated.usetrack(Object)protected voidreportInstancesLeak(java.lang.String resourceType) Deprecated.This method will no longer be invoked byResourceLeakDetector.private voidprotected 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 voidSets the resource leak detection level.Creates a newResourceLeakTrackerwhich is expected to be closed viaResourceLeakTracker.close(Object)when the related resource is deallocated.trackForcibly(T obj) Creates a newResourceLeakTrackerwhich is expected to be closed viaResourceLeakTracker.close(Object)when the related resource is deallocated.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
PROP_LEVEL_OLD
private static final java.lang.String PROP_LEVEL_OLD- See Also:
-
PROP_LEVEL
private static final java.lang.String PROP_LEVEL- See Also:
-
DEFAULT_LEVEL
-
PROP_TARGET_RECORDS
private static final java.lang.String PROP_TARGET_RECORDS- See Also:
-
DEFAULT_TARGET_RECORDS
private static final int DEFAULT_TARGET_RECORDS- See Also:
-
PROP_SAMPLING_INTERVAL
private static final java.lang.String PROP_SAMPLING_INTERVAL- See Also:
-
DEFAULT_SAMPLING_INTERVAL
private static final int DEFAULT_SAMPLING_INTERVAL- See Also:
-
PROP_TRACK_CLOSE
private static final java.lang.String PROP_TRACK_CLOSE- See Also:
-
DEFAULT_TRACK_CLOSE
private static final boolean DEFAULT_TRACK_CLOSE- See Also:
-
TARGET_RECORDS
private static final int TARGET_RECORDS -
SAMPLING_INTERVAL
static final int SAMPLING_INTERVAL -
TRACK_CLOSE
private static final boolean TRACK_CLOSE -
level
-
logger
-
allLeaks
the collection of active resources -
refQueue
private final java.lang.ref.ReferenceQueue<java.lang.Object> refQueue -
reportedLeaks
private final java.util.Set<java.lang.String> reportedLeaks -
resourceType
private final java.lang.String resourceType -
samplingInterval
private final int samplingInterval -
leakListener
Will be notified once a leak is detected. -
excludedMethods
private static final java.util.concurrent.atomic.AtomicReference<java.lang.String[]> excludedMethods
-
-
Constructor Details
-
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 Details
-
setEnabled
@Deprecated public static void setEnabled(boolean enabled) Deprecated.UsesetLevel(Level)instead. -
isEnabled
public static boolean isEnabled()Returnstrueif resource leak detection is enabled. -
setLevel
Sets the resource leak detection level. -
getLevel
Returns the current resource leak detection level. -
open
Deprecated.usetrack(Object)Creates a newResourceLeakwhich is expected to be closed viaResourceLeak.close()when the related resource is deallocated.- Returns:
- the
ResourceLeakornull
-
track
Creates a newResourceLeakTrackerwhich is expected to be closed viaResourceLeakTracker.close(Object)when the related resource is deallocated.- Returns:
- the
ResourceLeakTrackerornull
-
trackForcibly
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
-
track0
-
clearRefQueue
private void clearRefQueue() -
needReport
protected boolean needReport()When the return value istrue,reportTracedLeak(String, String)andreportUntracedLeak(String)will be called once a leak is detected, otherwise not.- Returns:
trueto enable leak reporting.
-
reportLeak
private void reportLeak() -
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
Set leak listener. Previous listener will be replaced. -
addExclusions
public static void addExclusions(java.lang.Class clz, java.lang.String... methodNames)
-
ResourceLeakDetectorFactory.newResourceLeakDetector(Class, int, long).