Package io.netty.buffer

Examples of io.netty.buffer.ByteBuf.retain()


                UUID uuid = UUID.randomUUID();

                try {
                  for (HelixAddress destination : destinations) {
                    m.retain();
                    ipcService.send(destination, MESSAGE_TYPE, uuid, m);
                  }
                } catch (Exception e) {
                  e.printStackTrace();
                }
View Full Code Here


            if (buffer.readableBytes() < frameLength)
                return;

            // extract body
            ByteBuf body = buffer.slice(idx, (int) bodyLength);
            body.retain();
           
            idx += bodyLength;
            buffer.readerIndex(idx);

            Connection connection = ctx.channel().attr(Connection.attributeKey).get();
View Full Code Here

            if (buffer.readableBytes() < frameLength)
                return;

            // extract body
            ByteBuf body = buffer.slice(idx, (int) bodyLength);
            body.retain();
           
            idx += bodyLength;
            buffer.readerIndex(idx);

            Connection connection = ctx.channel().attr(Connection.attributeKey).get();
View Full Code Here

    @Override
    protected void encode(ChannelHandlerContext ctx, AddressedEnvelope<Object, InetSocketAddress> msg, List<Object> out) throws Exception {
        if (msg.content() instanceof ByteBuf) {
            ByteBuf payload = (ByteBuf)msg.content();
            // Just wrap the message as DatagramPacket, need to make sure the message content is ByteBuf
            DatagramPacket dp = new DatagramPacket(payload.retain(), msg.recipient());
            out.add(dp);
        }
    }

}
View Full Code Here

        if (msg.content() instanceof Serializable) {
            Serializable payload = (Serializable) msg.content();
            ByteBuf buf = ctx.alloc().heapBuffer();
            delegateObjectEncoder.encode(ctx, payload, buf);
            AddressedEnvelope<Object, InetSocketAddress> addressedEnvelop =
                new DefaultAddressedEnvelope<Object, InetSocketAddress>(buf.retain(), msg.recipient(), msg.sender());
            out.add(addressedEnvelop);
        }
       
    }
View Full Code Here

  public ByteBuf getBuffer()
  {
      ByteBuf bufferHandle = this.buffer;

      /* Increment the ref count for this buffer */
      bufferHandle.retain();

      /* We are passing ownership of the buffer to the
       * caller. clear the buffer from within our selection vector
       */
      clear();
View Full Code Here

    // 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();
    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;
View Full Code Here

      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();
      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.");
    }
View Full Code Here

            if (buffer.readableBytes() < frameLength)
                return;

            // extract body
            ByteBuf body = buffer.slice(idx, (int) bodyLength);
            body.retain();
           
            idx += bodyLength;
            buffer.readerIndex(idx);

            Connection connection = ctx.channel().attr(Connection.attributeKey).get();
View Full Code Here

                        .getContentTransferEncoding(), fileUpload.getCharset(),
                        definedSize);

                ByteBuf data = fileUpload.getByteBuf();
                if (data != null && data.isReadable()) {
                    diskFileUpload.addContent(data.retain(), false);
                }
                // release old upload
                fileUpload.release();

                fileUpload = diskFileUpload;
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.