コード例 #1
0
ファイル: HBaseClient.java プロジェクト: 06094051/hindex
    /* Initiates a call by sending the parameter to the remote server.
     * Note: this is not called from the Connection thread, but by other
     * threads.
     */
    protected void sendParam(Call call) {
      if (shouldCloseConnection.get()) {
        return;
      }

      // For serializing the data to be written.

      final DataOutputBuffer d = new DataOutputBuffer();
      try {
        if (LOG.isDebugEnabled()) LOG.debug(getName() + " sending #" + call.id);

        d.writeInt(0xdeadbeef); // placeholder for data length
        d.writeInt(call.id);
        call.param.write(d);
        byte[] data = d.getData();
        int dataLength = d.getLength();
        // fill in the placeholder
        Bytes.putInt(data, 0, dataLength - 4);
        //noinspection SynchronizeOnNonFinalField
        synchronized (this.out) { // FindBugs IS2_INCONSISTENT_SYNC
          out.write(data, 0, dataLength);
          out.flush();
        }
      } catch (IOException e) {
        markClosed(e);
      } finally {
        // the buffer is just an in-memory buffer, but it is still polite to
        // close early
        IOUtils.closeStream(d);
      }
    }
コード例 #2
0
 /**
  * Serialize the shuffle port into a ByteBuffer for use later on.
  *
  * @param port the port to be sent to the ApplciationMaster
  * @return the serialized form of the port.
  */
 public static ByteBuffer serializeMetaData(int port) throws IOException {
   // TODO these bytes should be versioned
   DataOutputBuffer port_dob = new DataOutputBuffer();
   port_dob.writeInt(port);
   return ByteBuffer.wrap(port_dob.getData(), 0, port_dob.getLength());
 }