Search in sources :

Example 6 with EmbeddedCacheManager

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

the class InfinispanRegionFactoryTestCase method testBuildEntityCollectionRegionsPersonPlusEntityCollectionOverrides.

@Test
public void testBuildEntityCollectionRegionsPersonPlusEntityCollectionOverrides() {
    final String person = "com.acme.Person";
    final String address = "com.acme.Address";
    final String car = "com.acme.Car";
    final String addresses = "com.acme.Person.addresses";
    final String parts = "com.acme.Car.parts";
    Properties p = createProperties();
    // First option, cache defined for entity and overrides for generic entity data type and entity itself.
    p.setProperty("hibernate.cache.infinispan.com.acme.Person.cfg", "person-cache");
    p.setProperty("hibernate.cache.infinispan.com.acme.Person.eviction.strategy", "LRU");
    p.setProperty("hibernate.cache.infinispan.com.acme.Person.eviction.max_entries", "5000");
    p.setProperty("hibernate.cache.infinispan.com.acme.Person.expiration.wake_up_interval", "2000");
    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", "LIRS");
    p.setProperty("hibernate.cache.infinispan.entity.expiration.wake_up_interval", "3000");
    p.setProperty("hibernate.cache.infinispan.entity.eviction.max_entries", "20000");
    p.setProperty("hibernate.cache.infinispan.com.acme.Person.addresses.cfg", "addresses-cache");
    p.setProperty("hibernate.cache.infinispan.com.acme.Person.addresses.eviction.strategy", "LIRS");
    p.setProperty("hibernate.cache.infinispan.com.acme.Person.addresses.eviction.max_entries", "5500");
    p.setProperty("hibernate.cache.infinispan.com.acme.Person.addresses.expiration.wake_up_interval", "2500");
    p.setProperty("hibernate.cache.infinispan.com.acme.Person.addresses.expiration.lifespan", "65000");
    p.setProperty("hibernate.cache.infinispan.com.acme.Person.addresses.expiration.max_idle", "35000");
    p.setProperty("hibernate.cache.infinispan.collection.cfg", "mycollection-cache");
    p.setProperty("hibernate.cache.infinispan.collection.eviction.strategy", "LRU");
    p.setProperty("hibernate.cache.infinispan.collection.expiration.wake_up_interval", "3500");
    p.setProperty("hibernate.cache.infinispan.collection.eviction.max_entries", "25000");
    TestInfinispanRegionFactory factory = createRegionFactory(p);
    try {
        EmbeddedCacheManager manager = factory.getCacheManager();
        assertFalse(manager.getCacheManagerConfiguration().globalJmxStatistics().enabled());
        assertNotNull(factory.getBaseConfiguration(person));
        assertFalse(isDefinedCache(factory, person));
        assertNotNull(factory.getBaseConfiguration(addresses));
        assertFalse(isDefinedCache(factory, addresses));
        assertNull(factory.getBaseConfiguration(address));
        assertNull(factory.getBaseConfiguration(parts));
        AdvancedCache cache;
        EntityRegionImpl region = (EntityRegionImpl) factory.buildEntityRegion(person, p, MUTABLE_NON_VERSIONED);
        assertTrue(isDefinedCache(factory, person));
        cache = region.getCache();
        Configuration cacheCfg = cache.getCacheConfiguration();
        assertEquals(EvictionStrategy.LRU, cacheCfg.eviction().strategy());
        assertEquals(2000, cacheCfg.expiration().wakeUpInterval());
        assertEquals(5000, cacheCfg.eviction().maxEntries());
        assertEquals(60000, cacheCfg.expiration().lifespan());
        assertEquals(30000, cacheCfg.expiration().maxIdle());
        assertFalse(cacheCfg.jmxStatistics().enabled());
        region = (EntityRegionImpl) factory.buildEntityRegion(address, p, MUTABLE_NON_VERSIONED);
        assertTrue(isDefinedCache(factory, person));
        cache = region.getCache();
        cacheCfg = cache.getCacheConfiguration();
        assertEquals(EvictionStrategy.LIRS, cacheCfg.eviction().strategy());
        assertEquals(3000, cacheCfg.expiration().wakeUpInterval());
        assertEquals(20000, cacheCfg.eviction().maxEntries());
        assertFalse(cacheCfg.jmxStatistics().enabled());
        region = (EntityRegionImpl) factory.buildEntityRegion(car, p, MUTABLE_NON_VERSIONED);
        assertTrue(isDefinedCache(factory, person));
        cache = region.getCache();
        cacheCfg = cache.getCacheConfiguration();
        assertEquals(EvictionStrategy.LIRS, cacheCfg.eviction().strategy());
        assertEquals(3000, cacheCfg.expiration().wakeUpInterval());
        assertEquals(20000, cacheCfg.eviction().maxEntries());
        assertFalse(cacheCfg.jmxStatistics().enabled());
        CollectionRegionImpl collectionRegion = (CollectionRegionImpl) factory.buildCollectionRegion(addresses, p, MUTABLE_NON_VERSIONED);
        assertTrue(isDefinedCache(factory, person));
        cache = collectionRegion.getCache();
        cacheCfg = cache.getCacheConfiguration();
        assertEquals(EvictionStrategy.LIRS, cacheCfg.eviction().strategy());
        assertEquals(2500, cacheCfg.expiration().wakeUpInterval());
        assertEquals(5500, cacheCfg.eviction().maxEntries());
        assertEquals(65000, cacheCfg.expiration().lifespan());
        assertEquals(35000, cacheCfg.expiration().maxIdle());
        assertFalse(cacheCfg.jmxStatistics().enabled());
        collectionRegion = (CollectionRegionImpl) factory.buildCollectionRegion(parts, p, MUTABLE_NON_VERSIONED);
        assertTrue(isDefinedCache(factory, addresses));
        cache = collectionRegion.getCache();
        cacheCfg = cache.getCacheConfiguration();
        assertEquals(EvictionStrategy.LRU, cacheCfg.eviction().strategy());
        assertEquals(3500, cacheCfg.expiration().wakeUpInterval());
        assertEquals(25000, cacheCfg.eviction().maxEntries());
        assertFalse(cacheCfg.jmxStatistics().enabled());
        collectionRegion = (CollectionRegionImpl) factory.buildCollectionRegion(parts, p, MUTABLE_NON_VERSIONED);
        assertTrue(isDefinedCache(factory, addresses));
        cache = collectionRegion.getCache();
        cacheCfg = cache.getCacheConfiguration();
        assertEquals(EvictionStrategy.LRU, cacheCfg.eviction().strategy());
        assertEquals(3500, cacheCfg.expiration().wakeUpInterval());
        assertEquals(25000, cacheCfg.eviction().maxEntries());
        assertFalse(cacheCfg.jmxStatistics().enabled());
    } finally {
        factory.stop();
    }
}
Also used : EntityRegionImpl(org.hibernate.cache.infinispan.entity.EntityRegionImpl) Configuration(org.infinispan.configuration.cache.Configuration) 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 7 with EmbeddedCacheManager

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

the class TestInfinispanRegionFactory method createCacheManager.

@Override
protected EmbeddedCacheManager createCacheManager(ConfigurationBuilderHolder holder) {
    // If the cache manager has been provided by calling setCacheManager, don't create a new one
    EmbeddedCacheManager cacheManager = getCacheManager();
    if (cacheManager != null) {
        return cacheManager;
    }
    amendConfiguration(holder);
    cacheManager = new DefaultCacheManager(holder, true);
    if (timeService != null) {
        cacheManager.getGlobalComponentRegistry().registerComponent(timeService, TimeService.class);
        cacheManager.getGlobalComponentRegistry().rewire();
    }
    return cacheManager;
}
Also used : DefaultCacheManager(org.infinispan.manager.DefaultCacheManager) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager)

Example 8 with EmbeddedCacheManager

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

the class DefaultCacheContainerTestCase method startCaches.

@Test
public void startCaches() {
    when(this.manager.startCaches("other", DEFAULT_CACHE)).thenReturn(this.manager);
    EmbeddedCacheManager result = this.subject.startCaches("other", null);
    assertSame(this.subject, result);
}
Also used : EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) Test(org.junit.Test)

Example 9 with EmbeddedCacheManager

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

the class InfinispanCacheDeploymentListener method startCache.

@Override
public Wrapper startCache(Classification classification, Properties properties) throws Exception {
    String cache_type = properties.getProperty(CACHE_TYPE);
    String container = properties.getProperty(CONTAINER);
    // TODO Figure out how to access CapabilityServiceSupport from here
    ServiceName containerServiceName = ServiceName.parse(InfinispanRequirement.CONTAINER.resolve(container));
    EmbeddedCacheManager embeddedCacheManager;
    ServiceName serviceName;
    if (CACHE_PRIVATE.equals(cache_type)) {
        // need a private cache for non-jpa application use
        String name = properties.getProperty(NAME);
        serviceName = ServiceName.JBOSS.append(DEFAULT_CACHE_CONTAINER, (name != null) ? name : UUID.randomUUID().toString());
        ServiceContainer target = currentServiceContainer();
        // Create a mock service that represents this session factory instance
        ServiceBuilder<EmbeddedCacheManager> builder = new AliasServiceBuilder<>(serviceName, containerServiceName, EmbeddedCacheManager.class).build(target).setInitialMode(ServiceController.Mode.ACTIVE);
        embeddedCacheManager = ServiceContainerHelper.getValue(builder.install());
    } else {
        // need a shared cache for jpa applications
        serviceName = containerServiceName;
        ServiceRegistry registry = currentServiceContainer();
        embeddedCacheManager = (EmbeddedCacheManager) registry.getRequiredService(serviceName).getValue();
    }
    return new CacheWrapper(embeddedCacheManager, serviceName);
}
Also used : ServiceContainer(org.jboss.msc.service.ServiceContainer) CurrentServiceContainer(org.jboss.as.server.CurrentServiceContainer) ServiceName(org.jboss.msc.service.ServiceName) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) AliasServiceBuilder(org.wildfly.clustering.service.AliasServiceBuilder)

Example 10 with EmbeddedCacheManager

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

the class CacheContainerBuilder method build.

@Override
public ServiceBuilder<CacheContainer> build(ServiceTarget target) {
    Function<EmbeddedCacheManager, CacheContainer> mapper = manager -> new DefaultCacheContainer(this.name, manager, this.defaultCache, this.batcherFactory);
    Supplier<EmbeddedCacheManager> supplier = () -> {
        GlobalConfiguration config = this.configuration.getValue();
        EmbeddedCacheManager manager = new DefaultCacheManager(config, null, false);
        manager.addListener(this);
        manager.start();
        InfinispanLogger.ROOT_LOGGER.debugf("%s cache container started", this.name);
        return manager;
    };
    Consumer<EmbeddedCacheManager> destroyer = manager -> {
        manager.stop();
        manager.removeListener(this);
        InfinispanLogger.ROOT_LOGGER.debugf("%s cache container stopped", this.name);
    };
    Service<CacheContainer> service = new SuppliedValueService<>(mapper, supplier, destroyer);
    ServiceBuilder<CacheContainer> builder = target.addService(this.getServiceName(), service).addAliases(this.aliases.stream().toArray(ServiceName[]::new)).setInitialMode(ServiceController.Mode.PASSIVE);
    return this.configuration.register(builder);
}
Also used : ValueDependency(org.wildfly.clustering.service.ValueDependency) Service(org.jboss.msc.service.Service) GlobalConfiguration(org.infinispan.configuration.global.GlobalConfiguration) DefaultCacheContainer(org.jboss.as.clustering.infinispan.DefaultCacheContainer) InfinispanBatcherFactory(org.jboss.as.clustering.infinispan.InfinispanBatcherFactory) CacheContainer(org.wildfly.clustering.infinispan.spi.CacheContainer) Function(java.util.function.Function) Supplier(java.util.function.Supplier) CacheStoppedEvent(org.infinispan.notifications.cachemanagerlistener.event.CacheStoppedEvent) SuppliedValueService(org.wildfly.clustering.service.SuppliedValueService) ALIASES(org.jboss.as.clustering.infinispan.subsystem.CacheContainerResourceDefinition.Attribute.ALIASES) DefaultCacheManager(org.infinispan.manager.DefaultCacheManager) OperationContext(org.jboss.as.controller.OperationContext) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) InfinispanLogger(org.jboss.as.clustering.infinispan.InfinispanLogger) InfinispanRequirement(org.wildfly.clustering.infinispan.spi.InfinispanRequirement) CacheStopped(org.infinispan.notifications.cachemanagerlistener.annotation.CacheStopped) CacheStartedEvent(org.infinispan.notifications.cachemanagerlistener.event.CacheStartedEvent) InjectedValueDependency(org.wildfly.clustering.service.InjectedValueDependency) ServiceTarget(org.jboss.msc.service.ServiceTarget) LinkedList(java.util.LinkedList) BatcherFactory(org.jboss.as.clustering.infinispan.BatcherFactory) BasicCacheContainer(org.infinispan.commons.api.BasicCacheContainer) Listener(org.infinispan.notifications.Listener) CONTAINER(org.jboss.as.clustering.infinispan.subsystem.CacheContainerResourceDefinition.Capability.CONTAINER) PathAddress(org.jboss.as.controller.PathAddress) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) ResourceServiceBuilder(org.jboss.as.clustering.controller.ResourceServiceBuilder) Consumer(java.util.function.Consumer) ModelNodes(org.jboss.as.clustering.dmr.ModelNodes) CacheStarted(org.infinispan.notifications.cachemanagerlistener.annotation.CacheStarted) ServiceController(org.jboss.msc.service.ServiceController) List(java.util.List) DEFAULT_CACHE(org.jboss.as.clustering.infinispan.subsystem.CacheContainerResourceDefinition.Attribute.DEFAULT_CACHE) OperationFailedException(org.jboss.as.controller.OperationFailedException) ServiceName(org.jboss.msc.service.ServiceName) ModelNode(org.jboss.dmr.ModelNode) DefaultCacheManager(org.infinispan.manager.DefaultCacheManager) GlobalConfiguration(org.infinispan.configuration.global.GlobalConfiguration) DefaultCacheContainer(org.jboss.as.clustering.infinispan.DefaultCacheContainer) DefaultCacheContainer(org.jboss.as.clustering.infinispan.DefaultCacheContainer) CacheContainer(org.wildfly.clustering.infinispan.spi.CacheContainer) BasicCacheContainer(org.infinispan.commons.api.BasicCacheContainer) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) SuppliedValueService(org.wildfly.clustering.service.SuppliedValueService)

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