- java.lang.Object
-
- io.netty5.util.ReferenceCountUtil
-
public final class ReferenceCountUtil extends Object
Collection of method to handle objects that may implementReferenceCounted.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleanisReferenceCounted(Object obj)Tests whether the given object implements theReferenceCountedinterface.static intrefCnt(Object msg)Returns reference count of aReferenceCountedobject.static booleanrelease(Object msg)Try to callReferenceCounted.release()if the specified message implementsReferenceCounted.static booleanrelease(Object msg, int decrement)Try to callReferenceCounted.release(int)if the specified message implementsReferenceCounted.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(Object msg)Try to callReferenceCounted.release()if the specified message implementsReferenceCounted.static voidsafeRelease(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, Object hint)Tries to callReferenceCounted.touch(Object)if the specified message implementsReferenceCounted.
-
-
-
Method Detail
-
isReferenceCounted
public static boolean isReferenceCounted(Object obj)
Tests whether the given object implements theReferenceCountedinterface.- Parameters:
obj- The object to test.- Returns:
trueif the given object is reference counted.
-
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, 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(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(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(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(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.
-
refCnt
public static int refCnt(Object msg)
Returns reference count of aReferenceCountedobject. If object is not type ofReferenceCounted,-1is returned.
-
-