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

The following examples show how to use io.netty.util.ReferenceCounted#release() . 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: SmtpSessionTest.java    From NioSmtpClient with Apache License 2.0 6 votes vote down vote up
@After
public void tearDown() {
  for (Object obj : objectsToRelease) {
    if (!(obj instanceof ReferenceCounted)) {
      continue;
    }

    ReferenceCounted referenceCountedObject = (ReferenceCounted) obj;

    assertThat(referenceCountedObject.refCnt())
        .withFailMessage("Trying to free %s but it has a ref count of %d", obj, referenceCountedObject.refCnt())
        .isEqualTo(1);

    referenceCountedObject.release();
  }
}
 
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: FakeTsiTest.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
@After
public void tearDown() {
  for (ReferenceCounted reference : references) {
    reference.release();
  }
  references.clear();
  // Increase our chances to detect ByteBuf leaks.
  GcFinalization.awaitFullGc();
}
 
Example 4
Source File: AltsTsiTest.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
@After
public void tearDown() {
  for (ReferenceCounted reference : references) {
    reference.release();
  }
  references.clear();
  // Increase our chances to detect ByteBuf leaks.
  GcFinalization.awaitFullGc();
}
 
Example 5
Source File: AltsChannelCrypterTest.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
@After
public void tearDown() throws GeneralSecurityException {
  for (ReferenceCounted reference : references) {
    reference.release();
  }
  references.clear();
  client.destroy();
  server.destroy();
  // Increase our chances to detect ByteBuf leaks.
  GcFinalization.awaitFullGc();
}
 
Example 6
Source File: AltsTsiFrameProtectorTest.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
@After
public void teardown() {
  for (ReferenceCounted reference : references) {
    reference.release();
  }
  references.clear();
  // Increase our chances to detect ByteBuf leaks.
  GcFinalization.awaitFullGc();
}
 
Example 7
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 8
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 9
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 10
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 11
Source File: NettyChannelPublisher.java    From servicetalk with Apache License 2.0 5 votes vote down vote up
private void channelReadReferenceCounted(ReferenceCounted data) {
    try {
        data.release();
    } finally {
        // We do not expect ref-counted objects here as ST does not support them and do not take care to clean them
        // in error conditions. Hence we fail-fast when we see such objects.
        pending = null;
        if (fatalError == null) {
            fatalError = new IllegalArgumentException("Reference counted leaked netty's pipeline. Object: " +
                    data.getClass().getSimpleName());
            exceptionCaught0(fatalError);
        }
        channel.close();
    }
}
 
Example 12
Source File: FakeTsiTest.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
@After
public void tearDown() {
  for (ReferenceCounted reference : references) {
    reference.release();
  }
  references.clear();
  // Increase our chances to detect ByteBuf leaks.
  GcFinalization.awaitFullGc();
}
 
Example 13
Source File: AltsTsiTest.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
@After
public void tearDown() {
  for (ReferenceCounted reference : references) {
    reference.release();
  }
  references.clear();
  // Increase our chances to detect ByteBuf leaks.
  GcFinalization.awaitFullGc();
}
 
Example 14
Source File: AltsChannelCrypterTest.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
@After
public void tearDown() throws GeneralSecurityException {
  for (ReferenceCounted reference : references) {
    reference.release();
  }
  references.clear();
  client.destroy();
  server.destroy();
  // Increase our chances to detect ByteBuf leaks.
  GcFinalization.awaitFullGc();
}
 
Example 15
Source File: AltsTsiFrameProtectorTest.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
@After
public void teardown() {
  for (ReferenceCounted reference : references) {
    reference.release();
  }
  references.clear();
  // Increase our chances to detect ByteBuf leaks.
  GcFinalization.awaitFullGc();
}
 
Example 16
Source File: NettyTsiHandshakerTest.java    From grpc-nebula-java with Apache License 2.0 4 votes vote down vote up
@After
public void teardown() {
  for (ReferenceCounted reference : references) {
    reference.release(reference.refCnt());
  }
}
 
Example 17
Source File: NettyTsiHandshakerTest.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
@After
public void teardown() {
  for (ReferenceCounted reference : references) {
    reference.release(reference.refCnt());
  }
}