* @param timeInMillis the max amount of time to wait in milliseconds.
* @param version the version of events which it waits for.
* @throws ZoieException
*/
public void syncWithVersion(long timeInMillis, String version) throws ZoieException {
if (_consumerThread == null) throw new ZoieException("not running");
if (version == null) {
log.info("buffered version is NULL. Nothing to flush.");
return;
}
synchronized (this) {
long timeRemaining = Long.MAX_VALUE;
while (_currentVersion == null || _versionComparator.compare(_currentVersion, version) < 0) {
if (log.isDebugEnabled()) {
if (timeRemaining > timeInMillis + 5000) log.debug("syncWithVersion: timeRemaining: "
+ timeInMillis + "ms current: " + _currentVersion + " expecting: " + version);
timeRemaining = timeInMillis;
}
this.notifyAll();
long now1 = System.currentTimeMillis();
if (timeInMillis <= 0) {
throw new ZoieException("sync timed out at current: " + _currentVersion + " expecting: "
+ version);
}
try {
long waitTime = Math.min(5000, timeInMillis);
this.wait(waitTime);