当前位置: 首页>>代码示例>>Java>>正文


Java ReferenceCountUtil.release方法代码示例

本文整理汇总了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);
    }
}
 
开发者ID:tbressler,项目名称:waterrower-core,代码行数:19,代码来源:RxtxSerialHandler.java

示例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);
  }
}
 
开发者ID:monkeyWie,项目名称:proxyee,代码行数:18,代码来源:HttpProxyClientHandle.java

示例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);
        }
    }
}
 
开发者ID:ZhangJiupeng,项目名称:AgentX,代码行数:25,代码来源:XRelayHandler.java

示例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);
        }
    }
}
 
开发者ID:ZhangJiupeng,项目名称:AgentX,代码行数:25,代码来源:XRelayHandler.java

示例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);
}
 
开发者ID:HubSpot,项目名称:NioSmtpClient,代码行数:17,代码来源:DotStuffingChunkedStreamTest.java

示例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 () );
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:27,代码来源:APDUEncoder.java

示例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);
	}
}
 
开发者ID:breakEval13,项目名称:NSS,代码行数:19,代码来源:OutRelayHandler.java

示例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);
	}
}
 
开发者ID:breakEval13,项目名称:NSS,代码行数:20,代码来源:InRelayHandler.java

示例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);
}
 
开发者ID:SecureSmartHome,项目名称:SecureSmartHome,代码行数:18,代码来源:SignerTest.java

示例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);
    }
}
 
开发者ID:lujianbo,项目名称:moonlight-ss,代码行数:22,代码来源:ShadowSocksDecoder.java

示例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);
    }
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:26,代码来源:OpExecutorHandler.java

示例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);
    }
}
 
开发者ID:apache,项目名称:tinkerpop,代码行数:17,代码来源:AbstractGraphSONMessageSerializerV2d0.java

示例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);
    }
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:17,代码来源:HttpContentDecoderTest.java

示例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());
    }
}
 
开发者ID:digitalpetri,项目名称:ethernet-ip,代码行数:17,代码来源:ReadTagService.java

示例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);
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:19,代码来源:DefaultChannelGroup.java


注:本文中的io.netty.util.ReferenceCountUtil.release方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。