|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjsync.Conveyer
Class for parallel input data reading and processing. Two concurrent threads are started: one of them reads data from input stream in cyclic buffer and second thread performs processing of data, previously placed in another part of the buffer.
Processing of data is performed by overridden method process()
of class derived from Conveyer
. Processing of data continues
until end of stream is reached or process()
method returns false
.
Constructor Summary | |
Conveyer(java.io.InputStream stream,
int blockSize)
Create Conveyer object with specified block size.
|
|
Conveyer(java.io.InputStream stream,
int blockSize,
int bufferSize)
Create Conveyer object with specified size of cyclic
buffer and block size. |
Method Summary | |
abstract boolean |
process(byte[] buffer,
int offset,
int length)
Abstract method to be implemented in derived class. |
void |
setInputStream(java.io.InputStream stream)
Set new input stream for conveyer. |
void |
start()
Start execution of reading and processing threads. |
boolean |
waitTermination()
Wait termination of data processing thread. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public Conveyer(java.io.InputStream stream, int blockSize, int bufferSize)
Conveyer
object with specified size of cyclic
buffer and block size.
stream
- input stream from which data is extractedblockSize
- size of block for reading and processing data.
Read and data processing operation will not take more
than blockSize
bytes of data.bufferSize
- sizeof of cyclic buffer. Should be not less than
blockSize
.public Conveyer(java.io.InputStream stream, int blockSize)
Conveyer
object with specified block size.
Size of buffer is set by multiplying block size by two.
So read and process operations can be executed in parallel for
different parts of the buffer.
stream
- input stream from which data is extractedblockSize
- size of block for reading and processing data.
Input stream read and data processing operation will not take more
than blockSize
bytes of data.Method Detail |
public void setInputStream(java.io.InputStream stream)
stream
- new input streampublic void start()
public boolean waitTermination()
true
if all data from input stream is processed,
false
if processing of data is interrupted because
process()
method returns false
.public abstract boolean process(byte[] buffer, int offset, int length)
buffer
- cyclic buffer maintained by Conveyer
classoffset
- position in buffer of data to be processedlength
- number of bytes of data available for processing. Value
of this parameter never exceeds blockSize
.
false
processing of
data is finished, and both threads are stopped.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |