public class ClosableConcurrentHashEntryIterator<E extends Entry> extends Object implements ClosableIterator<E>
The hash has a usage/reference counter for iterations to suspend expand until the iteration finished. This is needed for correctness of the iteration, if an expand is done during the iteration process, the iterations returns duplicate entries or not all entries.
Failing to operate the increment/decrement in balance will mean that the hash table expands are blocked forever, which is a serious error condition. Typical problems arise by thrown exceptions during an iteration. Since there is a measure for the hash quality, a problem like this may be detected.
Rationale: We need to keep track of the entries/keys iterated. The cache may remove and insert entries from hash to refreshHash, also the application may do a remove and insert. A removed entry has always e.another kept intact, so traversal of the collision list will always work. If a iteration is going on, this means a removed entry needs to be cloned to reassign the e.another pointer.
Rationale: The iteration just works on the hash data structure. However, it needs to be checked, whether the cache is closed meanwhile. To signal this, the hash is closed also. This is a little complex, but safes the dependency on the cache here.
| Constructor and Description |
|---|
ClosableConcurrentHashEntryIterator(Hash<E> _hashCtl,
E[] _hash,
Hash<E> _hashCtl2,
E[] _hash2) |
| Modifier and Type | Method and Description |
|---|---|
protected boolean |
checkForClearAndAbort()
Check if hash was cleared and we need to abort.
|
protected E |
checkIteratedOrNext(E e) |
void |
close() |
protected void |
finalize() |
boolean |
hasNext() |
E |
next() |
void |
remove() |
void |
setKeepIterated(boolean keepIterated)
Keep hash of iterated items, needed for storage iteration.
|
void |
setStopOnClear(boolean stopOnClear)
Iterations stops when storage is cleared, default is true.
|
protected boolean |
switchAndCheckAbort() |
protected E checkIteratedOrNext(E e)
protected boolean switchAndCheckAbort()
protected boolean checkForClearAndAbort()
public void close()
close in interface Closeableclose in interface AutoCloseableclose in interface ClosableIterator<E extends Entry>public void setKeepIterated(boolean keepIterated)
public void setStopOnClear(boolean stopOnClear)
cache2k API documentation. Copyright © 2000–2015 headissue GmbH, Munich.