/** * Try to call {@link ReferenceCounted#release()} if the specified message implements {@link ReferenceCounted}. * If the specified message doesn't implement {@link ReferenceCounted}, this method does nothing. */ public static boolean release(Object msg) { if (msg instanceof ReferenceCounted) { return ((ReferenceCounted) msg).release(); } return false; }
/** * Returns reference count of a {@link ReferenceCounted} object. If object is not type of * {@link ReferenceCounted}, {@code -1} is returned. */ public static int refCnt(Object msg) { return msg instanceof ReferenceCounted ? ((ReferenceCounted) msg).refCnt() : -1; }
@Override ByteBuf retain0() { referenceCountDelegate.retain(); return this; }
/** * @param value An object with a value */ protected void releaseIfNecessary(Object value) { if (value instanceof ReferenceCounted) { ReferenceCounted referenceCounted = (ReferenceCounted) value; if ((!(value instanceof CompositeByteBuf))) { int i = referenceCounted.refCnt(); if (i != 0) { referenceCounted.release(); } } } }
@Override public void startAsync(final Executor executor, final Runnable runnable) { Channel channel = ctx.channel(); channel.attr(NEED_FLUSH).set(false); channel.attr(ASYNC).set(true); ReferenceCounted body = ((ByteBufHolder) req).content(); body.retain(); executor.execute(() -> { try { runnable.run(); } finally { body.release(); } }); }
@Override ByteBuf touch0() { referenceCountDelegate.touch(); return this; }
/** * Tries to call {@link ReferenceCounted#touch()} if the specified message implements {@link ReferenceCounted}. * If the specified message doesn't implement {@link ReferenceCounted}, this method does nothing. */ @SuppressWarnings("unchecked") public static <T> T touch(T msg) { if (msg instanceof ReferenceCounted) { return (T) ((ReferenceCounted) msg).touch(); } return msg; }
/** * Try to call {@link ReferenceCounted#release(int)} if the specified message implements {@link ReferenceCounted}. * If the specified message doesn't implement {@link ReferenceCounted}, this method does nothing. */ public static boolean release(Object msg, int decrement) { if (msg instanceof ReferenceCounted) { return ((ReferenceCounted) msg).release(decrement); } return false; }
@Override public int refCnt() { if (message instanceof ReferenceCounted) { return ((ReferenceCounted) message).refCnt(); } else { return 1; } }
/** * Try to call {@link ReferenceCounted#retain(int)} if the specified message implements {@link ReferenceCounted}. * If the specified message doesn't implement {@link ReferenceCounted}, this method does nothing. */ @SuppressWarnings("unchecked") public static <T> T retain(T msg, int increment) { if (msg instanceof ReferenceCounted) { return (T) ((ReferenceCounted) msg).retain(increment); } return msg; }
/** * Tries to call {@link ReferenceCounted#touch(Object)} if the specified message implements * {@link ReferenceCounted}. If the specified message doesn't implement {@link ReferenceCounted}, * this method does nothing. */ @SuppressWarnings("unchecked") public static <T> T touch(T msg, Object hint) { if (msg instanceof ReferenceCounted) { return (T) ((ReferenceCounted) msg).touch(hint); } return msg; }
@Override boolean release0() { return referenceCountDelegate.release(); }
@Override int refCnt0() { return referenceCountDelegate.refCnt(); }
@Override ByteBuf retain0() { referenceCountDelegate.retain(); return this; }
@Override ByteBuf touch0(Object hint) { referenceCountDelegate.touch(hint); return this; }
@Override boolean release0(int decrement) { return referenceCountDelegate.release(decrement); }
@Override int refCnt0() { return referenceCountDelegate.refCnt(); }
/** * Try to call {@link ReferenceCounted#retain()} if the specified message implements {@link ReferenceCounted}. * If the specified message doesn't implement {@link ReferenceCounted}, this method does nothing. */ @SuppressWarnings("unchecked") public static <T> T retain(T msg) { if (msg instanceof ReferenceCounted) { return (T) ((ReferenceCounted) msg).retain(); } return msg; }
@Override ByteBuf touch0(Object hint) { referenceCountDelegate.touch(hint); return this; }
@Override boolean release0() { return referenceCountDelegate.release(); }