Search in sources :

Example 1 with MemoryConfiguration

use of org.infinispan.configuration.cache.MemoryConfiguration in project wildfly by wildfly.

the class DataContainerFactory method createBoundedDataContainer.

@SuppressWarnings("deprecation")
private DataContainer<?, ?> createBoundedDataContainer() {
    ClusteringConfiguration clustering = this.configuration.clustering();
    boolean segmented = clustering.cacheMode().needsStateTransfer();
    int level = this.configuration.locking().concurrencyLevel();
    MemoryConfiguration memory = this.configuration.memory();
    boolean offHeap = memory.isOffHeap();
    long maxEntries = memory.maxCount();
    long maxBytes = memory.maxSizeBytes();
    org.infinispan.eviction.EvictionType type = memory.evictionType();
    DataContainerConfiguration config = this.configuration.module(DataContainerConfiguration.class);
    Predicate<?> evictable = (config != null) ? config.evictable() : DataContainerConfiguration.EVICTABLE_PREDICATE.getDefaultValue();
    if (segmented) {
        int segments = clustering.hash().numSegments();
        if (offHeap) {
            return new SegmentedBoundedOffHeapDataContainer(segments, maxEntries, type);
        }
        return (maxEntries > 0) ? new BoundedSegmentedDataContainer<>(segments, maxEntries, new EvictableEntrySizeCalculator<>(evictable)) : new BoundedSegmentedDataContainer<>(segments, maxBytes, type);
    }
    if (offHeap) {
        return new BoundedOffHeapDataContainer(maxEntries, type);
    }
    return (maxEntries > 0) ? new EvictableDataContainer<>(maxEntries, new EvictableEntrySizeCalculator<>(evictable)) : DefaultDataContainer.boundedDataContainer(level, maxBytes, type);
}
Also used : SegmentedBoundedOffHeapDataContainer(org.infinispan.container.offheap.SegmentedBoundedOffHeapDataContainer) BoundedOffHeapDataContainer(org.infinispan.container.offheap.BoundedOffHeapDataContainer) MemoryConfiguration(org.infinispan.configuration.cache.MemoryConfiguration) ClusteringConfiguration(org.infinispan.configuration.cache.ClusteringConfiguration) SegmentedBoundedOffHeapDataContainer(org.infinispan.container.offheap.SegmentedBoundedOffHeapDataContainer)

Example 2 with MemoryConfiguration

use of org.infinispan.configuration.cache.MemoryConfiguration in project wildfly by wildfly.

the class DataContainerFactory method construct.

@Override
public Object construct(String componentName) {
    MemoryConfiguration memory = this.configuration.memory();
    EvictionStrategy strategy = memory.whenFull();
    // handle case when < 0 value signifies unbounded container or when we are not removal based
    if (strategy.isExceptionBased() || !strategy.isEnabled()) {
        return this.createUnboundedContainer();
    }
    DataContainer<?, ?> container = this.createBoundedDataContainer();
    memory.attributes().attribute(MemoryConfiguration.MAX_COUNT).addListener((newSize, oldSize) -> container.resize(newSize.get()));
    return container;
}
Also used : MemoryConfiguration(org.infinispan.configuration.cache.MemoryConfiguration) EvictionStrategy(org.infinispan.eviction.EvictionStrategy)

Aggregations

MemoryConfiguration (org.infinispan.configuration.cache.MemoryConfiguration)2 ClusteringConfiguration (org.infinispan.configuration.cache.ClusteringConfiguration)1 BoundedOffHeapDataContainer (org.infinispan.container.offheap.BoundedOffHeapDataContainer)1 SegmentedBoundedOffHeapDataContainer (org.infinispan.container.offheap.SegmentedBoundedOffHeapDataContainer)1 EvictionStrategy (org.infinispan.eviction.EvictionStrategy)1