本文整理汇总了Java中io.netty.util.ReferenceCountUtil.release方法的典型用法代码示例。如果您正苦于以下问题:Java ReferenceCountUtil.release方法的具体用法?Java ReferenceCountUtil.release怎么用?Java ReferenceCountUtil.release使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.netty.util.ReferenceCountUtil
的用法示例。
在下文中一共展示了ReferenceCountUtil.release方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: channelRead
import io.netty.util.ReferenceCountUtil; //导入方法依赖的package包/类
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
try {
if (!(msg instanceof AbstractMessage)) {
Log.warn(SERIAL, "Invalid message received! Message skipped.");
return;
}
Log.debug(SERIAL, "Message received: " + msg);
// Notify that a message was received.
onMessageReceived((AbstractMessage) msg);
} finally {
ReferenceCountUtil.release(msg);
}
}
示例2: channelRead
import io.netty.util.ReferenceCountUtil; //导入方法依赖的package包/类
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
//客户端channel已关闭则不转发了
if (!clientChannel.isOpen()) {
ReferenceCountUtil.release(msg);
return;
}
HttpProxyInterceptPipeline interceptPipeline = ((HttpProxyServerHandle) clientChannel.pipeline()
.get("serverHandle")).getInterceptPipeline();
if (msg instanceof HttpResponse) {
interceptPipeline.afterResponse(clientChannel, ctx.channel(), (HttpResponse) msg);
} else if (msg instanceof HttpContent) {
interceptPipeline.afterResponse(clientChannel, ctx.channel(), (HttpContent) msg);
} else {
clientChannel.writeAndFlush(msg);
}
}
示例3: channelRead
import io.netty.util.ReferenceCountUtil; //导入方法依赖的package包/类
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
if (dstChannel.isActive()) {
ByteBuf byteBuf = (ByteBuf) msg;
try {
if (!byteBuf.hasArray()) {
byte[] bytes = new byte[byteBuf.readableBytes()];
byteBuf.getBytes(0, bytes);
if (uplink) {
dstChannel.writeAndFlush(Unpooled.wrappedBuffer(wrapper.wrap(bytes)));
log.info("\tClient ==========> Target \tSend [{} bytes]", bytes.length);
} else {
bytes = wrapper.unwrap(bytes);
if (bytes != null) {
dstChannel.writeAndFlush(Unpooled.wrappedBuffer(bytes));
log.info("\tClient <========== Target \tGet [{} bytes]", bytes.length);
}
}
}
} finally {
ReferenceCountUtil.release(msg);
}
}
}
示例4: channelRead
import io.netty.util.ReferenceCountUtil; //导入方法依赖的package包/类
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
if (dstChannel.isActive()) {
ByteBuf byteBuf = (ByteBuf) msg;
try {
if (!byteBuf.hasArray()) {
byte[] bytes = new byte[byteBuf.readableBytes()];
byteBuf.getBytes(0, bytes);
if (uplink) {
bytes = wrapper.unwrap(bytes);
if (bytes != null) {
dstChannel.writeAndFlush(Unpooled.wrappedBuffer(bytes));
log.info("\tClient ==========> Target \tSend [{} bytes]", bytes.length);
}
} else {
dstChannel.writeAndFlush(Unpooled.wrappedBuffer(wrapper.wrap(bytes)));
log.info("\tClient <========== Target \tGet [{} bytes]", bytes.length);
}
}
} finally {
ReferenceCountUtil.release(msg);
}
}
}
示例5: dotStuff
import io.netty.util.ReferenceCountUtil; //导入方法依赖的package包/类
private String dotStuff(String testString, int chunkSize) throws Exception {
ByteArrayInputStream stream = new ByteArrayInputStream(testString.getBytes(StandardCharsets.UTF_8));
DotStuffingChunkedStream chunkedStream = new DotStuffingChunkedStream(stream, chunkSize);
CompositeByteBuf destBuffer = ALLOCATOR.compositeBuffer();
while (!chunkedStream.isEndOfInput()) {
destBuffer.addComponent(true, chunkedStream.readChunk(ALLOCATOR));
}
byte[] bytes = new byte[destBuffer.readableBytes()];
destBuffer.getBytes(0, bytes);
ReferenceCountUtil.release(destBuffer);
return new String(bytes, CharsetUtil.UTF_8);
}
示例6: handleIFormat
import io.netty.util.ReferenceCountUtil; //导入方法依赖的package包/类
private void handleIFormat ( final InformationTransfer msg, ByteBuf out )
{
final ByteBuf data = msg.getData ();
try
{
out = out.order ( ByteOrder.LITTLE_ENDIAN );
final int len = data.readableBytes ();
if ( len > Constants.APCI_MAX_DATA_LENGTH )
{
throw new EncoderException ( String.format ( "Packet too big - %s bytes", len ) );
}
out.ensureWritable ( 6 + len );
out.writeByte ( Constants.START_BYTE );
out.writeByte ( 4 + len );
out.writeShort ( msg.getSendSequenceNumber () << 1 );
out.writeShort ( msg.getReceiveSequenceNumber () << 1 );
out.writeBytes ( data );
}
finally
{
ReferenceCountUtil.release ( msg.getData () );
}
}
示例7: channelRead
import io.netty.util.ReferenceCountUtil; //导入方法依赖的package包/类
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
try {
if (relayChannel.isActive()) {
ByteBuf bytebuff = (ByteBuf) msg;
if (!bytebuff.hasArray()) {
int len = bytebuff.readableBytes();
byte[] arr = new byte[len];
bytebuff.getBytes(0, arr);
connectHandler.sendRemote(arr, arr.length, relayChannel);
}
}
} catch (Exception e) {
logger.error("send data to remoteServer error",e);
} finally {
ReferenceCountUtil.release(msg);
}
}
示例8: channelRead
import io.netty.util.ReferenceCountUtil; //导入方法依赖的package包/类
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
try {
if (relayChannel.isActive()) {
logger.debug("get remote message" + relayChannel);
ByteBuf bytebuff = (ByteBuf) msg;
if (!bytebuff.hasArray()) {
int len = bytebuff.readableBytes();
byte[] arr = new byte[len];
bytebuff.getBytes(0, arr);
connectHandler.sendLocal(arr, arr.length, relayChannel);
}
}
} catch (Exception e) {
logger.error("receive remoteServer data error", e);
} finally {
ReferenceCountUtil.release(msg);
}
}
示例9: testRoundtrip
import io.netty.util.ReferenceCountUtil; //导入方法依赖的package包/类
public void testRoundtrip() {
ByteBuf buf = channel.alloc().buffer();
for (int c : new int[]{1, 1, 5, 10, 50, 100, 500, 1000, 5000, 10000}) {
buf.capacity(c);
while (buf.writableBytes() > 0) {
buf.writeByte(c);
}
channel.writeOutbound(buf.duplicate().retain());
channel.runPendingTasks();
for (Object msg; (msg = channel.readOutbound()) != null; ) {
channel.writeInbound(msg);
}
assertEquals(buf, channel.readInbound());
}
ReferenceCountUtil.release(buf);
}
示例10: channelRead
import io.netty.util.ReferenceCountUtil; //导入方法依赖的package包/类
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
ByteBuf in = (ByteBuf) msg;
if (!readIV) {
if (in.readableBytes() < ivLength) {
return;
} else {
readIV = true;
byte[] ivbytes = new byte[ivLength];
in.readBytes(ivbytes);
this.decryptCipher = new ShadowSocksCipher(ivbytes, crypto, password, false);
}
}
int length = in.readableBytes();
if (length > 0) {
ByteBuf out = ctx.alloc().buffer();
BytebufCipherUtil.update(decryptCipher, in, out);//update decode
ctx.fireChannelRead(out);
ReferenceCountUtil.release(in);
}
}
示例11: channelRead0
import io.netty.util.ReferenceCountUtil; //导入方法依赖的package包/类
@Override
protected void channelRead0(final ChannelHandlerContext ctx, final Pair<RequestMessage, ThrowingConsumer<Context>> objects) throws Exception {
final RequestMessage msg = objects.getValue0();
final ThrowingConsumer<Context> op = objects.getValue1();
final Context gremlinServerContext = new Context(msg, ctx,
settings, graphManager, gremlinExecutor, scheduledExecutorService);
try {
op.accept(gremlinServerContext);
} catch (OpProcessorException ope) {
// Ops may choose to throw OpProcessorException or write the error ResponseMessage down the line
// themselves
logger.warn(ope.getMessage(), ope);
ctx.writeAndFlush(ope.getResponseMessage());
} catch (Exception ex) {
// It is possible that an unplanned exception might raise out of an OpProcessor execution. Build a general
// error to send back to the client
logger.warn(ex.getMessage(), ex);
ctx.writeAndFlush(ResponseMessage.build(msg)
.code(ResponseStatusCode.SERVER_ERROR)
.statusMessage(ex.getMessage()).create());
} finally {
ReferenceCountUtil.release(objects);
}
}
示例12: serializeResponseAsBinary
import io.netty.util.ReferenceCountUtil; //导入方法依赖的package包/类
@Override
public ByteBuf serializeResponseAsBinary(final ResponseMessage responseMessage, final ByteBufAllocator allocator) throws SerializationException {
ByteBuf encodedMessage = null;
try {
final byte[] payload = mapper.writeValueAsBytes(responseMessage);
encodedMessage = allocator.buffer(payload.length);
encodedMessage.writeBytes(payload);
return encodedMessage;
} catch (Exception ex) {
if (encodedMessage != null) ReferenceCountUtil.release(encodedMessage);
logger.warn("Response [{}] could not be serialized by {}.", responseMessage.toString(), AbstractGraphSONMessageSerializerV2d0.class.getName());
throw new SerializationException(ex);
}
}
示例13: assertHasInboundMessages
import io.netty.util.ReferenceCountUtil; //导入方法依赖的package包/类
private void assertHasInboundMessages(EmbeddedChannel channel, boolean hasMessages) {
Object o;
if (hasMessages) {
while (true) {
o = channel.readInbound();
assertNotNull(o);
ReferenceCountUtil.release(o);
if (o instanceof LastHttpContent) {
break;
}
}
} else {
o = channel.readInbound();
assertNull(o);
}
}
示例14: decodeResponse
import io.netty.util.ReferenceCountUtil; //导入方法依赖的package包/类
@Override
public ByteBuf decodeResponse(ByteBuf buffer) throws PartialResponseException, CipResponseException {
MessageRouterResponse response = MessageRouterResponse.decode(buffer);
int generalStatus = response.getGeneralStatus();
try {
if (generalStatus == 0x00) {
return decode(response);
} else {
throw new CipResponseException(generalStatus, response.getAdditionalStatus());
}
} finally {
ReferenceCountUtil.release(response.getData());
}
}
示例15: writeAndFlush
import io.netty.util.ReferenceCountUtil; //导入方法依赖的package包/类
@Override
public ChannelGroupFuture writeAndFlush(Object message, ChannelMatcher matcher) {
if (message == null) {
throw new NullPointerException("message");
}
Map<Channel, ChannelFuture> futures = new LinkedHashMap<Channel, ChannelFuture>(size());
for (Channel c: nonServerChannels) {
if (matcher.matches(c)) {
futures.put(c, c.writeAndFlush(safeDuplicate(message)));
}
}
ReferenceCountUtil.release(message);
return new DefaultChannelGroupFuture(this, futures, executor);
}