Example usage for org.apache.hadoop.io WritableUtils writeVInt

List of usage examples for org.apache.hadoop.io WritableUtils writeVInt

Introduction

In this page you can find the example usage for org.apache.hadoop.io WritableUtils writeVInt.

Prototype

public static void writeVInt(DataOutput stream, int i) throws IOException 

Source Link

Document

Serializes an integer to a binary stream with zero-compressed encoding.

Usage

From source file:org.apache.hama.pipes.protocol.BinaryProtocol.java

License:Apache License

@Override
public void abort() throws IOException {
    WritableUtils.writeVInt(this.outStream, MessageType.ABORT.code);
    flush();//from   w w  w .j  a v a 2 s  . c  o  m
    LOG.debug("Sent MessageType.ABORT");
}

From source file:org.apache.hama.pipes.protocol.BinaryProtocol.java

License:Apache License

public void endOfInput() throws IOException {
    WritableUtils.writeVInt(this.outStream, MessageType.CLOSE.code);
    flush();/*ww w .  ja  v  a2 s. c  o  m*/
    LOG.debug("Sent close command");
    LOG.debug("Sent MessageType.CLOSE");
}

From source file:org.apache.hama.pipes.protocol.BinaryProtocol.java

License:Apache License

/**
 * Write the given object to the stream. If it is a IntWritable, LongWritable,
 * FloatWritable, DoubleWritable, Text or BytesWritable, write it directly.
 * Otherwise, write it to a buffer and then write the length and data to the
 * stream.//from   w  ww .  j  a  v a2 s .  c om
 * 
 * @param obj the object to write
 * @throws IOException
 */
protected void writeObject(Writable obj) throws IOException {
    // For basic types IntWritable, LongWritable, Text and BytesWritable,
    // encode them directly, so that they end up
    // in C++ as the natural translations.
    if (obj instanceof Text) {
        Text t = (Text) obj;
        int len = t.getLength();
        WritableUtils.writeVInt(this.outStream, len);
        this.outStream.write(t.getBytes(), 0, len);

    } else if (obj instanceof BytesWritable) {
        BytesWritable b = (BytesWritable) obj;
        int len = b.getLength();
        WritableUtils.writeVInt(this.outStream, len);
        this.outStream.write(b.getBytes(), 0, len);

    } else if (obj instanceof IntWritable) {
        WritableUtils.writeVInt(this.outStream, ((IntWritable) obj).get());

    } else if (obj instanceof LongWritable) {
        WritableUtils.writeVLong(this.outStream, ((LongWritable) obj).get());

    } else {
        // Note: FloatWritable and DoubleWritable are written here
        obj.write(this.outStream);
    }
}

From source file:org.apache.hama.pipes.protocol.UplinkReader.java

License:Apache License

public void reopenInput() throws IOException {
    LOG.debug("Got MessageType.REOPEN_INPUT");

    peer.reopenInput();/*from  ww w.j a v a 2  s.  c  o m*/

    WritableUtils.writeVInt(this.outStream, MessageType.REOPEN_INPUT.code);
    binProtocol.flush();
    LOG.debug("Responded MessageType.REOPEN_INPUT");
}

From source file:org.apache.hama.pipes.protocol.UplinkReader.java

License:Apache License

public void clear() throws IOException {
    LOG.debug("Got MessageType.CLEAR");

    peer.clear();//from w  w w  . ja v  a  2 s  . c o m

    WritableUtils.writeVInt(this.outStream, MessageType.CLEAR.code);
    binProtocol.flush();
    LOG.debug("Responded MessageType.CLEAR");
}

From source file:org.apache.hama.pipes.protocol.UplinkReader.java

License:Apache License

public void getSuperstepCount() throws IOException {
    WritableUtils.writeVInt(this.outStream, MessageType.GET_SUPERSTEP_COUNT.code);
    WritableUtils.writeVLong(this.outStream, peer.getSuperstepCount());
    binProtocol.flush();/*from   ww w.j av a2s.co m*/
    LOG.debug("Responded MessageType.GET_SUPERSTEP_COUNT - SuperstepCount: " + peer.getSuperstepCount());
}

From source file:org.apache.hama.pipes.protocol.UplinkReader.java

License:Apache License

public void getPeerCount() throws IOException {
    WritableUtils.writeVInt(this.outStream, MessageType.GET_PEER_COUNT.code);
    WritableUtils.writeVInt(this.outStream, peer.getNumPeers());
    binProtocol.flush();//from w  w w . j av a 2s. co m
    LOG.debug("Responded MessageType.GET_PEER_COUNT - NumPeers: " + peer.getNumPeers());
}

From source file:org.apache.hama.pipes.protocol.UplinkReader.java

License:Apache License

public void getPeerIndex() throws IOException {
    WritableUtils.writeVInt(this.outStream, MessageType.GET_PEER_INDEX.code);
    WritableUtils.writeVInt(this.outStream, peer.getPeerIndex());
    binProtocol.flush();/*from   w w  w .  ja v a2s.co m*/
    LOG.debug("Responded MessageType.GET_PEER_INDEX - PeerIndex: " + peer.getPeerIndex());
}

From source file:org.apache.hama.pipes.protocol.UplinkReader.java

License:Apache License

public void getPeerName() throws IOException {
    int id = WritableUtils.readVInt(this.inStream);
    LOG.debug("Got MessageType.GET_PEERNAME id: " + id);

    WritableUtils.writeVInt(this.outStream, MessageType.GET_PEERNAME.code);
    if (id == -1) { // -1 indicates get own PeerName
        Text.writeString(this.outStream, peer.getPeerName());
        LOG.debug("Responded MessageType.GET_PEERNAME - Get Own PeerName: " + peer.getPeerName());

    } else if ((id < -1) || (id >= peer.getNumPeers())) {
        // if no PeerName for this index is found write emptyString
        Text.writeString(this.outStream, "");
        LOG.debug("Responded MessageType.GET_PEERNAME - Empty PeerName!");

    } else {//from  w  ww.  j  a  v  a2 s  .  c  o  m
        Text.writeString(this.outStream, peer.getPeerName(id));
        LOG.debug("Responded MessageType.GET_PEERNAME - PeerName: " + peer.getPeerName(id));
    }
    binProtocol.flush();
}

From source file:org.apache.hama.pipes.protocol.UplinkReader.java

License:Apache License

public void getAllPeerNames() throws IOException {
    LOG.debug("Got MessageType.GET_ALL_PEERNAME");
    String[] peerNames = peer.getAllPeerNames();
    WritableUtils.writeVInt(this.outStream, MessageType.GET_ALL_PEERNAME.code);
    WritableUtils.writeVInt(this.outStream, peerNames.length);
    for (String s : peerNames) {
        Text.writeString(this.outStream, s);
    }/*from   w  ww  .  j a  v  a  2s .  co  m*/
    binProtocol.flush();
    LOG.debug("Responded MessageType.GET_ALL_PEERNAME - peerNamesCount: " + peerNames.length);
}