Search in sources :

Example 1 with EvictionStrategy

use of org.infinispan.eviction.EvictionStrategy in project kernel by exoplatform.

the class GenericExoCacheCreator method create.

/**
 * Creates a new ExoCache instance with the relevant parameters
 * @throws ExoCacheInitException If any exception occurs while creating the cache
 */
private ExoCache<Serializable, Object> create(ExoCacheConfig config, ConfigurationBuilder confBuilder, Callable<Cache<Serializable, Object>> cacheGetter, String strategy, int maxEntries, long lifespan, long maxIdle, long wakeUpInterval) throws ExoCacheInitException {
    EvictionStrategy es = strategy == null || strategy.length() == 0 ? null : EvictionStrategy.valueOf(strategy.toUpperCase(Locale.ENGLISH));
    if (es == null) {
        es = EvictionStrategy.LRU;
    }
    confBuilder.eviction().strategy(EvictionStrategy.valueOf(strategy)).maxEntries(maxEntries).expiration().lifespan(lifespan).maxIdle(maxIdle).wakeUpInterval(wakeUpInterval);
    try {
        return new GenericExoCache(config, cacheGetter.call());
    } catch (// NOSONAR
    Exception e) {
        throw new ExoCacheInitException("Cannot create the cache '" + config.getName() + "'", e);
    }
}
Also used : ExoCacheInitException(org.exoplatform.services.cache.ExoCacheInitException) ExoCacheInitException(org.exoplatform.services.cache.ExoCacheInitException) EvictionStrategy(org.infinispan.eviction.EvictionStrategy)

Example 2 with EvictionStrategy

use of org.infinispan.eviction.EvictionStrategy 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)

Example 3 with EvictionStrategy

use of org.infinispan.eviction.EvictionStrategy in project wildfly by wildfly.

the class InfinispanSessionManagerFactoryServiceConfigurator method accept.

@Override
public void accept(ConfigurationBuilder builder) {
    // Ensure expiration is not enabled on cache
    ExpirationConfiguration expiration = builder.expiration().create();
    if ((expiration.lifespan() >= 0) || (expiration.maxIdle() >= 0)) {
        builder.expiration().lifespan(-1).maxIdle(-1);
        InfinispanWebLogger.ROOT_LOGGER.expirationDisabled(InfinispanCacheRequirement.CONFIGURATION.resolve(this.configuration.getContainerName(), this.configuration.getCacheName()));
    }
    Integer size = this.factoryConfiguration.getMaxActiveSessions();
    EvictionStrategy strategy = (size != null) ? EvictionStrategy.REMOVE : EvictionStrategy.NONE;
    builder.memory().storage(StorageType.HEAP).whenFull(strategy).maxCount((size != null) ? size.longValue() : 0);
    if (strategy.isEnabled()) {
        // Only evict creation meta-data entries
        // We will cascade eviction to the remaining entries for a given session
        builder.addModule(DataContainerConfigurationBuilder.class).evictable(SessionCreationMetaDataKey.class::isInstance);
    }
}
Also used : DataContainerConfigurationBuilder(org.wildfly.clustering.infinispan.spi.DataContainerConfigurationBuilder) ExpirationConfiguration(org.infinispan.configuration.cache.ExpirationConfiguration) EvictionStrategy(org.infinispan.eviction.EvictionStrategy)

Example 4 with EvictionStrategy

use of org.infinispan.eviction.EvictionStrategy in project wildfly by wildfly.

the class InfinispanBeanManagerFactoryServiceConfiguratorFactory method getDeploymentServiceConfigurators.

@Override
public Iterable<CapabilityServiceConfigurator> getDeploymentServiceConfigurators(final ServiceName name) {
    String cacheName = getCacheName(name, this.name);
    String containerName = this.config.getContainerName();
    String templateCacheName = this.config.getCacheName();
    // Ensure eviction and expiration are disabled
    Consumer<ConfigurationBuilder> configurator = builder -> {
        // Ensure expiration is not enabled on cache
        ExpirationConfiguration expiration = builder.expiration().create();
        if ((expiration.lifespan() >= 0) || (expiration.maxIdle() >= 0)) {
            builder.expiration().lifespan(-1).maxIdle(-1);
            InfinispanEjbLogger.ROOT_LOGGER.expirationDisabled(InfinispanCacheRequirement.CONFIGURATION.resolve(containerName, templateCacheName));
        }
        int size = this.config.getMaxSize();
        EvictionStrategy strategy = (size > 0) ? EvictionStrategy.REMOVE : EvictionStrategy.MANUAL;
        builder.memory().storage(StorageType.HEAP).whenFull(strategy).maxCount(size);
        if (strategy.isEnabled()) {
            // Only evict bean group entries
            // We will cascade eviction to the associated beans
            builder.addModule(DataContainerConfigurationBuilder.class).evictable(BeanGroupKey.class::isInstance);
        }
    };
    CapabilityServiceConfigurator configurationConfigurator = new TemplateConfigurationServiceConfigurator(ServiceNameFactory.parseServiceName(InfinispanCacheRequirement.CONFIGURATION.getName()).append(containerName, cacheName), containerName, cacheName, templateCacheName, configurator);
    CapabilityServiceConfigurator cacheConfigurator = new CacheServiceConfigurator<>(ServiceNameFactory.parseServiceName(InfinispanCacheRequirement.CACHE.getName()).append(containerName, cacheName), containerName, cacheName).require(new ServiceDependency(name.append("marshalling")));
    List<Iterable<CapabilityServiceConfigurator>> configurators = new LinkedList<>();
    configurators.add(Arrays.asList(configurationConfigurator, cacheConfigurator));
    ServiceNameRegistry<ClusteringCacheRequirement> registry = new ServiceNameRegistry<ClusteringCacheRequirement>() {

        @Override
        public ServiceName getServiceName(ClusteringCacheRequirement requirement) {
            return (requirement == ClusteringCacheRequirement.GROUP) ? ServiceNameFactory.parseServiceName(requirement.getName()).append(containerName, cacheName) : null;
        }
    };
    for (CacheServiceConfiguratorProvider provider : ServiceLoader.load(DistributedCacheServiceConfiguratorProvider.class, DistributedCacheServiceConfiguratorProvider.class.getClassLoader())) {
        configurators.add(provider.getServiceConfigurators(registry, containerName, cacheName));
    }
    return new CompositeIterable<>(configurators);
}
Also used : Arrays(java.util.Arrays) Services(org.jboss.as.server.deployment.Services) CacheServiceConfigurator(org.wildfly.clustering.infinispan.spi.service.CacheServiceConfigurator) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) ExpirationConfiguration(org.infinispan.configuration.cache.ExpirationConfiguration) ServiceDependency(org.wildfly.clustering.service.ServiceDependency) ArrayList(java.util.ArrayList) BeanManagerFactoryServiceConfiguratorFactory(org.wildfly.clustering.ejb.BeanManagerFactoryServiceConfiguratorFactory) StatefulBeanConfiguration(org.wildfly.clustering.ejb.StatefulBeanConfiguration) BeanManagerFactoryServiceConfiguratorConfiguration(org.wildfly.clustering.ejb.BeanManagerFactoryServiceConfiguratorConfiguration) CompositeIterable(org.wildfly.clustering.ee.CompositeIterable) BeanManagerFactory(org.wildfly.clustering.ejb.BeanManagerFactory) LinkedList(java.util.LinkedList) ClusteringCacheRequirement(org.wildfly.clustering.spi.ClusteringCacheRequirement) StorageType(org.infinispan.configuration.cache.StorageType) TemplateConfigurationServiceConfigurator(org.wildfly.clustering.infinispan.spi.service.TemplateConfigurationServiceConfigurator) ServiceLoader(java.util.ServiceLoader) InfinispanEjbLogger(org.wildfly.clustering.ejb.infinispan.logging.InfinispanEjbLogger) DistributedCacheServiceConfiguratorProvider(org.wildfly.clustering.spi.DistributedCacheServiceConfiguratorProvider) CacheServiceConfiguratorProvider(org.wildfly.clustering.spi.CacheServiceConfiguratorProvider) Consumer(java.util.function.Consumer) EvictionStrategy(org.infinispan.eviction.EvictionStrategy) ServiceNameRegistry(org.wildfly.clustering.service.ServiceNameRegistry) List(java.util.List) ServiceNameFactory(org.jboss.as.controller.ServiceNameFactory) ServiceName(org.jboss.msc.service.ServiceName) InfinispanCacheRequirement(org.wildfly.clustering.infinispan.spi.InfinispanCacheRequirement) DataContainerConfigurationBuilder(org.wildfly.clustering.infinispan.spi.DataContainerConfigurationBuilder) CapabilityServiceConfigurator(org.jboss.as.clustering.controller.CapabilityServiceConfigurator) DistributedCacheServiceConfiguratorProvider(org.wildfly.clustering.spi.DistributedCacheServiceConfiguratorProvider) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) DataContainerConfigurationBuilder(org.wildfly.clustering.infinispan.spi.DataContainerConfigurationBuilder) DistributedCacheServiceConfiguratorProvider(org.wildfly.clustering.spi.DistributedCacheServiceConfiguratorProvider) CacheServiceConfiguratorProvider(org.wildfly.clustering.spi.CacheServiceConfiguratorProvider) CapabilityServiceConfigurator(org.jboss.as.clustering.controller.CapabilityServiceConfigurator) CompositeIterable(org.wildfly.clustering.ee.CompositeIterable) ExpirationConfiguration(org.infinispan.configuration.cache.ExpirationConfiguration) CompositeIterable(org.wildfly.clustering.ee.CompositeIterable) ClusteringCacheRequirement(org.wildfly.clustering.spi.ClusteringCacheRequirement) LinkedList(java.util.LinkedList) TemplateConfigurationServiceConfigurator(org.wildfly.clustering.infinispan.spi.service.TemplateConfigurationServiceConfigurator) ServiceNameRegistry(org.wildfly.clustering.service.ServiceNameRegistry) ServiceDependency(org.wildfly.clustering.service.ServiceDependency) EvictionStrategy(org.infinispan.eviction.EvictionStrategy)

Example 5 with EvictionStrategy

use of org.infinispan.eviction.EvictionStrategy in project wildfly by wildfly.

the class MemoryServiceConfigurator method get.

@Override
public MemoryConfiguration get() {
    EvictionStrategy strategy = this.size > 0 ? EvictionStrategy.REMOVE : EvictionStrategy.MANUAL;
    MemoryConfigurationBuilder builder = new ConfigurationBuilder().memory().storage(this.storageType).whenFull(strategy);
    if (strategy.isEnabled()) {
        if (this.unit == MemorySizeUnit.ENTRIES) {
            builder.maxCount(this.size);
        } else {
            builder.maxSize(Long.toString(this.unit.applyAsLong(this.size)));
        }
    }
    return builder.create();
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) MemoryConfigurationBuilder(org.infinispan.configuration.cache.MemoryConfigurationBuilder) MemoryConfigurationBuilder(org.infinispan.configuration.cache.MemoryConfigurationBuilder) EvictionStrategy(org.infinispan.eviction.EvictionStrategy)

Aggregations

EvictionStrategy (org.infinispan.eviction.EvictionStrategy)5 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)2 ExpirationConfiguration (org.infinispan.configuration.cache.ExpirationConfiguration)2 DataContainerConfigurationBuilder (org.wildfly.clustering.infinispan.spi.DataContainerConfigurationBuilder)2 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 ServiceLoader (java.util.ServiceLoader)1 Consumer (java.util.function.Consumer)1 ExoCacheInitException (org.exoplatform.services.cache.ExoCacheInitException)1 MemoryConfiguration (org.infinispan.configuration.cache.MemoryConfiguration)1 MemoryConfigurationBuilder (org.infinispan.configuration.cache.MemoryConfigurationBuilder)1 StorageType (org.infinispan.configuration.cache.StorageType)1 CapabilityServiceConfigurator (org.jboss.as.clustering.controller.CapabilityServiceConfigurator)1 ServiceNameFactory (org.jboss.as.controller.ServiceNameFactory)1 Services (org.jboss.as.server.deployment.Services)1 ServiceName (org.jboss.msc.service.ServiceName)1 CompositeIterable (org.wildfly.clustering.ee.CompositeIterable)1 BeanManagerFactory (org.wildfly.clustering.ejb.BeanManagerFactory)1