boolean result; if (_leasedIterator.isTerminated()) result = false; else {
/** * Same as {@link #next()} but with blocking behavior, blocking until a matched entity is * available or until timeout expires. * * @param timeout time to wait until a next element is available. * @return an entity from the iterated buffered set. * @throws NoSuchElementException when timeout expires and no available match was found. */ public Object next(long timeout) throws NoSuchElementException { Object nextEntry = next(); if (nextEntry != null) return nextEntry; //else try blocking next... synchronized (_lock) { if (!_leasedIterator.isTerminated()) { try { _lock.wait(timeout); } catch (InterruptedException e) { //fall through } } }//synchronized(lock) // either we found before timeout or we try at end of timeout nextEntry = next(); if (nextEntry == null) throw new NoSuchElementException(); //return result return nextEntry; }
/** * Used to renew the iterator's lease for an additional period of time, specified in * milliseconds. This duration is not added to the original lease, but is used to determine a * new expiration time for the existing lease. If the renewal is granted this is reflected in * value returned by getExpiration. If the renewal fails, the lease is left intact for the same * duration that was in force prior to the call to renew. <p> An expired iterator is an * <em>invalidated</em> iterator and will have no more entities added to it. Subsequent calls to * <code>next</code> on this iterator will always return <code>null</code>. * * @param duration the requested duration in milliseconds * @throws IllegalArgumentException if invalid lease expiration time * @throws LeaseDeniedException if the iterator's lease has already expired */ public void renew(long duration) throws IllegalArgumentException, LeaseDeniedException { if (_leasedIterator.isTerminated()) throw new LeaseDeniedException("Lease has already expired or been cancelled."); _leasedIterator.renew(duration); }
public void notify(RemoteEvent event) { synchronized (_lock) { if (_leasedIterator.isTerminated()) return; processEvent((EntryArrivedRemoteEvent) event); } }
public void notifyBatch(BatchRemoteEvent batchEvent) { synchronized (_lock) { if (_leasedIterator.isTerminated()) return; for (RemoteEvent event : batchEvent.getEvents()) processEvent((EntryArrivedRemoteEvent) event); } }