Search in sources :

Example 11 with DataByteBuffer

use of alluxio.network.protocol.databuffer.DataByteBuffer in project alluxio by Alluxio.

the class RPCBlockWriteRequest method decode.

/**
   * Decodes the input {@link ByteBuf} into a {@link RPCBlockWriteRequest} object and returns it.
   *
   * @param in the input {@link ByteBuf}
   * @return The decoded RPCBlockWriteRequest object
   */
public static RPCBlockWriteRequest decode(ByteBuf in) {
    long sessionId = in.readLong();
    long blockId = in.readLong();
    long offset = in.readLong();
    long length = in.readLong();
    // TODO(gene): Look into accessing Netty ByteBuf directly, to avoid copying the data.
    // Length will always be greater than 0 if the request is not corrupted. If length is negative,
    // ByteBuffer.allocate will fail. If length is 0 this will become a no-op but still go through
    // the necessary calls to validate the sessionId/blockId. If length is positive, the request
    // will proceed as normal
    ByteBuffer buffer = ByteBuffer.allocate((int) length);
    in.readBytes(buffer);
    DataByteBuffer data = new DataByteBuffer(buffer, (int) length);
    return new RPCBlockWriteRequest(sessionId, blockId, offset, length, data);
}
Also used : DataByteBuffer(alluxio.network.protocol.databuffer.DataByteBuffer) DataByteBuffer(alluxio.network.protocol.databuffer.DataByteBuffer) ByteBuffer(java.nio.ByteBuffer)

Example 12 with DataByteBuffer

use of alluxio.network.protocol.databuffer.DataByteBuffer in project alluxio by Alluxio.

the class RPCFileWriteRequest method decode.

/**
   * Decodes the input {@link ByteBuf} into a {@link RPCFileWriteRequest} object and returns it.
   *
   * @param in the input {@link ByteBuf}
   * @return The decoded RPCFileWriteRequest object
   */
public static RPCFileWriteRequest decode(ByteBuf in) {
    long tempUfsFileId = in.readLong();
    long offset = in.readLong();
    long length = in.readLong();
    // TODO(gene): Look into accessing Netty ByteBuf directly, to avoid copying the data.
    // Length will always be greater than 0 if the request is not corrupted. If length is negative,
    // ByteBuffer.allocate will fail. If length is 0 this will become a no-op but still go through
    // the necessary calls to validate the tempUfsFileId. If length is positive, the request will
    // proceed as normal
    ByteBuffer buffer = ByteBuffer.allocate((int) length);
    in.readBytes(buffer);
    DataByteBuffer data = new DataByteBuffer(buffer, (int) length);
    return new RPCFileWriteRequest(tempUfsFileId, offset, length, data);
}
Also used : DataByteBuffer(alluxio.network.protocol.databuffer.DataByteBuffer) DataByteBuffer(alluxio.network.protocol.databuffer.DataByteBuffer) ByteBuffer(java.nio.ByteBuffer)

Aggregations

DataByteBuffer (alluxio.network.protocol.databuffer.DataByteBuffer)12 ByteBuffer (java.nio.ByteBuffer)7 Test (org.junit.Test)6 DataBuffer (alluxio.network.protocol.databuffer.DataBuffer)5 RPCBlockReadResponse (alluxio.network.protocol.RPCBlockReadResponse)2 ChannelFuture (io.netty.channel.ChannelFuture)2 IOException (java.io.IOException)2 BlockDoesNotExistException (alluxio.exception.BlockDoesNotExistException)1 RPCFileReadResponse (alluxio.network.protocol.RPCFileReadResponse)1 BlockReader (alluxio.worker.block.io.BlockReader)1 InputStream (java.io.InputStream)1