Search in sources :

Example 1 with Configuration

use of org.infinispan.configuration.cache.Configuration in project jetty.project by eclipse.

the class InfinispanTestSupport method setup.

public void setup() throws Exception {
    if (_useFileStore) {
        _tmpdir = File.createTempFile("infini", "span");
        _tmpdir.delete();
        _tmpdir.mkdir();
        Configuration config = _builder.persistence().addSingleFileStore().location(_tmpdir.getAbsolutePath()).storeAsBinary().build();
        _manager.defineConfiguration(_name, config);
    } else {
        _manager.defineConfiguration(_name, _builder.build());
    }
    _cache = _manager.getCache(_name);
}
Also used : Configuration(org.infinispan.configuration.cache.Configuration)

Example 2 with Configuration

use of org.infinispan.configuration.cache.Configuration in project hibernate-orm by hibernate.

the class InfinispanRegionFactory method getCache.

protected AdvancedCache getCache(String regionName, DataType type, CacheDataDescription metadata) {
    if (!manager.cacheExists(regionName)) {
        String templateCacheName = baseConfigurations.get(regionName);
        Configuration configuration = null;
        ConfigurationBuilder builder = new ConfigurationBuilder();
        if (templateCacheName != null) {
            configuration = manager.getCacheConfiguration(templateCacheName);
            if (configuration == null) {
                log.customConfigForRegionNotFound(templateCacheName, regionName, type.key);
            } else {
                log.debugf("Region '%s' will use cache template '%s'", regionName, templateCacheName);
                builder.read(configuration);
                configureTransactionManager(builder);
            // do not apply data type overrides to regions that set special cache configuration
            }
        }
        if (configuration == null) {
            configuration = dataTypeConfigurations.get(type);
            if (configuration == null) {
                throw new IllegalStateException("Configuration not defined for type " + type.key);
            }
            builder.read(configuration);
        // overrides for data types are already applied, but we should check custom ones
        }
        ConfigurationBuilder override = configOverrides.get(regionName);
        if (override != null) {
            log.debugf("Region '%s' has additional configuration set through properties.", regionName);
            builder.read(override.build(false));
        }
        if (getCacheKeysFactory() instanceof SimpleCacheKeysFactory) {
            // the keys may not define hashCode/equals correctly (e.g. arrays)
            if (metadata != null && metadata.getKeyType() != null) {
                builder.dataContainer().keyEquivalence(new TypeEquivalance(metadata.getKeyType()));
            }
        }
        if (globalStats != null) {
            builder.jmxStatistics().enabled(globalStats).available(globalStats);
        }
        configuration = builder.build();
        type.validate(configuration);
        manager.defineConfiguration(regionName, configuration);
    }
    final AdvancedCache cache = manager.getCache(regionName).getAdvancedCache();
    // TODO: not sure if this is needed in recent Infinispan
    if (!cache.getStatus().allowInvocations()) {
        cache.start();
    }
    return createCacheWrapper(cache);
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) TransactionConfiguration(org.infinispan.configuration.cache.TransactionConfiguration) Configuration(org.infinispan.configuration.cache.Configuration) SimpleCacheKeysFactory(org.hibernate.cache.internal.SimpleCacheKeysFactory) AdvancedCache(org.infinispan.AdvancedCache)

Example 3 with Configuration

use of org.infinispan.configuration.cache.Configuration in project hibernate-orm by hibernate.

the class InfinispanRegionFactoryTestCase method testBuildEntityRegionPersonPlusEntityOverridesWithoutCfg.

@Test
public void testBuildEntityRegionPersonPlusEntityOverridesWithoutCfg() {
    final String person = "com.acme.Person";
    Properties p = createProperties();
    // Third option, no cache defined for entity and overrides for generic entity data type and entity itself.
    p.setProperty("hibernate.cache.infinispan.com.acme.Person.eviction.strategy", "LRU");
    p.setProperty("hibernate.cache.infinispan.com.acme.Person.expiration.lifespan", "60000");
    p.setProperty("hibernate.cache.infinispan.com.acme.Person.expiration.max_idle", "30000");
    p.setProperty("hibernate.cache.infinispan.entity.cfg", "myentity-cache");
    p.setProperty("hibernate.cache.infinispan.entity.eviction.strategy", "FIFO");
    p.setProperty("hibernate.cache.infinispan.entity.eviction.max_entries", "10000");
    p.setProperty("hibernate.cache.infinispan.entity.expiration.wake_up_interval", "3000");
    TestInfinispanRegionFactory factory = createRegionFactory(p);
    try {
        factory.getCacheManager();
        assertFalse(isDefinedCache(factory, person));
        EntityRegionImpl region = (EntityRegionImpl) factory.buildEntityRegion(person, p, MUTABLE_NON_VERSIONED);
        assertTrue(isDefinedCache(factory, person));
        AdvancedCache cache = region.getCache();
        Configuration cacheCfg = cache.getCacheConfiguration();
        assertEquals(EvictionStrategy.LRU, cacheCfg.eviction().strategy());
        assertEquals(3000, cacheCfg.expiration().wakeUpInterval());
        assertEquals(10000, cacheCfg.eviction().maxEntries());
        assertEquals(60000, cacheCfg.expiration().lifespan());
        assertEquals(30000, cacheCfg.expiration().maxIdle());
    } finally {
        factory.stop();
    }
}
Also used : EntityRegionImpl(org.hibernate.cache.infinispan.entity.EntityRegionImpl) Configuration(org.infinispan.configuration.cache.Configuration) AdvancedCache(org.infinispan.AdvancedCache) Properties(java.util.Properties) Test(org.junit.Test)

Example 4 with Configuration

use of org.infinispan.configuration.cache.Configuration in project hibernate-orm by hibernate.

the class InfinispanRegionFactoryTestCase method testBuildQueryRegionWithCustomRegionName.

@Test
public void testBuildQueryRegionWithCustomRegionName() {
    final String queryRegionName = "myquery";
    Properties p = createProperties();
    p.setProperty("hibernate.cache.infinispan.myquery.cfg", "timestamps-none-eviction");
    p.setProperty("hibernate.cache.infinispan.myquery.eviction.strategy", "LIRS");
    p.setProperty("hibernate.cache.infinispan.myquery.expiration.wake_up_interval", "2222");
    p.setProperty("hibernate.cache.infinispan.myquery.eviction.max_entries", "11111");
    TestInfinispanRegionFactory factory = createRegionFactory(p);
    try {
        assertTrue(isDefinedCache(factory, "local-query"));
        QueryResultsRegionImpl region = (QueryResultsRegionImpl) factory.buildQueryResultsRegion(queryRegionName, p);
        assertNotNull(factory.getBaseConfiguration(queryRegionName));
        assertTrue(isDefinedCache(factory, queryRegionName));
        AdvancedCache cache = region.getCache();
        Configuration cacheCfg = cache.getCacheConfiguration();
        assertEquals(EvictionStrategy.LIRS, cacheCfg.eviction().strategy());
        assertEquals(2222, cacheCfg.expiration().wakeUpInterval());
        assertEquals(11111, cacheCfg.eviction().maxEntries());
    } finally {
        factory.stop();
    }
}
Also used : QueryResultsRegionImpl(org.hibernate.cache.infinispan.query.QueryResultsRegionImpl) Configuration(org.infinispan.configuration.cache.Configuration) AdvancedCache(org.infinispan.AdvancedCache) Properties(java.util.Properties) Test(org.junit.Test)

Example 5 with Configuration

use of org.infinispan.configuration.cache.Configuration in project hibernate-orm by hibernate.

the class InfinispanRegionFactoryTestCase method testBuildQueryRegion.

@Test
public void testBuildQueryRegion() {
    final String query = "org.hibernate.cache.internal.StandardQueryCache";
    Properties p = createProperties();
    InfinispanRegionFactory factory = createRegionFactory(p);
    try {
        assertTrue(isDefinedCache(factory, "local-query"));
        QueryResultsRegionImpl region = (QueryResultsRegionImpl) factory.buildQueryResultsRegion(query, p);
        AdvancedCache cache = region.getCache();
        Configuration cacheCfg = cache.getCacheConfiguration();
        assertEquals(CacheMode.LOCAL, cacheCfg.clustering().cacheMode());
        assertFalse(cacheCfg.jmxStatistics().enabled());
    } finally {
        factory.stop();
    }
}
Also used : QueryResultsRegionImpl(org.hibernate.cache.infinispan.query.QueryResultsRegionImpl) InfinispanRegionFactory(org.hibernate.cache.infinispan.InfinispanRegionFactory) Configuration(org.infinispan.configuration.cache.Configuration) AdvancedCache(org.infinispan.AdvancedCache) Properties(java.util.Properties) Test(org.junit.Test)

Aggregations

Configuration (org.infinispan.configuration.cache.Configuration)37 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)24 Test (org.junit.Test)24 Properties (java.util.Properties)12 AdvancedCache (org.infinispan.AdvancedCache)9 GlobalConfigurationBuilder (org.infinispan.configuration.global.GlobalConfigurationBuilder)6 InfinispanRegionFactory (org.hibernate.cache.infinispan.InfinispanRegionFactory)5 EntityRegionImpl (org.hibernate.cache.infinispan.entity.EntityRegionImpl)4 GlobalConfiguration (org.infinispan.configuration.global.GlobalConfiguration)4 CacheMode (org.infinispan.configuration.cache.CacheMode)3 TransactionConfiguration (org.infinispan.configuration.cache.TransactionConfiguration)3 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)3 CollectionRegionImpl (org.hibernate.cache.infinispan.collection.CollectionRegionImpl)2 QueryResultsRegionImpl (org.hibernate.cache.infinispan.query.QueryResultsRegionImpl)2 TimestampsRegionImpl (org.hibernate.cache.infinispan.timestamp.TimestampsRegionImpl)2 DefaultCacheManager (org.infinispan.manager.DefaultCacheManager)2 CacheProperties (org.wildfly.clustering.ee.cache.CacheProperties)2 TransactionBatch (org.wildfly.clustering.ee.infinispan.TransactionBatch)2 Method (java.lang.reflect.Method)1 Map (java.util.Map)1