當前位置: 首頁>>代碼示例>>Java>>正文


Java ByteBuf.retain方法代碼示例

本文整理匯總了Java中io.netty.buffer.ByteBuf.retain方法的典型用法代碼示例。如果您正苦於以下問題:Java ByteBuf.retain方法的具體用法?Java ByteBuf.retain怎麽用?Java ByteBuf.retain使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在io.netty.buffer.ByteBuf的用法示例。


在下文中一共展示了ByteBuf.retain方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: filterOutboundMessage

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
@Override
protected Object filterOutboundMessage(Object msg) {
    if (msg instanceof UkcpPacket) {
        UkcpPacket p = (UkcpPacket) msg;
        ByteBuf content = p.content();
        if (isSingleDirectBuffer(content)) {
            return p;
        }
        content.retain(); // newDirectBuffer method call release method of content
        UkcpPacket np = UkcpPacket.newInstance(newDirectBuffer(content), p.remoteAddress());
        p.release();
        return np;
    }

    throw new UnsupportedOperationException(
            "unsupported message type: " + StringUtil.simpleClassName(msg) + EXPECTED_TYPES);
}
 
開發者ID:szhnet,項目名稱:kcp-netty,代碼行數:18,代碼來源:UkcpServerChannel.java

示例2: decode

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
/**
 * 將webSocket消息轉換為bytebuf類型,以適配後麵的解碼器
 */
@Override
protected void decode(ChannelHandlerContext paramChannelHandlerContext,
		WebSocketFrame paramINBOUND_IN, List<Object> paramList)
		throws Exception {
	if(paramINBOUND_IN instanceof BinaryWebSocketFrame)
	{
		BinaryWebSocketFrame msg=(BinaryWebSocketFrame)paramINBOUND_IN;
		ByteBuf data = msg.content();
		paramList.add(data);
		data.retain();
	}
}
 
開發者ID:juebanlin,項目名稱:util4j,代碼行數:16,代碼來源:WebSocketBinaryFrameByteBufAdapter.java

示例3: decodeUser

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
private Object decodeUser(ByteBuf in, int offset, int length) throws IOException {
    // Make sure that buffer will not be recycled until message is processed.
    in.retain();

    try {
        return message(in, offset, length);
    } catch (RuntimeException | Error | IOException e) {
        in.release();

        throw e;
    }
}
 
開發者ID:hekate-io,項目名稱:hekate,代碼行數:13,代碼來源:NetworkProtocolCodec.java

示例4: decode

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
/**
 * 將webSocket消息轉換為bytebuf類型,以適配後麵的解碼器
 */
@Override
protected void decode(ChannelHandlerContext paramChannelHandlerContext,
		WebSocketFrame paramINBOUND_IN, List<Object> paramList)
		throws Exception {
	if(paramINBOUND_IN instanceof TextWebSocketFrame)
	{
		TextWebSocketFrame msg=(TextWebSocketFrame)paramINBOUND_IN;
		ByteBuf data = msg.content();
		paramList.add(data);
		data.retain();
		log.debug("TextWebSocketFrame to ByteBuf,size="+data.readableBytes());
	}
}
 
開發者ID:juebanlin,項目名稱:util4j,代碼行數:17,代碼來源:WebSocketTextFrameByteBufAdapter.java

示例5: encode

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
/**
 * 對於業務層直接發送的bytebuf實例將其轉換為websocket消息
 */
@Override
protected void encode(ChannelHandlerContext paramChannelHandlerContext,
		ByteBuf paramOUTBOUND_IN, List<Object> paramList) throws Exception {
	paramList.add(new TextWebSocketFrame(paramOUTBOUND_IN));
	paramOUTBOUND_IN.retain();
	log.debug("ByteBuf to TextWebSocketFrame,size="+paramOUTBOUND_IN.readableBytes());
}
 
開發者ID:juebanlin,項目名稱:util4j,代碼行數:11,代碼來源:WebSocketTextFrameByteBufAdapter.java

示例6: encode

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
/**
 * 對於業務層直接發送的bytebuf實例將其轉換為websocket消息
 */
@Override
protected void encode(ChannelHandlerContext paramChannelHandlerContext,
		ByteBuf paramOUTBOUND_IN, List<Object> paramList) throws Exception {
	paramList.add(new BinaryWebSocketFrame(paramOUTBOUND_IN));
	paramOUTBOUND_IN.retain();
}
 
開發者ID:juebanlin,項目名稱:util4j,代碼行數:10,代碼來源:WebSocketBinaryFrameByteBufAdapter.java

示例7: decode

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
public static org.apache.spark.network.sasl.SaslMessage decode(ByteBuf buf) {
  if (buf.readByte() != TAG_BYTE) {
    throw new IllegalStateException("Expected SaslMessage, received something else"
      + " (maybe your client does not have SASL enabled?)");
  }

  String appId = Encoders.Strings.decode(buf);
  // See comment in encodedLength().
  buf.readInt();
  return new org.apache.spark.network.sasl.SaslMessage(appId, buf.retain());
}
 
開發者ID:spafka,項目名稱:spark_deep,代碼行數:12,代碼來源:SaslMessage.java

示例8: decode

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
/** Decoding uses the given ByteBuf as our data, and will retain() it. */
public static org.apache.spark.network.protocol.ChunkFetchSuccess decode(ByteBuf buf) {
  StreamChunkId streamChunkId = StreamChunkId.decode(buf);
  buf.retain();
  NettyManagedBuffer managedBuf = new NettyManagedBuffer(buf.duplicate());
  return new org.apache.spark.network.protocol.ChunkFetchSuccess(streamChunkId, managedBuf);
}
 
開發者ID:spafka,項目名稱:spark_deep,代碼行數:8,代碼來源:ChunkFetchSuccess.java

示例9: dataFromScreenArrived

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
public void dataFromScreenArrived(QueryData header, ByteBuf data, ResponseSender sender) throws RpcException {
  if(data != null){
    // we're going to send this some place, we need increment to ensure this is around long enough to send.
    data.retain();
    observers.execDataArrived(new ScreenShuttle(sender), new QueryWritableBatch(header, data));
  } else {
    observers.execDataArrived(new ScreenShuttle(sender), new QueryWritableBatch(header));
  }

}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:11,代碼來源:AttemptManager.java

示例10: RequestEvent

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
RequestEvent(int coordinationId, C connection, int rpcType, byte[] pBody, ByteBuf dBody) {
  sender = new ResponseSenderImpl();
  this.connection = connection;
  this.rpcType = rpcType;
  this.pBody = pBody;
  this.dBody = dBody;
  sender.set(connection, coordinationId);

  if(dBody != null){
    dBody.retain();
  }
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:13,代碼來源:RpcBus.java

示例11: ResponseEvent

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
public ResponseEvent(C connection, int rpcType, int coordinationId, byte[] pBody, ByteBuf dBody) {
  this.rpcType = rpcType;
  this.coordinationId = coordinationId;
  this.pBody = pBody;
  this.dBody = dBody;
  this.connection = connection;

  if(dBody != null){
    dBody.retain();
  }
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:12,代碼來源:RpcBus.java

示例12: decode

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf buffer, List<Object> out) throws Exception {
  if (!ctx.channel().isOpen()) {
    return;
  }

  if (RpcConstants.EXTRA_DEBUGGING) {
    logger.debug("Inbound rpc message received.");
  }

  // now, we know the entire message is in the buffer and the buffer is constrained to this message. Additionally,
  // this process should avoid reading beyond the end of this buffer so we inform the ByteBufInputStream to throw an
  // exception if be go beyond readable bytes (as opposed to blocking).
  final ByteBufInputStream is = new ByteBufInputStream(buffer, buffer.readableBytes());

  // read the rpc header, saved in delimited format.
  checkTag(is, RpcEncoder.HEADER_TAG);
  final RpcHeader header = RpcHeader.parseDelimitedFrom(is);

  if (RpcConstants.EXTRA_DEBUGGING) {
    logger.debug(" post header read index {}", buffer.readerIndex());
  }

  // read the protobuf body into a buffer.
  checkTag(is, RpcEncoder.PROTOBUF_BODY_TAG);
  final int pBodyLength = readRawVarint32(is);
  final ByteBuf pBody = buffer.slice(buffer.readerIndex(), pBodyLength);
  buffer.skipBytes(pBodyLength);
  pBody.retain(1);
  if (RpcConstants.EXTRA_DEBUGGING) {
    logger.debug("Read protobuf body of length {} into buffer {}.", pBodyLength, pBody);
  }

  if (RpcConstants.EXTRA_DEBUGGING) {
    logger.debug("post protobufbody read index {}", buffer.readerIndex());
  }

  ByteBuf dBody = null;
  int dBodyLength = 0;

  // read the data body.
  if (buffer.readableBytes() > 0) {

    if (RpcConstants.EXTRA_DEBUGGING) {
      logger.debug("Reading raw body, buffer has {} bytes available, is available {}.", buffer.readableBytes(), is.available());
    }
    checkTag(is, RpcEncoder.RAW_BODY_TAG);
    dBodyLength = readRawVarint32(is);
    if (buffer.readableBytes() != dBodyLength) {
      throw new CorruptedFrameException(String.format("Expected to receive a raw body of %d bytes but received a buffer with %d bytes.", dBodyLength, buffer.readableBytes()));
    }
    dBody = buffer.slice();
    dBody.retain(1);
    if (RpcConstants.EXTRA_DEBUGGING) {
      logger.debug("Read raw body of {}", dBody);
    }

  }else{
    if (RpcConstants.EXTRA_DEBUGGING) {
      logger.debug("No need to read raw body, no readable bytes left.");
    }
  }


  // return the rpc message.
  InboundRpcMessage m = new InboundRpcMessage(header.getMode(), header.getRpcType(), header.getCoordinationId(),
      pBody, dBody);

  // move the reader index forward so the next rpc call won't try to work with it.
  buffer.skipBytes(dBodyLength);
  messageCounter.incrementAndGet();
  if (RpcConstants.SOME_DEBUGGING) {
    logger.debug("Inbound Rpc Message Decoded {}.", m);
  }
  out.add(m);

}
 
開發者ID:skhalifa,項目名稱:QDrill,代碼行數:78,代碼來源:RpcDecoder.java

示例13: decode

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
public static org.apache.spark.network.protocol.RpcResponse decode(ByteBuf buf) {
  long requestId = buf.readLong();
  // See comment in encodedLength().
  buf.readInt();
  return new org.apache.spark.network.protocol.RpcResponse(requestId, new NettyManagedBuffer(buf.retain()));
}
 
開發者ID:spafka,項目名稱:spark_deep,代碼行數:7,代碼來源:RpcResponse.java

示例14: decode

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
public static org.apache.spark.network.protocol.OneWayMessage decode(ByteBuf buf) {
  // See comment in encodedLength().
  buf.readInt();
  return new org.apache.spark.network.protocol.OneWayMessage(new NettyManagedBuffer(buf.retain()));
}
 
開發者ID:spafka,項目名稱:spark_deep,代碼行數:6,代碼來源:OneWayMessage.java

示例15: decode

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
public static org.apache.spark.network.protocol.RpcRequest decode(ByteBuf buf) {
  long requestId = buf.readLong();
  // See comment in encodedLength().
  buf.readInt();
  return new org.apache.spark.network.protocol.RpcRequest(requestId, new NettyManagedBuffer(buf.retain()));
}
 
開發者ID:spafka,項目名稱:spark_deep,代碼行數:7,代碼來源:RpcRequest.java


注:本文中的io.netty.buffer.ByteBuf.retain方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。