Ejemplo n.º 1
0
  /** Populates the header with information received via socket */
  public void readHeader() throws IOException {
    if (this.socket != null) {
      final ByteBuffer cb = getCommBuffer();
      synchronized (cb) {
        fetchHeader();
        final int type = cb.getInt();
        final int numParts = cb.getInt();
        final int txid = cb.getInt();
        cb.clear();
        if (!MessageType.validate(type)) {
          throw new IOException(
              LocalizedStrings.ChunkedMessage_INVALID_MESSAGE_TYPE_0_WHILE_READING_HEADER
                  .toLocalizedString(Integer.valueOf(type)));
        }

        // Set the header and payload fields only after receiving all the
        // socket data, providing better message consistency in the face
        // of exceptional conditions (e.g. IO problems, timeouts etc.)
        this.msgType = type;
        this.numberOfParts = numParts; // Already set in setPayloadFields via setNumberOfParts
        this.transactionId = txid;
      }
    } else {
      throw new IOException(LocalizedStrings.ChunkedMessage_DEAD_CONNECTION.toLocalizedString());
    }
  }
Ejemplo n.º 2
0
 /** Reads a chunk of this message. */
 public void receiveChunk() throws IOException {
   if (this.socket != null) {
     synchronized (getCommBuffer()) {
       readChunk();
     }
   } else {
     throw new IOException(LocalizedStrings.ChunkedMessage_DEAD_CONNECTION.toLocalizedString());
   }
 }
Ejemplo n.º 3
0
 /** Sends the header of this message. */
 public void sendHeader() throws IOException {
   if (this.socket != null) {
     synchronized (getCommBuffer()) {
       getHeaderBytesForWrite();
       flushBuffer();
       // Darrel says: I see no need for the following os.flush() call
       // so I've deadcoded it for performance.
       // this.os.flush();
     }
     this.currentPart = 0;
     this.headerSent = true;
   } else {
     throw new IOException(LocalizedStrings.ChunkedMessage_DEAD_CONNECTION.toLocalizedString());
   }
 }