Class ReferenceCountUtil
java.lang.Object
io.netty.util.ReferenceCountUtil
public final class ReferenceCountUtil
extends java.lang.Object
Collection of method to handle objects that may implement
ReferenceCounted.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final classReleases the objects when the thread that calledreleaseLater(Object)has been terminated. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intrefCnt(java.lang.Object msg) Returns reference count of aReferenceCountedobject.static booleanrelease(java.lang.Object msg) Try to callReferenceCounted.release()if the specified message implementsReferenceCounted.static booleanrelease(java.lang.Object msg, int decrement) Try to callReferenceCounted.release(int)if the specified message implementsReferenceCounted.static <T> TreleaseLater(T msg) Deprecated.this may introduce a lot of memory usage so it is generally preferable to manually release objects.static <T> TreleaseLater(T msg, int decrement) Deprecated.this may introduce a lot of memory usage so it is generally preferable to manually release objects.static <T> Tretain(T msg) Try to callReferenceCounted.retain()if the specified message implementsReferenceCounted.static <T> Tretain(T msg, int increment) Try to callReferenceCounted.retain(int)if the specified message implementsReferenceCounted.static voidsafeRelease(java.lang.Object msg) Try to callReferenceCounted.release()if the specified message implementsReferenceCounted.static voidsafeRelease(java.lang.Object msg, int decrement) Try to callReferenceCounted.release(int)if the specified message implementsReferenceCounted.static <T> Ttouch(T msg) Tries to callReferenceCounted.touch()if the specified message implementsReferenceCounted.static <T> Ttouch(T msg, java.lang.Object hint) Tries to callReferenceCounted.touch(Object)if the specified message implementsReferenceCounted.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
logger
-
-
Constructor Details
-
ReferenceCountUtil
private ReferenceCountUtil()
-
-
Method Details
-
retain
public static <T> T retain(T msg) Try to callReferenceCounted.retain()if the specified message implementsReferenceCounted. If the specified message doesn't implementReferenceCounted, this method does nothing. -
retain
public static <T> T retain(T msg, int increment) Try to callReferenceCounted.retain(int)if the specified message implementsReferenceCounted. If the specified message doesn't implementReferenceCounted, this method does nothing. -
touch
public static <T> T touch(T msg) Tries to callReferenceCounted.touch()if the specified message implementsReferenceCounted. If the specified message doesn't implementReferenceCounted, this method does nothing. -
touch
public static <T> T touch(T msg, java.lang.Object hint) Tries to callReferenceCounted.touch(Object)if the specified message implementsReferenceCounted. If the specified message doesn't implementReferenceCounted, this method does nothing. -
release
public static boolean release(java.lang.Object msg) Try to callReferenceCounted.release()if the specified message implementsReferenceCounted. If the specified message doesn't implementReferenceCounted, this method does nothing. -
release
public static boolean release(java.lang.Object msg, int decrement) Try to callReferenceCounted.release(int)if the specified message implementsReferenceCounted. If the specified message doesn't implementReferenceCounted, this method does nothing. -
safeRelease
public static void safeRelease(java.lang.Object msg) Try to callReferenceCounted.release()if the specified message implementsReferenceCounted. If the specified message doesn't implementReferenceCounted, this method does nothing. Unlikerelease(Object)this method catches an exception raised byReferenceCounted.release()and logs it, rather than rethrowing it to the caller. It is usually recommended to userelease(Object)instead, unless you absolutely need to swallow an exception. -
safeRelease
public static void safeRelease(java.lang.Object msg, int decrement) Try to callReferenceCounted.release(int)if the specified message implementsReferenceCounted. If the specified message doesn't implementReferenceCounted, this method does nothing. Unlikerelease(Object)this method catches an exception raised byReferenceCounted.release(int)and logs it, rather than rethrowing it to the caller. It is usually recommended to userelease(Object, int)instead, unless you absolutely need to swallow an exception. -
releaseLater
@Deprecated public static <T> T releaseLater(T msg) Deprecated.this may introduce a lot of memory usage so it is generally preferable to manually release objects.Schedules the specified object to be released when the caller thread terminates. Note that this operation is intended to simplify reference counting of ephemeral objects during unit tests. Do not use it beyond the intended use case. -
releaseLater
@Deprecated public static <T> T releaseLater(T msg, int decrement) Deprecated.this may introduce a lot of memory usage so it is generally preferable to manually release objects.Schedules the specified object to be released when the caller thread terminates. Note that this operation is intended to simplify reference counting of ephemeral objects during unit tests. Do not use it beyond the intended use case. -
refCnt
public static int refCnt(java.lang.Object msg) Returns reference count of aReferenceCountedobject. If object is not type ofReferenceCounted,-1is returned.
-