本文整理汇总了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);
}
示例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();
}
}
示例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;
}
}
示例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());
}
}
示例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());
}
示例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();
}
示例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());
}
示例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);
}
示例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));
}
}
示例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();
}
}
示例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();
}
}
示例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);
}
示例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()));
}
示例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()));
}
示例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()));
}