Class ThrottledInputStream
java.lang.Object
java.io.InputStream
org.apache.hadoop.hbase.io.hadoopbackport.ThrottledInputStream
- All Implemented Interfaces:
Closeable,AutoCloseable
The ThrottleInputStream provides bandwidth throttling on a specified InputStream. It is
implemented as a wrapper on top of another InputStream instance. The throttling works by
examining the number of bytes read from the underlying InputStream from the beginning, and
sleep()ing for a time interval if the byte-transfer is found exceed the specified tolerable
maximum. (Thus, while the read-rate might exceed the maximum for a given short interval, the
average tends towards the specified maximum, overall.)
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate longprivate final longprivate final InputStreamprivate final longprivate long -
Constructor Summary
ConstructorsConstructorDescriptionThrottledInputStream(InputStream rawStream) ThrottledInputStream(InputStream rawStream, long maxBytesPerSec) -
Method Summary
Modifier and TypeMethodDescriptionprivate long(package private) static longcalSleepTimeMs(long bytesRead, long maxBytesPerSec, long elapsed) voidclose()longGetter for the read-rate from this stream, since creation.longGetter for the number of bytes read from this stream, since creation.longGetter the total time spent in sleep.intread()intread(byte[] b) intread(byte[] b, int off, int len) intread(long position, byte[] buffer, int offset, int length) Read bytes starting from the specified position.private voidthrottle()toString()Methods inherited from class java.io.InputStream
available, mark, markSupported, reset, skip
-
Field Details
-
rawStream
-
maxBytesPerSec
-
startTime
-
bytesRead
-
totalSleepTime
-
-
Constructor Details
-
ThrottledInputStream
-
ThrottledInputStream
-
-
Method Details
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classInputStream- Throws:
IOException
-
read
- Specified by:
readin classInputStream- Throws:
IOException
-
read
- Overrides:
readin classInputStream- Throws:
IOException
-
read
- Overrides:
readin classInputStream- Throws:
IOException
-
read
Read bytes starting from the specified position. This requires rawStream is an instance ofPositionedReadable.- Returns:
- the number of bytes read
- Throws:
IOException
-
calSleepTimeMs
-
calSleepTimeMs
-
throttle
- Throws:
InterruptedIOException
-
getTotalBytesRead
Getter for the number of bytes read from this stream, since creation.- Returns:
- The number of bytes.
-
getBytesPerSec
Getter for the read-rate from this stream, since creation. Calculated as bytesRead/elapsedTimeSinceStart.- Returns:
- Read rate, in bytes/sec.
-
getTotalSleepTime
Getter the total time spent in sleep.- Returns:
- Number of milliseconds spent in sleep.
-
toString
-