Package io.netty.util

Class ReferenceCountUtil

java.lang.Object
io.netty.util.ReferenceCountUtil

public final class ReferenceCountUtil extends Object
Collection of method to handle objects that may implement ReferenceCounted.
  • Field Details

  • Constructor Details

    • ReferenceCountUtil

      private ReferenceCountUtil()
  • Method Details

    • retain

      public static <T> T retain(T msg)
      Try to call ReferenceCounted.retain() if the specified message implements ReferenceCounted. If the specified message doesn't implement ReferenceCounted, this method does nothing.
    • retain

      public static <T> T retain(T msg, int increment)
      Try to call ReferenceCounted.retain(int) if the specified message implements ReferenceCounted. If the specified message doesn't implement ReferenceCounted, this method does nothing.
    • touch

      public static <T> T touch(T msg)
      Tries to call ReferenceCounted.touch() if the specified message implements ReferenceCounted. If the specified message doesn't implement ReferenceCounted, this method does nothing.
    • touch

      public static <T> T touch(T msg, Object hint)
      Tries to call ReferenceCounted.touch(Object) if the specified message implements ReferenceCounted. If the specified message doesn't implement ReferenceCounted, this method does nothing.
    • release

      public static boolean release(Object msg)
      Try to call ReferenceCounted.release() if the specified message implements ReferenceCounted. If the specified message doesn't implement ReferenceCounted, this method does nothing.
    • release

      public static boolean release(Object msg, int decrement)
      Try to call ReferenceCounted.release(int) if the specified message implements ReferenceCounted. If the specified message doesn't implement ReferenceCounted, this method does nothing.
    • safeRelease

      public static void safeRelease(Object msg)
      Try to call ReferenceCounted.release() if the specified message implements ReferenceCounted. If the specified message doesn't implement ReferenceCounted, this method does nothing. Unlike release(Object) this method catches an exception raised by ReferenceCounted.release() and logs it, rather than rethrowing it to the caller. It is usually recommended to use release(Object) instead, unless you absolutely need to swallow an exception.
    • safeRelease

      public static void safeRelease(Object msg, int decrement)
      Try to call ReferenceCounted.release(int) if the specified message implements ReferenceCounted. If the specified message doesn't implement ReferenceCounted, this method does nothing. Unlike release(Object) this method catches an exception raised by ReferenceCounted.release(int) and logs it, rather than rethrowing it to the caller. It is usually recommended to use release(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(Object msg)
      Returns reference count of a ReferenceCounted object. If object is not type of ReferenceCounted, -1 is returned.