Search in sources :

Example 46 with ConfigurationBuilder

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

the class ClusteredCacheBuilder method configure.

@Override
public Builder<Configuration> configure(OperationContext context, ModelNode model) throws OperationFailedException {
    Mode mode = ModelNodes.asEnum(MODE.resolveModelAttribute(context, model), Mode.class);
    ClusteringConfigurationBuilder builder = new ConfigurationBuilder().clustering().cacheMode(mode.apply(this.mode));
    if (mode.isSynchronous()) {
        builder.sync().replTimeout(REMOTE_TIMEOUT.resolveModelAttribute(context, model).asLong());
    } else {
        builder.async();
    }
    this.clustering = builder.create();
    return super.configure(context, model);
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) ClusteringConfigurationBuilder(org.infinispan.configuration.cache.ClusteringConfigurationBuilder) ClusteringConfigurationBuilder(org.infinispan.configuration.cache.ClusteringConfigurationBuilder) CacheMode(org.infinispan.configuration.cache.CacheMode)

Example 47 with ConfigurationBuilder

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

the class DistributedCacheBuilder method configure.

@Override
public Builder<Configuration> configure(OperationContext context, ModelNode model) throws OperationFailedException {
    this.consistentHashStrategy = ModelNodes.asEnum(CONSISTENT_HASH_STRATEGY.resolveModelAttribute(context, model), ConsistentHashStrategy.class);
    ClusteringConfigurationBuilder builder = new ConfigurationBuilder().clustering();
    this.hash = builder.hash().capacityFactor(CAPACITY_FACTOR.resolveModelAttribute(context, model).asInt()).numOwners(OWNERS.resolveModelAttribute(context, model).asInt()).numSegments(SEGMENTS.resolveModelAttribute(context, model).asInt()).create();
    long l1Lifespan = L1_LIFESPAN.resolveModelAttribute(context, model).asLong();
    this.l1 = builder.l1().enabled(l1Lifespan > 0).lifespan(l1Lifespan).create();
    this.global = new InjectedValueDependency<>(InfinispanRequirement.CONFIGURATION.getServiceName(context, this.containerName), GlobalConfiguration.class);
    return super.configure(context, model);
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) HashConfigurationBuilder(org.infinispan.configuration.cache.HashConfigurationBuilder) ClusteringConfigurationBuilder(org.infinispan.configuration.cache.ClusteringConfigurationBuilder) ClusteringConfigurationBuilder(org.infinispan.configuration.cache.ClusteringConfigurationBuilder) GlobalConfiguration(org.infinispan.configuration.global.GlobalConfiguration)

Example 48 with ConfigurationBuilder

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

the class BackupsBuilder method getValue.

@Override
public SitesConfiguration getValue() {
    SitesConfigurationBuilder builder = new ConfigurationBuilder().sites();
    builder.backupFor().read(this.backupFor.getValue());
    builder.disableBackups(this.backups.isEmpty());
    for (Map.Entry<String, BackupConfiguration> backup : this.backups.entrySet()) {
        builder.addBackup().read(backup.getValue());
        builder.addInUseBackupSite(backup.getKey());
    }
    return builder.create();
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) SitesConfigurationBuilder(org.infinispan.configuration.cache.SitesConfigurationBuilder) BackupConfigurationBuilder(org.infinispan.configuration.cache.BackupConfigurationBuilder) SitesConfigurationBuilder(org.infinispan.configuration.cache.SitesConfigurationBuilder) BackupConfiguration(org.infinispan.configuration.cache.BackupConfiguration) HashMap(java.util.HashMap) Map(java.util.Map)

Example 49 with ConfigurationBuilder

use of org.infinispan.configuration.cache.ConfigurationBuilder in project OpenOLAT by OpenOLAT.

the class InfinispanCacher method createInfinispanConfiguration.

private void createInfinispanConfiguration(String cacheName) {
    Configuration conf = cacheManager.getCacheConfiguration(cacheName);
    if (conf == null) {
        long maxEntries = 10000;
        long maxIdle = 900000l;
        ConfigurationBuilder builder = new ConfigurationBuilder();
        builder.eviction().strategy(EvictionStrategy.LRU);
        builder.eviction().type(EvictionType.COUNT).size(maxEntries);
        builder.expiration().maxIdle(maxIdle);
        builder.transaction().transactionMode(TransactionMode.NON_TRANSACTIONAL);
        builder.dataContainer().storeAsBinary().storeValuesAsBinary(false);
        builder.locking().concurrencyLevel(1000);
        builder.locking().useLockStriping(false);
        builder.locking().lockAcquisitionTimeout(15000);
        builder.locking().isolationLevel(IsolationLevel.READ_COMMITTED);
        builder.jmxStatistics().enable();
        Configuration configurationOverride = builder.build();
        cacheManager.defineConfiguration(cacheName, configurationOverride);
    }
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) Configuration(org.infinispan.configuration.cache.Configuration)

Example 50 with ConfigurationBuilder

use of org.infinispan.configuration.cache.ConfigurationBuilder in project kernel by exoplatform.

the class ExoCacheFactoryImpl method createCache.

/**
 * To create a new cache instance according to the given configuration, we follow the steps below:
 *
 * We first try to find if a specific location of the cache configuration has been defined thanks
 * to an external component plugin of type ExoCacheFactoryConfigPlugin. If so we use the default cache
 * configuration defined in this file otherwise we use the default cache configuration defined in
 * "${CACHE_CONFIG_TEMPLATE_KEY}"
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
public ExoCache<Serializable, Object> createCache(final ExoCacheConfig config) throws ExoCacheInitException {
    final String region = config.getName();
    final String customConfig = mappingCacheNameConfig.get(region);
    final ExoCache<Serializable, Object> eXoCache;
    final DefaultCacheManager cacheManager;
    try {
        final ConfigurationBuilder confBuilder = new ConfigurationBuilder();
        if (customConfig != null) {
            try {
                cacheManager = SecurityHelper.doPrivilegedExceptionAction(new PrivilegedExceptionAction<DefaultCacheManager>() {

                    public DefaultCacheManager run() throws Exception {
                        // A custom configuration has been set
                        if (LOG.isInfoEnabled())
                            LOG.info("A custom configuration has been set for the cache '" + region + "'.");
                        ParserRegistry parser = new ParserRegistry(Thread.currentThread().getContextClassLoader());
                        // Load the configuration
                        ConfigurationBuilderHolder holder = parser.parse(configManager.getInputStream(customConfig));
                        GlobalConfigurationBuilder configBuilder = holder.getGlobalConfigurationBuilder();
                        // Configure JGroups and JMX since it could affect the state of the Global Config
                        configureCacheManager(configBuilder);
                        GlobalConfiguration gc = configBuilder.build();
                        // Check if a CacheManager with the same GlobalConfiguration exists
                        DefaultCacheManager currentCacheManager = mappingGlobalConfigCacheManager.get(gc.transport().clusterName());
                        if (currentCacheManager == null) {
                            // Use a different cache manager name to prevent naming conflict
                            configBuilder.globalJmxStatistics().cacheManagerName(gc.globalJmxStatistics().cacheManagerName() + "_" + region + "_" + ctx.getName());
                            // No cache manager has been defined so far for this Cache Configuration
                            currentCacheManager = new DefaultCacheManager(configBuilder.build(), holder.getDefaultConfigurationBuilder().build(), false);
                            for (Entry<String, ConfigurationBuilder> entry : holder.getNamedConfigurationBuilders().entrySet()) {
                                currentCacheManager.defineConfiguration(entry.getKey(), entry.getValue().build());
                            }
                            currentCacheManager.start();
                            // We register this new cache manager
                            mappingGlobalConfigCacheManager.put(gc.transport().clusterName(), currentCacheManager);
                        }
                        return currentCacheManager;
                    }
                });
            } catch (PrivilegedActionException e) {
                Throwable cause = e.getCause();
                if (cause instanceof Exception) {
                    // NOSONAR
                    throw (Exception) cause;
                } else {
                    throw new Exception(e);
                }
            }
            confBuilder.read(cacheManager.getDefaultCacheConfiguration());
        } else if (config.isDistributed()) {
            // We expect a distributed cache
            if (distributedCacheManager == null) {
                throw new IllegalArgumentException("The DistributedCacheManager has not been defined in the configuration," + " please configure it at root container level if you want to use a distributed cache.");
            }
            return new DistributedExoCache(ctx, config, distributedCacheManager.getCache(DistributedExoCache.CACHE_NAME));
        } else {
            cacheManager = this.cacheManager;
            // No custom configuration has been found, a configuration template will be used
            if (LOG.isInfoEnabled())
                LOG.info("The configuration template will be used for the cache '" + region + "'.");
            confBuilder.read(cacheManager.getDefaultCacheConfiguration());
            if (!config.isRepicated()) {
                // The cache is local
                confBuilder.clustering().cacheMode(CacheMode.LOCAL);
            }
        }
        // Reset the configuration to avoid conflicts
        resetConfiguration(confBuilder);
        final ExoCacheCreator creator = getExoCacheCreator(config);
        // Create the cache
        eXoCache = creator.create(config, confBuilder, new Callable<Cache<Serializable, Object>>() {

            public Cache<Serializable, Object> call() throws Exception {
                try {
                    return SecurityHelper.doPrivilegedExceptionAction(new PrivilegedExceptionAction<Cache<Serializable, Object>>() {

                        public Cache<Serializable, Object> run() throws Exception {
                            // Define the configuration
                            cacheManager.defineConfiguration(region, confBuilder.build());
                            // create and start the cache
                            return cacheManager.getCache(region);
                        }
                    });
                } catch (PrivilegedActionException e) {
                    Throwable cause = e.getCause();
                    if (cause instanceof Exception) {
                        // NOSONAR
                        throw (Exception) cause;
                    } else {
                        throw new Exception(e);
                    }
                }
            }
        });
    } catch (// NOSONAR
    Exception e) {
        throw new ExoCacheInitException("The cache '" + region + "' could not be initialized", e);
    }
    return eXoCache;
}
Also used : GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) DefaultCacheManager(org.infinispan.manager.DefaultCacheManager) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) Serializable(java.io.Serializable) GlobalConfiguration(org.infinispan.configuration.global.GlobalConfiguration) PrivilegedActionException(java.security.PrivilegedActionException) GenericExoCacheCreator(org.exoplatform.services.cache.impl.infinispan.generic.GenericExoCacheCreator) ParserRegistry(org.infinispan.configuration.parsing.ParserRegistry) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) PrivilegedActionException(java.security.PrivilegedActionException) ExoCacheInitException(org.exoplatform.services.cache.ExoCacheInitException) Callable(java.util.concurrent.Callable) ExoCacheInitException(org.exoplatform.services.cache.ExoCacheInitException) ConfigurationBuilderHolder(org.infinispan.configuration.parsing.ConfigurationBuilderHolder) DistributedExoCache(org.exoplatform.services.cache.impl.infinispan.distributed.DistributedExoCache) ExoCache(org.exoplatform.services.cache.ExoCache) Cache(org.infinispan.Cache) DistributedExoCache(org.exoplatform.services.cache.impl.infinispan.distributed.DistributedExoCache)

Aggregations

ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)71 Configuration (org.infinispan.configuration.cache.Configuration)36 GlobalConfigurationBuilder (org.infinispan.configuration.global.GlobalConfigurationBuilder)29 DefaultCacheManager (org.infinispan.manager.DefaultCacheManager)23 Test (org.junit.Test)19 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)9 ClusteringConfigurationBuilder (org.infinispan.configuration.cache.ClusteringConfigurationBuilder)8 GlobalConfiguration (org.infinispan.configuration.global.GlobalConfiguration)7 Properties (java.util.Properties)6 Map (java.util.Map)5 InfinispanRegionFactory (org.hibernate.cache.infinispan.InfinispanRegionFactory)5 TimestampsRegionImpl (org.hibernate.cache.infinispan.timestamp.TimestampsRegionImpl)5 BeforeClass (org.junit.BeforeClass)5 AdvancedCache (org.infinispan.AdvancedCache)4 BackupConfiguration (org.infinispan.configuration.cache.BackupConfiguration)3 BackupConfigurationBuilder (org.infinispan.configuration.cache.BackupConfigurationBuilder)3 CacheMode (org.infinispan.configuration.cache.CacheMode)3 SitesConfigurationBuilder (org.infinispan.configuration.cache.SitesConfigurationBuilder)3 TransportConfigurationBuilder (org.infinispan.configuration.global.TransportConfigurationBuilder)3 EmbeddedTransactionManagerLookup (org.infinispan.transaction.lookup.EmbeddedTransactionManagerLookup)3