Java Code Examples for io.netty.util.ReferenceCounted#refCnt()

The following examples show how to use io.netty.util.ReferenceCounted#refCnt() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RecyclableUtil.java    From spring-boot-protocol with Apache License 2.0 5 votes vote down vote up
public static boolean release(Object obj) {
    if(obj == null){
        return false;
    }
    if(obj instanceof EmptyByteBuf){
        return true;
    }

    if(obj instanceof ReferenceCounted) {
        ReferenceCounted counted = (ReferenceCounted)obj;
        try {
            int refCnt = counted.refCnt();
            if (refCnt > 0) {
                counted.release();
                return true;
            }else {
                return false;
            }
        }catch (IllegalStateException e){
            throw e;
        }
    }
    if(obj instanceof Recyclable){
        ((Recyclable) obj).recycle();
        return true;
    }
    return false;
}
 
Example 2
Source File: ChannelOperationsHandler.java    From reactor-netty with Apache License 2.0 5 votes vote down vote up
static void safeRelease(Object msg) {
	if (msg instanceof ReferenceCounted) {
		ReferenceCounted referenceCounted = (ReferenceCounted) msg;
		if (referenceCounted.refCnt() > 0) {
			try {
				referenceCounted.release();
			}
			catch (IllegalReferenceCountException e) {
				if (log.isDebugEnabled()) {
					log.debug("", e);
				}
			}
		}
	}
}
 
Example 3
Source File: ReactorNetty.java    From reactor-netty with Apache License 2.0 5 votes vote down vote up
/**
 * Try to call {@link ReferenceCounted#release()} if the specified message implements {@link ReferenceCounted}.
 * If the specified message doesn't implement {@link ReferenceCounted} or it is already released,
 * this method does nothing.
 */
public static void safeRelease(Object msg) {
	if (msg instanceof ReferenceCounted) {
		ReferenceCounted referenceCounted = (ReferenceCounted) msg;
		if (referenceCounted.refCnt() > 0) {
			referenceCounted.release();
		}
	}
}
 
Example 4
Source File: IOUtils.java    From hasor with Apache License 2.0 5 votes vote down vote up
public static void releaseByteBuf(ReferenceCounted frame) {
    if (frame == null) {
        return;
    }
    try {
        if (frame.refCnt() != 0) {
            frame.release();
        }
    } catch (Exception e) {
    }
}
 
Example 5
Source File: UnboundedProcessor.java    From rsocket-java with Apache License 2.0 5 votes vote down vote up
void release(T t) {
  if (t instanceof ReferenceCounted) {
    ReferenceCounted refCounted = (ReferenceCounted) t;
    if (refCounted.refCnt() > 0) {
      try {
        refCounted.release();
      } catch (Throwable ex) {
        // no ops
      }
    }
  }
}
 
Example 6
Source File: OpenSsl.java    From netty-4.1.22 with Apache License 2.0 4 votes vote down vote up
static void releaseIfNeeded(ReferenceCounted counted) {
    if (counted.refCnt() > 0) {
        ReferenceCountUtil.safeRelease(counted);
    }
}