org.apache.lucene.util
Class ThrottledIndexOutput

java.lang.Object
  extended by org.apache.lucene.store.DataOutput
      extended by org.apache.lucene.store.IndexOutput
          extended by org.apache.lucene.util.ThrottledIndexOutput
All Implemented Interfaces:
Closeable

public class ThrottledIndexOutput
extends IndexOutput

Intentionally slow IndexOutput for testing.


Field Summary
static int DEFAULT_MIN_WRITTEN_BYTES
           
 
Constructor Summary
ThrottledIndexOutput(int bytesPerSecond, long delayInMillis, IndexOutput delegate)
           
ThrottledIndexOutput(int bytesPerSecond, long delays, int minBytesWritten, IndexOutput delegate)
           
ThrottledIndexOutput(int bytesPerSecond, long flushDelayMillis, long closeDelayMillis, long seekDelayMillis, long minBytesWritten, IndexOutput delegate)
           
 
Method Summary
 void close()
          Closes this stream to further operations.
 void copyBytes(DataInput input, long numBytes)
          Copy numBytes bytes from input to ourself.
 void flush()
          Forces any buffered output to be written.
protected  long getDelay(boolean closing)
           
 long getFilePointer()
          Returns the current position in this file, where the next write will occur.
 long length()
          The number of bytes in the file.
static int mBitsToBytes(int mbits)
           
 ThrottledIndexOutput newFromDelegate(IndexOutput output)
           
 void seek(long pos)
          Sets current position in this file, where the next write will occur.
 void setLength(long length)
          Set the file length.
 void writeByte(byte b)
          Writes a single byte.
 void writeBytes(byte[] b, int offset, int length)
          Writes an array of bytes.
 
Methods inherited from class org.apache.lucene.store.DataOutput
writeBytes, writeChars, writeChars, writeInt, writeLong, writeShort, writeString, writeStringStringMap, writeVInt, writeVLong
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_MIN_WRITTEN_BYTES

public static final int DEFAULT_MIN_WRITTEN_BYTES
See Also:
Constant Field Values
Constructor Detail

ThrottledIndexOutput

public ThrottledIndexOutput(int bytesPerSecond,
                            long delayInMillis,
                            IndexOutput delegate)

ThrottledIndexOutput

public ThrottledIndexOutput(int bytesPerSecond,
                            long delays,
                            int minBytesWritten,
                            IndexOutput delegate)

ThrottledIndexOutput

public ThrottledIndexOutput(int bytesPerSecond,
                            long flushDelayMillis,
                            long closeDelayMillis,
                            long seekDelayMillis,
                            long minBytesWritten,
                            IndexOutput delegate)
Method Detail

newFromDelegate

public ThrottledIndexOutput newFromDelegate(IndexOutput output)

mBitsToBytes

public static final int mBitsToBytes(int mbits)

flush

public void flush()
           throws IOException
Description copied from class: IndexOutput
Forces any buffered output to be written.

Specified by:
flush in class IndexOutput
Throws:
IOException

close

public void close()
           throws IOException
Description copied from class: IndexOutput
Closes this stream to further operations.

Specified by:
close in interface Closeable
Specified by:
close in class IndexOutput
Throws:
IOException

getFilePointer

public long getFilePointer()
Description copied from class: IndexOutput
Returns the current position in this file, where the next write will occur.

Specified by:
getFilePointer in class IndexOutput
See Also:
IndexOutput.seek(long)

seek

public void seek(long pos)
          throws IOException
Description copied from class: IndexOutput
Sets current position in this file, where the next write will occur.

Specified by:
seek in class IndexOutput
Throws:
IOException
See Also:
IndexOutput.getFilePointer()

length

public long length()
            throws IOException
Description copied from class: IndexOutput
The number of bytes in the file.

Specified by:
length in class IndexOutput
Throws:
IOException

writeByte

public void writeByte(byte b)
               throws IOException
Description copied from class: DataOutput
Writes a single byte.

Specified by:
writeByte in class DataOutput
Throws:
IOException
See Also:
DataInput.readByte()

writeBytes

public void writeBytes(byte[] b,
                       int offset,
                       int length)
                throws IOException
Description copied from class: DataOutput
Writes an array of bytes.

Specified by:
writeBytes in class DataOutput
Parameters:
b - the bytes to write
offset - the offset in the byte array
length - the number of bytes to write
Throws:
IOException
See Also:
DataInput.readBytes(byte[],int,int)

getDelay

protected long getDelay(boolean closing)

setLength

public void setLength(long length)
               throws IOException
Description copied from class: IndexOutput
Set the file length. By default, this method does nothing (it's optional for a Directory to implement it). But, certain Directory implementations (for example @see FSDirectory) can use this to inform the underlying IO system to pre-allocate the file to the specified size. If the length is longer than the current file length, the bytes added to the file are undefined. Otherwise the file is truncated.

Overrides:
setLength in class IndexOutput
Parameters:
length - file length
Throws:
IOException

copyBytes

public void copyBytes(DataInput input,
                      long numBytes)
               throws IOException
Description copied from class: DataOutput
Copy numBytes bytes from input to ourself.

Overrides:
copyBytes in class DataOutput
Throws:
IOException