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();
}
}
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;
}
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);
}
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);
}
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);
}
Aggregations