Package io.netty.util
Class ResourceLeakDetector<T>
java.lang.Object
io.netty.util.ResourceLeakDetector<T>
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final class
static interface
static enum
Represents the level of resource leak detection.private static class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Set
<ResourceLeakDetector.DefaultResourceLeak<?>> the collection of active resourcesprivate static final ResourceLeakDetector.Level
private static final int
private static final int
private static final AtomicReference
<String[]> Will be notified once a leak is detected.private static ResourceLeakDetector.Level
private static final InternalLogger
private static final String
private static final String
private static final String
private static final String
private final ReferenceQueue
<Object> private final String
(package private) static final int
private final int
private static final int
-
Constructor Summary
ConstructorsConstructorDescriptionResourceLeakDetector
(Class<?> resourceType) Deprecated.ResourceLeakDetector
(Class<?> resourceType, int samplingInterval) This should not be used directly by users ofResourceLeakDetector
.ResourceLeakDetector
(Class<?> resourceType, int samplingInterval, long maxActive) Deprecated.ResourceLeakDetector
(String resourceType) ResourceLeakDetector
(String resourceType, int samplingInterval, long maxActive) -
Method Summary
Modifier and TypeMethodDescriptionstatic void
addExclusions
(Class clz, String... methodNames) private void
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
Returnstrue
if resource leak detection is enabled.protected boolean
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.final ResourceLeak
Deprecated.usetrack(Object)
protected void
reportInstancesLeak
(String resourceType) Deprecated.This method will no longer be invoked byResourceLeakDetector
.private void
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
setEnabled
(boolean enabled) Deprecated.UsesetLevel(Level)
instead.void
setLeakListener
(ResourceLeakDetector.LeakListener leakListener) Set leak listener.static void
Sets the resource leak detection level.final ResourceLeakTracker
<T> Creates a newResourceLeakTracker
which is expected to be closed viaResourceLeakTracker.close(Object)
when the related resource is deallocated.trackForcibly
(T obj) Creates a newResourceLeakTracker
which is expected to be closed viaResourceLeakTracker.close(Object)
when the related resource is deallocated.
-
Field Details
-
PROP_LEVEL_OLD
- See Also:
-
PROP_LEVEL
- See Also:
-
DEFAULT_LEVEL
-
PROP_TARGET_RECORDS
- See Also:
-
DEFAULT_TARGET_RECORDS
private static final int DEFAULT_TARGET_RECORDS- See Also:
-
PROP_SAMPLING_INTERVAL
- See Also:
-
DEFAULT_SAMPLING_INTERVAL
private static final int DEFAULT_SAMPLING_INTERVAL- See Also:
-
TARGET_RECORDS
private static final int TARGET_RECORDS -
SAMPLING_INTERVAL
static final int SAMPLING_INTERVAL -
level
-
logger
-
allLeaks
the collection of active resources -
refQueue
-
reportedLeaks
-
resourceType
-
samplingInterval
private final int samplingInterval -
leakListener
Will be notified once a leak is detected. -
excludedMethods
-
-
Constructor Details
-
ResourceLeakDetector
-
ResourceLeakDetector
-
ResourceLeakDetector
@Deprecated public ResourceLeakDetector(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
This should not be used directly by users ofResourceLeakDetector
. Please useResourceLeakDetectorFactory.newResourceLeakDetector(Class)
orResourceLeakDetectorFactory.newResourceLeakDetector(Class, int, long)
-
ResourceLeakDetector
- Parameters:
maxActive
- This is deprecated and will be ignored.
-
-
Method Details
-
setEnabled
Deprecated.UsesetLevel(Level)
instead. -
isEnabled
public static boolean isEnabled()Returnstrue
if 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 newResourceLeak
which is expected to be closed viaResourceLeak.close()
when the related resource is deallocated.- Returns:
- the
ResourceLeak
ornull
-
track
Creates a newResourceLeakTracker
which is expected to be closed viaResourceLeakTracker.close(Object)
when the related resource is deallocated.- Returns:
- the
ResourceLeakTracker
ornull
-
trackForcibly
Creates a newResourceLeakTracker
which is expected to be closed viaResourceLeakTracker.close(Object)
when the related resource is deallocated. Unliketrack(Object)
, this method always returns a tracker, regardless of the detection settings.- Returns:
- the
ResourceLeakTracker
-
track0
-
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:
true
to enable leak reporting.
-
reportLeak
private void reportLeak() -
reportTracedLeak
This method is called when a traced leak is detected. It can be overridden for tracking how many times leaks have been detected. -
reportUntracedLeak
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.This method will no longer be invoked byResourceLeakDetector
. -
getInitialHint
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
-
ResourceLeakDetectorFactory.newResourceLeakDetector(Class, int, long)
.