Package org.infinispan.container.impl
Class DefaultDataContainer<K,V>
- java.lang.Object
-
- org.infinispan.container.impl.AbstractInternalDataContainer<K,V>
-
- org.infinispan.container.impl.DefaultDataContainer<K,V>
-
- All Implemented Interfaces:
Iterable<InternalCacheEntry<K,V>>
,DataContainer<K,V>
,InternalDataContainer<K,V>
@ThreadSafe public class DefaultDataContainer<K,V> extends AbstractInternalDataContainer<K,V>
DefaultDataContainer is both eviction and non-eviction based data container.- Since:
- 4.0
- Author:
- Manik Surtani, Galder ZamarreƱo, Vladimir Blagojevic, Trustin Lee
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.infinispan.container.impl.AbstractInternalDataContainer
AbstractInternalDataContainer.EntryIterator, AbstractInternalDataContainer.Values
-
Nested classes/interfaces inherited from interface org.infinispan.container.DataContainer
DataContainer.ComputeAction<K,V>
-
-
Field Summary
-
Fields inherited from class org.infinispan.container.impl.AbstractInternalDataContainer
activator, configuration, entryFactory, evictionManager, expirationManager, keyPartitioner, listeners, passivator, timeService
-
-
Constructor Summary
Constructors Modifier Constructor Description DefaultDataContainer(int concurrencyLevel)
protected
DefaultDataContainer(int concurrencyLevel, long thresholdSize, org.infinispan.commons.util.EntrySizeCalculator<? super K,? super V> sizeCalculator)
Method invoked when memory policy is used.protected
DefaultDataContainer(int concurrencyLevel, long thresholdSize, EvictionType thresholdPolicy)
protected
DefaultDataContainer(long thresholdSize, org.infinispan.commons.util.EntrySizeCalculator<? super K,? super InternalCacheEntry<K,V>> sizeCalculator)
Constructor that allows user to provide a size calculator that also handles the cache entry and metadata.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addSegments(org.infinispan.commons.util.IntSet segments)
Sets what segments this data container should be using.static <K,V>
DefaultDataContainer<K,V>boundedDataContainer(int concurrencyLevel, long maxEntries, org.infinispan.commons.util.EntrySizeCalculator<? super K,? super V> sizeCalculator)
static <K,V>
DefaultDataContainer<K,V>boundedDataContainer(int concurrencyLevel, long maxEntries, EvictionType thresholdPolicy)
long
capacity()
Returns the capacity of the underlying container.void
clear()
Removes all entries in the containervoid
clear(org.infinispan.commons.util.IntSet segments)
Removes entries from the container whose key maps to one of the provided segmentslong
evictionSize()
Returns how large the eviction size is currently.void
executeTask(KeyFilter<? super K> filter, BiConsumer<? super K,InternalCacheEntry<K,V>> action)
Executes task specified by the given action on the container key/values filtered using the specified key filter.void
executeTask(KeyValueFilter<? super K,? super V> filter, BiConsumer<? super K,InternalCacheEntry<K,V>> action)
Executes task specified by the given action on the container key/values filtered using the specified keyvalue filter.protected PeekableTouchableMap<K,InternalCacheEntry<K,V>>
getMapForSegment(int segment)
protected int
getSegmentForKey(Object key)
Iterator<InternalCacheEntry<K,V>>
iterator()
Iterator<InternalCacheEntry<K,V>>
iterator(org.infinispan.commons.util.IntSet segments)
Same asDataContainer.iterator()
except that only entries that map to the provided segments are returned via the iterator.Iterator<InternalCacheEntry<K,V>>
iteratorIncludingExpired()
Same asDataContainer.iterator()
except that is also returns expired entries.Iterator<InternalCacheEntry<K,V>>
iteratorIncludingExpired(org.infinispan.commons.util.IntSet segments)
Same asDataContainer.iteratorIncludingExpired()
except that only entries that map to the provided segments are returned via the iterator.Set<K>
keySet()
Returns a set of keys in the container.void
removeSegments(org.infinispan.commons.util.IntSet segments)
Removes and un-associates the given segments.void
resize(long newSize)
Resizes the capacity of the underlying container.int
sizeIncludingExpired()
Spliterator<InternalCacheEntry<K,V>>
spliterator()
Spliterator<InternalCacheEntry<K,V>>
spliterator(org.infinispan.commons.util.IntSet segments)
Same asDataContainer.spliterator()
except that only entries that map to the provided segments are returned via this spliterator.Spliterator<InternalCacheEntry<K,V>>
spliteratorIncludingExpired()
Same asDataContainer.spliterator()
except that is also returns expired entries.Spliterator<InternalCacheEntry<K,V>>
spliteratorIncludingExpired(org.infinispan.commons.util.IntSet segments)
Same asDataContainer.spliteratorIncludingExpired()
except that only entries that map to the provided segments are returned via this spliterator.static <K,V>
DefaultDataContainer<K,V>unBoundedDataContainer(int concurrencyLevel)
-
Methods inherited from class org.infinispan.container.impl.AbstractInternalDataContainer
addRemovalListener, applyListener, compute, compute, computeEntryRemoved, computeEntryWritten, containsKey, containsKey, entrySet, evict, evict, expiredIterationPredicate, filterExpiredEntries, get, get, peek, peek, put, put, remove, remove, removeRemovalListener, touch, values
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.infinispan.container.DataContainer
size
-
Methods inherited from interface org.infinispan.container.impl.InternalDataContainer
forEach, size, sizeIncludingExpired
-
-
-
-
Constructor Detail
-
DefaultDataContainer
public DefaultDataContainer(int concurrencyLevel)
-
DefaultDataContainer
protected DefaultDataContainer(int concurrencyLevel, long thresholdSize, EvictionType thresholdPolicy)
-
DefaultDataContainer
protected DefaultDataContainer(int concurrencyLevel, long thresholdSize, org.infinispan.commons.util.EntrySizeCalculator<? super K,? super V> sizeCalculator)
Method invoked when memory policy is used. This calculator only calculates the given key and value.- Parameters:
concurrencyLevel
-thresholdSize
-sizeCalculator
-
-
DefaultDataContainer
protected DefaultDataContainer(long thresholdSize, org.infinispan.commons.util.EntrySizeCalculator<? super K,? super InternalCacheEntry<K,V>> sizeCalculator)
Constructor that allows user to provide a size calculator that also handles the cache entry and metadata.- Parameters:
thresholdSize
-sizeCalculator
-
-
-
Method Detail
-
boundedDataContainer
public static <K,V> DefaultDataContainer<K,V> boundedDataContainer(int concurrencyLevel, long maxEntries, EvictionType thresholdPolicy)
-
boundedDataContainer
public static <K,V> DefaultDataContainer<K,V> boundedDataContainer(int concurrencyLevel, long maxEntries, org.infinispan.commons.util.EntrySizeCalculator<? super K,? super V> sizeCalculator)
-
unBoundedDataContainer
public static <K,V> DefaultDataContainer<K,V> unBoundedDataContainer(int concurrencyLevel)
-
getMapForSegment
protected PeekableTouchableMap<K,InternalCacheEntry<K,V>> getMapForSegment(int segment)
- Specified by:
getMapForSegment
in classAbstractInternalDataContainer<K,V>
-
getSegmentForKey
protected int getSegmentForKey(Object key)
- Specified by:
getSegmentForKey
in classAbstractInternalDataContainer<K,V>
-
capacity
public long capacity()
Description copied from interface:DataContainer
Returns the capacity of the underlying container. This is only supported if the container is bounded. AnUnsupportedOperationException
is thrown otherwise.- Returns:
-
resize
public void resize(long newSize)
Description copied from interface:DataContainer
Resizes the capacity of the underlying container. This is only supported if the container is bounded. AnUnsupportedOperationException
is thrown otherwise.- Parameters:
newSize
- the new size
-
sizeIncludingExpired
public int sizeIncludingExpired()
- Returns:
- count of the number of entries in the container including expired entries
-
clear
public void clear(org.infinispan.commons.util.IntSet segments)
Description copied from interface:InternalDataContainer
Removes entries from the container whose key maps to one of the provided segments- Specified by:
clear
in interfaceInternalDataContainer<K,V>
- Overrides:
clear
in classAbstractInternalDataContainer<K,V>
- Parameters:
segments
- segments of entries to remove
-
clear
public void clear()
Description copied from interface:DataContainer
Removes all entries in the container
-
keySet
public Set<K> keySet()
Description copied from interface:DataContainer
Returns a set of keys in the container. When iterating through the container using this method, clients should never callDataContainer.get(Object)
method but insteadDataContainer.peek(Object)
, in order to avoid changing the order of the underlying collection as a side of effect of iterating through it.This set of keys will include expired entries. If you wish to only retrieve non expired keys please use the
DataContainer.iterator()
method and retrieve keys from there.- Specified by:
keySet
in interfaceDataContainer<K,V>
- Overrides:
keySet
in classAbstractInternalDataContainer<K,V>
- Returns:
- a set of keys
-
iterator
public Iterator<InternalCacheEntry<K,V>> iterator()
Description copied from interface:DataContainer
This iterator only returns entries that are not expired, however it will not remove them while doing so.
- Returns:
- iterator that doesn't produce expired entries
-
iterator
public Iterator<InternalCacheEntry<K,V>> iterator(org.infinispan.commons.util.IntSet segments)
Description copied from interface:InternalDataContainer
Same asDataContainer.iterator()
except that only entries that map to the provided segments are returned via the iterator. The iterator will not return expired entries.- Parameters:
segments
- segments of entries to use- Returns:
- iterator that returns all entries mapped to the given segments
-
spliterator
public Spliterator<InternalCacheEntry<K,V>> spliterator()
Description copied from interface:DataContainer
This spliterator only returns entries that are not expired, however it will not remove them while doing so.
- Returns:
- spliterator that doesn't produce expired entries
-
spliterator
public Spliterator<InternalCacheEntry<K,V>> spliterator(org.infinispan.commons.util.IntSet segments)
Description copied from interface:InternalDataContainer
Same asDataContainer.spliterator()
except that only entries that map to the provided segments are returned via this spliterator. The spliterator will not return expired entries.- Parameters:
segments
- segments of entries to return- Returns:
- spliterator containing entries mapping to those segments that aren't expired
-
spliteratorIncludingExpired
public Spliterator<InternalCacheEntry<K,V>> spliteratorIncludingExpired()
Description copied from interface:DataContainer
Same asDataContainer.spliterator()
except that is also returns expired entries.- Returns:
- spliterator that returns all entries including expired ones
-
spliteratorIncludingExpired
public Spliterator<InternalCacheEntry<K,V>> spliteratorIncludingExpired(org.infinispan.commons.util.IntSet segments)
Description copied from interface:InternalDataContainer
Same asDataContainer.spliteratorIncludingExpired()
except that only entries that map to the provided segments are returned via this spliterator. The spliterator will return expired entries as well.- Parameters:
segments
- segments of entries to use- Returns:
- spliterator containing entries mapping to those segments that could be expired
-
iteratorIncludingExpired
public Iterator<InternalCacheEntry<K,V>> iteratorIncludingExpired()
Description copied from interface:DataContainer
Same asDataContainer.iterator()
except that is also returns expired entries.- Returns:
- iterator that returns all entries including expired ones
-
iteratorIncludingExpired
public Iterator<InternalCacheEntry<K,V>> iteratorIncludingExpired(org.infinispan.commons.util.IntSet segments)
Description copied from interface:InternalDataContainer
Same asDataContainer.iteratorIncludingExpired()
except that only entries that map to the provided segments are returned via the iterator. The iterator can return expired entries.- Parameters:
segments
- segments of entries to use- Returns:
- iterator that returns all entries mapped to the given segments that could be expired
-
evictionSize
public long evictionSize()
Description copied from interface:DataContainer
Returns how large the eviction size is currently. This is only supported if the container is bounded. AnUnsupportedOperationException
is thrown otherwise. This value will always be lower than the value returned fromDataContainer.capacity()
- Returns:
- how large the counted eviction is
-
addSegments
public void addSegments(org.infinispan.commons.util.IntSet segments)
Description copied from interface:InternalDataContainer
Sets what segments this data container should be using. Already associated segments are unaffected by this and takes a union of existing and new segments.- Parameters:
segments
- segments to associate with this container
-
removeSegments
public void removeSegments(org.infinispan.commons.util.IntSet segments)
Description copied from interface:InternalDataContainer
Removes and un-associates the given segments. This will notify any listeners registered viaInternalDataContainer.addRemovalListener(Consumer)
of entries that were removed due to no longer being associated with this container. There is no guarantee if the consumer is invoked once or multiple times for a given group of segments and could be in any order.When this method is invoked an implementation is free to remove any entries that don't map to segments currently associated with this container. Note that entries that were removed due to their segments never being associated with this container do not notify listeners registered via
InternalDataContainer.addRemovalListener(Consumer)
.- Parameters:
segments
- segments that should no longer be associated with this container
-
executeTask
public void executeTask(KeyFilter<? super K> filter, BiConsumer<? super K,InternalCacheEntry<K,V>> action) throws InterruptedException
Description copied from interface:DataContainer
Executes task specified by the given action on the container key/values filtered using the specified key filter.- Parameters:
filter
- the filter for the container keysaction
- the specified action to execute on filtered key/values- Throws:
InterruptedException
-
executeTask
public void executeTask(KeyValueFilter<? super K,? super V> filter, BiConsumer<? super K,InternalCacheEntry<K,V>> action) throws InterruptedException
Description copied from interface:DataContainer
Executes task specified by the given action on the container key/values filtered using the specified keyvalue filter.- Parameters:
filter
- the filter for the container key/valuesaction
- the specified action to execute on filtered key/values- Throws:
InterruptedException
-
-