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 private static classResourceLeakDetector.DefaultResourceLeak<T>static classResourceLeakDetector.LevelRepresents the level of resource leak detection.private static classResourceLeakDetector.Record
-
Field Summary
Fields Modifier and Type Field Description private java.util.Set<ResourceLeakDetector.DefaultResourceLeak<?>>allLeaksthe collection of active resourcesprivate static ResourceLeakDetector.LevelDEFAULT_LEVELprivate static intDEFAULT_SAMPLING_INTERVALprivate static intDEFAULT_TARGET_RECORDSprivate static java.util.concurrent.atomic.AtomicReference<java.lang.String[]>excludedMethodsprivate static ResourceLeakDetector.Levellevelprivate static InternalLoggerloggerprivate static java.lang.StringPROP_LEVELprivate static java.lang.StringPROP_LEVEL_OLDprivate static java.lang.StringPROP_SAMPLING_INTERVALprivate static java.lang.StringPROP_TARGET_RECORDSprivate java.lang.ref.ReferenceQueue<java.lang.Object>refQueueprivate java.util.Set<java.lang.String>reportedLeaksprivate java.lang.StringresourceType(package private) static intSAMPLING_INTERVALprivate intsamplingIntervalprivate static intTARGET_RECORDS
-
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)private voidclearRefQueue()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.ResourceLeakopen(T obj)Deprecated.usetrack(Object)protected voidreportInstancesLeak(java.lang.String resourceType)Deprecated.This method will no longer be invoked byResourceLeakDetector.private voidreportLeak()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.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.private ResourceLeakDetector.DefaultResourceLeaktrack0(T obj)
-
-
-
Field Detail
-
PROP_LEVEL_OLD
private static final java.lang.String PROP_LEVEL_OLD
- See Also:
- Constant Field Values
-
PROP_LEVEL
private static final java.lang.String PROP_LEVEL
- See Also:
- Constant Field Values
-
DEFAULT_LEVEL
private static final ResourceLeakDetector.Level DEFAULT_LEVEL
-
PROP_TARGET_RECORDS
private static final java.lang.String PROP_TARGET_RECORDS
- See Also:
- Constant Field Values
-
DEFAULT_TARGET_RECORDS
private static final int DEFAULT_TARGET_RECORDS
- See Also:
- Constant Field Values
-
PROP_SAMPLING_INTERVAL
private static final java.lang.String PROP_SAMPLING_INTERVAL
- See Also:
- Constant Field Values
-
DEFAULT_SAMPLING_INTERVAL
private static final int DEFAULT_SAMPLING_INTERVAL
- See Also:
- Constant Field Values
-
TARGET_RECORDS
private static final int TARGET_RECORDS
-
SAMPLING_INTERVAL
static final int SAMPLING_INTERVAL
-
level
private static ResourceLeakDetector.Level level
-
logger
private static final InternalLogger logger
-
allLeaks
private final java.util.Set<ResourceLeakDetector.DefaultResourceLeak<?>> 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
-
excludedMethods
private static final java.util.concurrent.atomic.AtomicReference<java.lang.String[]> excludedMethods
-
-
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 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
-
track0
private ResourceLeakDetector.DefaultResourceLeak track0(T obj)
-
clearRefQueue
private void clearRefQueue()
-
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.
-
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.
-
addExclusions
public static void addExclusions(java.lang.Class clz, java.lang.String... methodNames)
-
-