コード例 #1
0
  @Override
  public void read(int len) {
    if (readByteBuffer.position() != readByteBuffer.capacity()) {
      logger.error(
          "Read buffer position {} != capacity {}",
          readByteBuffer.position(),
          readByteBuffer.capacity());
      eventLoop.disconnect(this);
      return;
    }

    readByteBuffer.flip();
    long timestamp = readByteBuffer.getLong();
    if (timestamp < -2) {
      logger.error("Received bad timestamp {}", timestamp);
      eventLoop.disconnect(this);
      return;
    } else if (timestamp != this.timestamp) {
      logger.error("Received bad timestamp {}. Sent timestamp {}", timestamp, this.timestamp);
      eventLoop.disconnect(this);
      return;
    } else if (timestamp > 0) {
      benchmarkResults.addResult(System.nanoTime() - timestamp);
    }
    readByteBuffer.clear();

    send();
  }
コード例 #2
0
 private void send(final long tsSent) {
   this.timestamp = tsSent;
   sendByteBuffer.putLong(tsSent);
   while (sendByteBuffer.hasRemaining()) {
     sendByteBuffer.put((byte) 'x');
   }
   sendByteBuffer.flip();
   try {
     while (!send(sendByteBuffer.array())) {
       sleep(5);
     }
     write();
   } catch (Exception e) {
     logger.error("", e);
     eventLoop.disconnect(this);
     return;
   }
   sendByteBuffer.clear();
 }
コード例 #3
0
 private void send() {
   if (warmingUp) {
     if (++count == BenchmarkConfiguration.messageCount) {
       logger.info(
           "Finished warming up! Sent {} messages in {} millis",
           count,
           System.currentTimeMillis() - start);
       warmingUp = false;
       benchmarking = true;
       count = 0;
       send(System.nanoTime());
     } else {
       send(0);
     }
   } else if (benchmarking) {
     if (++count == BenchmarkConfiguration.messageCount) {
       send(-2);
       logger.info("Finished sending messages! Sent {} messages.", count);
       eventLoop.disconnect(this);
     } else {
       send(System.nanoTime());
     }
   }
 }