|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.metastatic.rsync.MatcherStream
A streaming version of Matcher
. The idea here is that the
hashtable search is the most expensive operation in the rsync
algorithm, and it is at times undesirable to wait for this to finish
while whoever on the other end of the wire is waiting for our data.
With this construction, we can send Delta
s as soon as they
are generated.
To implement the outgoing stream of Deltas, this class makes use
of a callback interface, MatcherListener
. Pass a concrete
implementation of this interface to the addListener(MatcherListener)
method, and a List
of ChecksumPair
s before calling any of the
update
methods. Once the data have been passed to these
methods, call doFinal()
to finish the process.
Field Summary | |
---|---|
protected byte[] |
buffer
The intermediate byte buffer. |
protected Configuration |
config
The configuration. |
protected long |
count
The number of bytes summed thusfar. |
protected TwoKeyMap |
hashtable
The current hashtable. |
protected List |
listeners
The list of MatcherListener s. |
protected int |
ndx
The current index in buffer . |
Constructor Summary | |
---|---|
MatcherStream(Configuration config)
Create a new MatcherStream. |
Method Summary | |
---|---|
void |
addListener(MatcherListener listener)
Add a MatcherListener to the list of listeners. |
void |
doFinal()
Flush any buffered data and reset this instance. |
protected Long |
hashSearch(byte[] block,
int off,
int len)
Search if a portion of the given byte array is in the map, returning its original offset if it is. |
boolean |
removeListener(MatcherListener listener)
Remove a MatcherListener from the list of listeners. |
void |
reset()
Reset this matcher, to be used for another data set. |
void |
setChecksums(List sums)
Set the list of checksums that will be searched by this matcher. |
void |
update(byte b)
Update this matcher with a single byte. |
void |
update(byte[] buf)
Update this matcher with a byte array. |
void |
update(byte[] buf,
int off,
int len)
Update this matcher with a portion of a byte array. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected final Configuration config
protected final List listeners
MatcherListener
s.
protected final TwoKeyMap hashtable
protected final byte[] buffer
protected int ndx
buffer
.
protected long count
Constructor Detail |
public MatcherStream(Configuration config)
config
- The current configuration.Method Detail |
public void addListener(MatcherListener listener)
MatcherListener
to the list of listeners.
listener
- The listener to add.public boolean removeListener(MatcherListener listener)
MatcherListener
from the list of listeners.
listener
- The listener to add.
public void setChecksums(List sums)
sums
- The checksums.public void reset()
public void update(byte b) throws ListenerException
b
- The next byte
ListenerException
public void update(byte[] buf, int off, int len) throws ListenerException
buf
- The next bytes.off
- The offset to begin at.len
- The number of bytes to update.
ListenerException
public void update(byte[] buf) throws ListenerException
buf
- The next bytes.
ListenerException
public void doFinal() throws ListenerException
ListenerException
protected Long hashSearch(byte[] block, int off, int len)
block
- The block of bytes to search for.off
- The offset in the block to begin.len
- The number of bytes to read from the block.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |