當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。