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 SummaryFieldsModifier and TypeFieldDescriptionprivate longprivate final longprivate final InputStreamprivate final longprivate long
- 
Constructor SummaryConstructorsConstructorDescriptionThrottledInputStream(InputStream rawStream) ThrottledInputStream(InputStream rawStream, long maxBytesPerSec) 
- 
Method SummaryModifier 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.InputStreamavailable, mark, markSupported, nullInputStream, readAllBytes, readNBytes, readNBytes, reset, skip, skipNBytes, transferTo
- 
Field Details- 
rawStream
- 
maxBytesPerSec
- 
startTime
- 
bytesRead
- 
totalSleepTime
 
- 
- 
Constructor Details- 
ThrottledInputStream
- 
ThrottledInputStream
 
- 
- 
Method Details- 
close- Specified by:
- closein interface- AutoCloseable
- Specified by:
- closein interface- Closeable
- Overrides:
- closein class- InputStream
- Throws:
- IOException
 
- 
read- Specified by:
- readin class- InputStream
- Throws:
- IOException
 
- 
read- Overrides:
- readin class- InputStream
- Throws:
- IOException
 
- 
read- Overrides:
- readin class- InputStream
- Throws:
- IOException
 
- 
readRead 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
 
- 
getTotalBytesReadGetter for the number of bytes read from this stream, since creation.- Returns:
- The number of bytes.
 
- 
getBytesPerSecGetter for the read-rate from this stream, since creation. Calculated as bytesRead/elapsedTimeSinceStart.- Returns:
- Read rate, in bytes/sec.
 
- 
getTotalSleepTimeGetter the total time spent in sleep.- Returns:
- Number of milliseconds spent in sleep.
 
- 
toString
 
-