Search in sources :

Example 1 with EmbeddedCacheManager

use of org.infinispan.manager.EmbeddedCacheManager in project hibernate-orm by hibernate.

the class InfinispanRegionFactoryTestCase method testEnableStatistics.

@Test
public void testEnableStatistics() {
    Properties p = createProperties();
    p.setProperty("hibernate.cache.infinispan.statistics", "true");
    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.expiration.wake_up_interval", "3000");
    p.setProperty("hibernate.cache.infinispan.entity.eviction.max_entries", "10000");
    InfinispanRegionFactory factory = createRegionFactory(p);
    try {
        EmbeddedCacheManager manager = factory.getCacheManager();
        assertTrue(manager.getCacheManagerConfiguration().globalJmxStatistics().enabled());
        EntityRegionImpl region = (EntityRegionImpl) factory.buildEntityRegion("com.acme.Address", p, MUTABLE_NON_VERSIONED);
        AdvancedCache cache = region.getCache();
        assertTrue(cache.getCacheConfiguration().jmxStatistics().enabled());
        region = (EntityRegionImpl) factory.buildEntityRegion("com.acme.Person", p, MUTABLE_NON_VERSIONED);
        cache = region.getCache();
        assertTrue(cache.getCacheConfiguration().jmxStatistics().enabled());
        final String query = "org.hibernate.cache.internal.StandardQueryCache";
        QueryResultsRegionImpl queryRegion = (QueryResultsRegionImpl) factory.buildQueryResultsRegion(query, p);
        cache = queryRegion.getCache();
        assertTrue(cache.getCacheConfiguration().jmxStatistics().enabled());
        final String timestamps = "org.hibernate.cache.spi.UpdateTimestampsCache";
        ConfigurationBuilder builder = new ConfigurationBuilder();
        builder.clustering().stateTransfer().fetchInMemoryState(true);
        manager.defineConfiguration("timestamps", builder.build());
        TimestampsRegionImpl timestampsRegion = (TimestampsRegionImpl) factory.buildTimestampsRegion(timestamps, p);
        cache = timestampsRegion.getCache();
        assertTrue(cache.getCacheConfiguration().jmxStatistics().enabled());
        CollectionRegionImpl collectionRegion = (CollectionRegionImpl) factory.buildCollectionRegion("com.acme.Person.addresses", p, MUTABLE_NON_VERSIONED);
        cache = collectionRegion.getCache();
        assertTrue(cache.getCacheConfiguration().jmxStatistics().enabled());
    } finally {
        factory.stop();
    }
}
Also used : QueryResultsRegionImpl(org.hibernate.cache.infinispan.query.QueryResultsRegionImpl) TimestampsRegionImpl(org.hibernate.cache.infinispan.timestamp.TimestampsRegionImpl) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) ClusteringConfigurationBuilder(org.infinispan.configuration.cache.ClusteringConfigurationBuilder) GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) InfinispanRegionFactory(org.hibernate.cache.infinispan.InfinispanRegionFactory) EntityRegionImpl(org.hibernate.cache.infinispan.entity.EntityRegionImpl) CollectionRegionImpl(org.hibernate.cache.infinispan.collection.CollectionRegionImpl) AdvancedCache(org.infinispan.AdvancedCache) Properties(java.util.Properties) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) Test(org.junit.Test)

Example 2 with EmbeddedCacheManager

use of org.infinispan.manager.EmbeddedCacheManager in project hibernate-orm by hibernate.

the class ClusterAwareRegionFactory method start.

public void start(SessionFactoryOptions settings, Properties properties) throws CacheException {
    cacheManagerName = properties.getProperty(DualNodeTest.NODE_ID_PROP);
    EmbeddedCacheManager existing = getCacheManager(cacheManagerName);
    locallyAdded = (existing == null);
    if (locallyAdded) {
        delegate.start(settings, properties);
        cacheManagers.put(cacheManagerName, delegate.getCacheManager());
    } else {
        delegate.setCacheManager(existing);
    }
}
Also used : EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager)

Example 3 with EmbeddedCacheManager

use of org.infinispan.manager.EmbeddedCacheManager in project spring-boot by spring-projects.

the class InfinispanCacheConfiguration method infinispanCacheManager.

@Bean(destroyMethod = "stop")
@ConditionalOnMissingBean
public EmbeddedCacheManager infinispanCacheManager() throws IOException {
    EmbeddedCacheManager cacheManager = createEmbeddedCacheManager();
    List<String> cacheNames = this.cacheProperties.getCacheNames();
    if (!CollectionUtils.isEmpty(cacheNames)) {
        for (String cacheName : cacheNames) {
            cacheManager.defineConfiguration(cacheName, getDefaultCacheConfiguration());
        }
    }
    return cacheManager;
}
Also used : EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) SpringEmbeddedCacheManager(org.infinispan.spring.provider.SpringEmbeddedCacheManager) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 4 with EmbeddedCacheManager

use of org.infinispan.manager.EmbeddedCacheManager in project wildfly by wildfly.

the class SharedInfinispanRegionFactory method createCacheManager.

@Override
protected EmbeddedCacheManager createCacheManager(Properties properties, final ServiceRegistry serviceRegistry) {
    String container = properties.getProperty(CACHE_CONTAINER, DEFAULT_CACHE_CONTAINER);
    Properties cacheSettings = new Properties();
    cacheSettings.put(HibernateSecondLevelCache.CONTAINER, container);
    try {
        // Get the (shared) cache manager for JPA application use
        wrapper = Notification.startCache(Classification.INFINISPAN, cacheSettings);
        return (EmbeddedCacheManager) wrapper.getValue();
    } catch (Exception e) {
        throw new CacheException(e);
    }
}
Also used : CacheException(org.hibernate.cache.CacheException) Properties(java.util.Properties) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) CacheException(org.hibernate.cache.CacheException)

Example 5 with EmbeddedCacheManager

use of org.infinispan.manager.EmbeddedCacheManager in project galley by Commonjava.

the class NFSOwnerCacheProducer method getCacheMgr.

public EmbeddedCacheManager getCacheMgr() {
    final EmbeddedCacheManager cacheManager = new DefaultCacheManager(new GlobalConfigurationBuilder().globalJmxStatistics().jmxDomain("org.commonjava.maven.galley").build());
    // Want to enable dead lock check as lock will be used in FastLocalCacheProvider
    // and also set transaction mode to PESSIMISTIC with DummyTransactionManger.
    final Configuration configuration = new ConfigurationBuilder().eviction().strategy(EvictionStrategy.LRU).size(1000).type(EvictionType.COUNT).deadlockDetection().spinDuration(10, TimeUnit.SECONDS).enable().transaction().transactionManagerLookup(new DummyTransactionManagerLookup()).lockingMode(LockingMode.PESSIMISTIC).build();
    cacheManager.defineConfiguration(CACHE_NAME, configuration);
    return cacheManager;
}
Also used : GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) DummyTransactionManagerLookup(org.infinispan.transaction.lookup.DummyTransactionManagerLookup) DefaultCacheManager(org.infinispan.manager.DefaultCacheManager) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) Configuration(org.infinispan.configuration.cache.Configuration) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager)

Aggregations

EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)14 Properties (java.util.Properties)6 CacheException (org.hibernate.cache.CacheException)4 DefaultCacheManager (org.infinispan.manager.DefaultCacheManager)3 Test (org.junit.Test)3 CollectionRegionImpl (org.hibernate.cache.infinispan.collection.CollectionRegionImpl)2 EntityRegionImpl (org.hibernate.cache.infinispan.entity.EntityRegionImpl)2 AdvancedCache (org.infinispan.AdvancedCache)2 Configuration (org.infinispan.configuration.cache.Configuration)2 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)2 GlobalConfigurationBuilder (org.infinispan.configuration.global.GlobalConfigurationBuilder)2 ServiceName (org.jboss.msc.service.ServiceName)2 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Consumer (java.util.function.Consumer)1 Function (java.util.function.Function)1 Supplier (java.util.function.Supplier)1 InfinispanRegionFactory (org.hibernate.cache.infinispan.InfinispanRegionFactory)1 QueryResultsRegionImpl (org.hibernate.cache.infinispan.query.QueryResultsRegionImpl)1 TimestampsRegionImpl (org.hibernate.cache.infinispan.timestamp.TimestampsRegionImpl)1