Example usage for io.netty.buffer ByteBuf readLong

List of usage examples for io.netty.buffer ByteBuf readLong

Introduction

In this page you can find the example usage for io.netty.buffer ByteBuf readLong.

Prototype

public abstract long readLong();

Source Link

Document

Gets a 64-bit integer at the current readerIndex and increases the readerIndex by 8 in this buffer.

Usage

From source file:com.heliosapm.ohcrs.core.AbstractDriverCodec.java

License:Apache License

/**
 * {@inheritDoc}//from w w  w  . ja v a  2s  .c om
 * @see com.heliosapm.ohcrs.core.DriverCodec#readLong(io.netty.buffer.ByteBuf)
 */
@Override
public Long readLong(final ByteBuf b) throws SQLException {
    if (checkNull(b))
        return null;
    return b.readLong();
}

From source file:com.heliosapm.ohcrs.core.AbstractDriverCodec.java

License:Apache License

/**
 * {@inheritDoc}/*from   ww  w.j  av  a 2  s  . c  o  m*/
 * @see com.heliosapm.ohcrs.core.DriverCodec#readlong(io.netty.buffer.ByteBuf)
 */
@Override
public long readlong(final ByteBuf b) throws SQLException {
    if (checkNull(b))
        return 0L;
    return b.readLong();
}

From source file:com.heliosapm.streams.metrics.StreamedMetric.java

License:Open Source License

void readFromBuff(final ByteBuf buff) {
    final byte v = buff.readByte();
    if (v == 0) {
        valueType = null;/*from   w  w w .jav a  2s.  com*/
    } else {
        valueType = ValueType.ordinal(v - 1);
    }
    timestamp = buff.readLong();
    metricName = BufferManager.readUTF(buff);
    final int tsize = buff.readByte();
    for (int i = 0; i < tsize; i++) {
        final String key = BufferManager.readUTF(buff);
        final String val = BufferManager.readUTF(buff);
        tags.put(key, val);
    }
}

From source file:com.heliosapm.streams.metrics.StreamedMetricValue.java

License:Apache License

/**
 * Updates this StreamedMetricValue using the next serialized version in the passed ByteBuf. 
 * @param buf The buffer to update from/* w w w . j a v a2s . c  om*/
 * @return this StreamedMetricValue
 */
@Override
public StreamedMetricValue update(final ByteBuf buf) {
    super.update(buf);
    if (buf.readByte() == ZERO_BYTE) {
        isDoubleValue = true;
        doubleValue = buf.readDouble();
    } else {
        isDoubleValue = false;
        longValue = buf.readLong();
    }
    return this;
}

From source file:com.heliosapm.streams.metrics.StreamedMetricValue.java

License:Apache License

/**
 * Reads a StreamedMetricValue from the passed buffer
 * @param buff The buffer to read from/*from w ww. j  a  v  a  2s .c  o m*/
 * @return the StreamedMetricValue
 */
public static StreamedMetricValue from(final ByteBuf buff) {
    buff.readByte();
    final byte vt = buff.readByte();
    final ValueType valueType = vt == 0 ? null : ValueType.ordinal(vt);
    final long ts = buff.readLong();
    final String mn = BufferManager.readUTF(buff);
    final int tagCount = buff.readByte();
    final Map<String, String> tags = new HashMap<String, String>(tagCount);
    for (int i = 0; i < tagCount; i++) {
        tags.put(BufferManager.readUTF(buff), BufferManager.readUTF(buff));
    }
    final byte lord = buff.readByte();
    if (lord == 0) {
        return new StreamedMetricValue(ts, buff.readDouble(), mn, tags).setValueType(valueType);
    }
    return new StreamedMetricValue(ts, buff.readLong(), mn, tags).setValueType(valueType);

}

From source file:com.heliosapm.streams.metrics.StreamedMetricValue.java

License:Apache License

/**
 * Creates a StreamedMetricValue from the passed buffer
 * @param bytes The byte to read the StreamedMetric from
 * @return the created StreamedMetric/*from  ww w .j  a v  a  2  s  .  c o m*/
 */
static StreamedMetricValue fromBuff(final ByteBuf buff) {
    final StreamedMetricValue sm = new StreamedMetricValue();
    sm.byteSize = buff.readableBytes() + 1;
    sm.readFromBuff(buff);
    final byte type = buff.readByte();
    if (type == 0) {
        sm.isDoubleValue = true;
        sm.doubleValue = buff.readDouble();
    } else {
        sm.isDoubleValue = false;
        sm.longValue = buff.readLong();
    }
    return sm;
}

From source file:com.hiido.eagle.hes.transfer.FileTransferServer.java

License:Apache License

protected FileStoreInfo createAndStoreFile(ChannelHandlerContext ctx, Object msg) throws Exception {
    ByteBuf in = (ByteBuf) msg;
    int filePathSize = in.readInt();
    String fileName = new String(in.readBytes(filePathSize).array());
    long fileSize = in.readLong();

    String localPath = TransferServerConfig.class.getResource("/").getPath() + fileName;
    logger.info("Start to handler the file [{}] with size [{}b] which be writen to local disk [{}]", fileName,
            fileSize, localPath);//from   w  w  w . j av a  2 s . c o m

    long currFileSize = in.readableBytes();
    ByteBuffer buf = ByteBuffer.allocate((int) currFileSize);
    in.readBytes(buf);

    RandomAccessFile accessfile = new RandomAccessFile(localPath, "rw");
    FileChannel fileChannel = accessfile.getChannel();
    fileChannel.write(buf);
    return new FileStoreInfo(accessfile, fileChannel, fileName, fileSize, currFileSize);
}

From source file:com.ibm.crail.datanode.netty.rpc.RdmaMsgHeader.java

License:Apache License

public void decodeHeader(ByteBuf src) {
    this.address = src.readLong();
    this.opLength = src.readInt();
    this.stag = src.readInt();
    this.type = src.readInt();
    this.status = src.readInt();
    this.cookie = src.readLong();
}

From source file:com.ibm.crail.namenode.rpc.netty.common.NettyRequest.java

License:Apache License

public void update(ByteBuf buffer) throws IOException {

    this.cookie = buffer.readLong();
    this.cmd = buffer.readShort();
    this.type = buffer.readShort();

    nioBuffer.clear();/*from  ww  w.  ja v  a  2 s. co m*/
    buffer.readBytes(nioBuffer);
    nioBuffer.flip();

    switch (type) {
    case NameNodeProtocol.REQ_CREATE_FILE:
        this.createFileReq = new RpcRequestMessage.CreateFileReq();
        createFileReq.update(nioBuffer);
        break;
    case NameNodeProtocol.REQ_GET_FILE:
        this.fileReq = new RpcRequestMessage.GetFileReq();
        fileReq.update(nioBuffer);
        break;
    case NameNodeProtocol.REQ_SET_FILE:
        this.setFileReq = new RpcRequestMessage.SetFileReq();
        setFileReq.update(nioBuffer);
        break;
    case NameNodeProtocol.REQ_REMOVE_FILE:
        this.removeReq = new RpcRequestMessage.RemoveFileReq();
        removeReq.update(nioBuffer);
        break;
    case NameNodeProtocol.REQ_RENAME_FILE:
        this.renameFileReq = new RpcRequestMessage.RenameFileReq();
        renameFileReq.update(nioBuffer);
        break;
    case NameNodeProtocol.REQ_GET_BLOCK:
        this.getBlockReq = new RpcRequestMessage.GetBlockReq();
        getBlockReq.update(nioBuffer);
        break;
    case NameNodeProtocol.REQ_GET_LOCATION:
        this.getLocationReq = new RpcRequestMessage.GetLocationReq();
        getLocationReq.update(nioBuffer);
        break;
    case NameNodeProtocol.REQ_SET_BLOCK:
        this.setBlockReq = new RpcRequestMessage.SetBlockReq();
        setBlockReq.update(nioBuffer);
        break;
    case NameNodeProtocol.REQ_GET_DATANODE:
        this.getDataNodeReq = new RpcRequestMessage.GetDataNodeReq();
        getDataNodeReq.update(nioBuffer);
        break;
    case NameNodeProtocol.REQ_DUMP_NAMENODE:
        this.dumpNameNodeReq = new RpcRequestMessage.DumpNameNodeReq();
        dumpNameNodeReq.update(nioBuffer);
        break;
    case NameNodeProtocol.REQ_PING_NAMENODE:
        this.pingNameNodeReq = new RpcRequestMessage.PingNameNodeReq();
        pingNameNodeReq.update(nioBuffer);
        break;
    }
}

From source file:com.ibm.crail.namenode.rpc.netty.common.ResponseDecoder.java

License:Apache License

@Override
protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List<Object> list)
        throws Exception {
    if (byteBuf.readableBytes() < NettyResponse.CSIZE) {
        return;//from  ww w  .  j av  a2 s.  c  o  m
    }
    long cookie = byteBuf.readLong();
    /* allocate a new response here and then proceed */
    NettyResponse resp = this.group.retriveAndRemove(cookie);
    resp.update(cookie, byteBuf);
    resp.getNettyCommonFuture().markDone();
}