当前位置: 首页>>代码示例>>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;未经允许,请勿转载。