com.hazelcast.cache.impl
Class AbstractClusterWideIterator<K,V>
java.lang.Object
com.hazelcast.cache.impl.AbstractClusterWideIterator<K,V>
- Type Parameters:
K
- the type of key.V
- the type of value.
- All Implemented Interfaces:
- Iterator<javax.cache.Cache.Entry<K,V>>
- Direct Known Subclasses:
- ClientClusterWideIterator, ClusterWideIterator
public abstract class AbstractClusterWideIterator<K,V>
- extends Object
- implements Iterator<javax.cache.Cache.Entry<K,V>>
AbstractClusterWideIterator
provides the core iterator functionality shared by its descendants.
Hazelcast cluster is made of partitions which holds a slice of all clusters data. Partition count
never increase or decrease in a cluster. In order to implement an iterator over a partitioned data, we use
the following parameters.
- To iterate over partitioned data, we use partitionId as the first parameter of this iterator.
- Each partition may have a lot of entries, so we use a second parameter to track the iteration of the
partition.
Iteration steps:
- fetching fixed sized of keys from the current partition defined by partitionId.
- iteration on fetched keys.
- get value of each key with
next()
when method is called.
- when fetched keys are all used by calling
next()
, more keys are fetched from the cluster.
This implementation iterates over partitions and for each partition it iterates over the internal map using the
internal table index of the map CacheConcurrentHashMap
.
Fetching data from cluster:
Fetching is getting a fixed size of keys from the internal table of records of a partition defined by
partitionId. Table index is also provided as a table index locator. Fetch response is the keys and
last table index. The last table index is included in the result to be used in the next fetch.
Notes:
- Iterator fetches keys in batch with a fixed size that is configurable.
- Fetched keys are cached in the iterator to be used in each iteration step.
hasNext()
may return true for a key already removed.
hasNext()
only return false when all known keys are fetched and iterated.
next()
may return null although cache never has null value. This may happen when, for example,
someone removes the entry after the current thread has checked with hasNext()
.
- This implementation does not affected by value updates as each value is got from the cluster
when
next()
called.
- See Also:
AbstractCacheRecordStore.iterator(int tableIndex, int size)
,
ClusterWideIterator
,
CacheKeyIteratorResult
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
cache
protected ICache<K,V> cache
result
protected CacheKeyIteratorResult result
partitionCount
protected final int partitionCount
partitionIndex
protected int partitionIndex
lastTableIndex
protected int lastTableIndex
fetchSize
protected final int fetchSize
index
protected int index
currentIndex
protected int currentIndex
AbstractClusterWideIterator
public AbstractClusterWideIterator(ICache<K,V> cache,
int partitionCount)
hasNext
public boolean hasNext()
- Specified by:
hasNext
in interface Iterator<javax.cache.Cache.Entry<K,V>>
next
public javax.cache.Cache.Entry<K,V> next()
- Specified by:
next
in interface Iterator<javax.cache.Cache.Entry<K,V>>
remove
public void remove()
- Specified by:
remove
in interface Iterator<javax.cache.Cache.Entry<K,V>>
advance
protected boolean advance()
ensureOpen
protected void ensureOpen()
getPartitionCount
protected int getPartitionCount()
fetch
protected abstract CacheKeyIteratorResult fetch()
toData
protected abstract Data toData(Object obj)
toObject
protected abstract <T> T toObject(Object data)
Copyright © 2015 Hazelcast, Inc.. All Rights Reserved.