Beispiel #1
0
 void updateCounters() {
   if (readBytesCounter == null) {
     readBytesCounter = counterManager.findCounter(scheme, FileSystemCounter.BYTES_READ);
   }
   if (writeBytesCounter == null) {
     writeBytesCounter = counterManager.findCounter(scheme, FileSystemCounter.BYTES_WRITTEN);
   }
   if (readOpsCounter == null) {
     readOpsCounter = counterManager.findCounter(scheme, FileSystemCounter.READ_OPS);
   }
   if (largeReadOpsCounter == null) {
     largeReadOpsCounter = counterManager.findCounter(scheme, FileSystemCounter.LARGE_READ_OPS);
   }
   if (writeOpsCounter == null) {
     writeOpsCounter = counterManager.findCounter(scheme, FileSystemCounter.WRITE_OPS);
   }
   long readBytes = 0;
   long writeBytes = 0;
   long readOps = 0;
   long largeReadOps = 0;
   long writeOps = 0;
   for (FileSystem.Statistics stat : stats) {
     readBytes = readBytes + stat.getBytesRead();
     writeBytes = writeBytes + stat.getBytesWritten();
     readOps = readOps + stat.getReadOps();
     largeReadOps = largeReadOps + stat.getLargeReadOps();
     writeOps = writeOps + stat.getWriteOps();
   }
   readBytesCounter.setValue(readBytes);
   writeBytesCounter.setValue(writeBytes);
   readOpsCounter.setValue(readOps);
   largeReadOpsCounter.setValue(largeReadOps);
   writeOpsCounter.setValue(writeOps);
 }
Beispiel #2
0
 @Override
 public synchronized int read() throws IOException {
   if (closed) {
     throw new IOException("Stream closed");
   }
   int result = -1;
   if (pos < fileLength) {
     if (pos > blockEnd) {
       blockSeekTo(pos);
     }
     result = blockStream.read();
     if (result >= 0) {
       pos++;
     }
   }
   if (stats != null & result >= 0) {
     stats.incrementBytesRead(1);
   }
   return result;
 }
Beispiel #3
0
 @Override
 public synchronized int read(byte buf[], int off, int len) throws IOException {
   if (closed) {
     throw new IOException("Stream closed");
   }
   if (pos < fileLength) {
     if (pos > blockEnd) {
       blockSeekTo(pos);
     }
     int realLen = Math.min(len, (int) (blockEnd - pos + 1));
     int result = blockStream.read(buf, off, realLen);
     if (result >= 0) {
       pos += result;
     }
     if (stats != null && result > 0) {
       stats.incrementBytesRead(result);
     }
     return result;
   }
   return -1;
 }