public void waitForState(final String collection,long wait,TimeUnit unit,CollectionStatePredicate predicate) throws InterruptedException, TimeoutException {
  final CountDownLatch latch=new CountDownLatch(1);
  CollectionStateWatcher watcher=null;
  registerCollectionStateWatcher(collection,watcher);
  try {
    if (!latch.await(wait,unit))     throw new TimeoutException();
  }
  finally {
    removeCollectionStateWatcher(collection,watcher);
  }
}

public void waitForState ( final String collection , long wait , TimeUnit unit , CollectionStatePredicate predicate ) throws InterruptedException , TimeoutException { final CountDownLatch latch = new CountDownLatch ( 1 ) ; CollectionStateWatcher watcher = null ; registerCollectionStateWatcher ( collection , watcher ) ; try { if ( ! latch . await ( wait , unit ) ) throw new TimeoutException ( ) ; } finally { removeCollectionStateWatcher ( collection , watcher ) ; } }
block until a collectionstatepredicate returns true , or the wait times out note that the predicate may be called again even after it has returned true , so implementors should avoid changing state within the predicate call itself .
