use of org.infinispan.configuration.parsing.ConfigurationBuilderHolder in project hibernate-orm by hibernate.
the class InfinispanRegionFactory method createCacheManager.
/* This method is overridden in WildFly, so the signature must not change. */
/* In WF, the global configuration setting is ignored */
protected EmbeddedCacheManager createCacheManager(Properties properties, ServiceRegistry serviceRegistry) {
if (properties.containsKey(INFINISPAN_USE_SYNCHRONIZATION_PROP)) {
log.propertyUseSynchronizationDeprecated();
}
ConfigurationBuilderHolder cfgHolder;
String configFile = ConfigurationHelper.extractPropertyValue(INFINISPAN_CONFIG_RESOURCE_PROP, properties);
if (configFile != null) {
cfgHolder = loadConfiguration(serviceRegistry, configFile);
} else {
cfgHolder = defaultConfiguration;
}
// We cannot just add the default configurations not defined in provided configuration
// since WF overrides this method - we have to deal with missing configuration for each cache separately
String globalStatsStr = extractProperty(INFINISPAN_GLOBAL_STATISTICS_PROP, properties);
if (globalStatsStr != null) {
globalStats = Boolean.parseBoolean(globalStatsStr);
}
if (globalStats != null) {
cfgHolder.getGlobalConfigurationBuilder().globalJmxStatistics().enabled(globalStats);
}
return createCacheManager(cfgHolder);
}
use of org.infinispan.configuration.parsing.ConfigurationBuilderHolder in project hibernate-orm by hibernate.
the class InfinispanRegionFactory method parseWithOverridenClassLoader.
private static ConfigurationBuilderHolder parseWithOverridenClassLoader(ParserRegistry configurationParser, InputStream is, ClassLoader infinispanClassLoader) {
// Infinispan requires the context ClassLoader to have full visibility on all
// its components and eventual extension points even *during* configuration parsing.
final Thread currentThread = Thread.currentThread();
final ClassLoader originalContextClassLoader = currentThread.getContextClassLoader();
try {
currentThread.setContextClassLoader(infinispanClassLoader);
ConfigurationBuilderHolder builderHolder = configurationParser.parse(is);
// Workaround Infinispan's ClassLoader strategies to bend to our will:
builderHolder.getGlobalConfigurationBuilder().classLoader(infinispanClassLoader);
return builderHolder;
} finally {
currentThread.setContextClassLoader(originalContextClassLoader);
}
}
use of org.infinispan.configuration.parsing.ConfigurationBuilderHolder in project hibernate-orm by hibernate.
the class InfinispanRegionFactoryTestCase method testTimestampValidation.
@Test(expected = CacheException.class)
public void testTimestampValidation() {
final String timestamps = "org.hibernate.cache.spi.UpdateTimestampsCache";
Properties p = createProperties();
InputStream configStream = FileLookupFactory.newInstance().lookupFile(InfinispanRegionFactory.DEF_INFINISPAN_CONFIG_RESOURCE, getClass().getClassLoader());
ConfigurationBuilderHolder cbh = new ParserRegistry().parse(configStream);
DefaultCacheManager manager = new DefaultCacheManager(cbh, true);
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.clustering().cacheMode(CacheMode.INVALIDATION_SYNC);
manager.defineConfiguration(DEF_TIMESTAMPS_RESOURCE, builder.build());
try {
InfinispanRegionFactory factory = createRegionFactory(manager, p, null);
factory.start(CacheTestUtil.sfOptionsForStart(), p);
TimestampsRegionImpl region = (TimestampsRegionImpl) factory.buildTimestampsRegion(timestamps, p);
fail("Should have failed saying that invalidation is not allowed for timestamp caches.");
} finally {
TestingUtil.killCacheManagers(manager);
}
}
use of org.infinispan.configuration.parsing.ConfigurationBuilderHolder in project indy by Commonjava.
the class CacheProducer method mergedCachesFromConfig.
/**
* For the ISPN merging, we should involve at least two different xml config scopes here,
* one is from indy self default resource xml, another one is from customer's config xml.
*
* To prevent the error of EmbeddedCacheManager instances configured with same JMX domain,
* ISPN should enable 'allowDuplicateDomains' attribute for per GlobalConfigurationBuilder build,
* that will cost more price there for DefaultCacheManager construct and ConfigurationBuilder build.
*
* Since what we need here is simply parsing xml inputStreams to the defined configurations that ISPN
* could accept, then merging the two stream branches into a entire one.
* What classes this method uses from ISPN are:
* {@link ConfigurationBuilderHolder}
* {@link ParserRegistry}
* {@link ConfigurationManager}
*
* @param cacheMgr
* @param config
* @param path
*/
private EmbeddedCacheManager mergedCachesFromConfig(EmbeddedCacheManager cacheMgr, String config, String path) {
logger.debug("[ISPN xml merge] cache config xml to merge:\n {}", config);
// FIXME: here may cause ISPN000343 problem if your cache config has enabled distributed cache. Because distributed
// cache needs transport support, so if the cache manager does not enable it and then add this type of cache
// by defineConfiguration, it will report ISPN000343. So we should ensure the transport has been added by initialization.
EmbeddedCacheManager mgr = cacheMgr;
if (mgr == null) {
try {
logger.info("Using {} resource Infinispan configuration to construct mergable cache configuration:\n\n{}\n\n", path, config);
mgr = new DefaultCacheManager(new ByteArrayInputStream(config.getBytes(StandardCharsets.UTF_8)));
} catch (IOException e) {
throw new RuntimeException(String.format("Failed to construct ISPN cacheManger due to %s xml stream read error.", path), e);
}
}
final ConfigurationBuilderHolder holder = (new ParserRegistry()).parse(IOUtils.toInputStream(config));
final ConfigurationManager manager = new ConfigurationManager(holder);
final Set<String> definedCaches = mgr.getCacheNames();
for (String name : manager.getDefinedCaches()) {
if (definedCaches.isEmpty() || !definedCaches.contains(name)) {
logger.info("[ISPN xml merge] Define cache: {} from {} config.", name, path);
mgr.defineConfiguration(name, manager.getConfiguration(name, false));
}
}
return mgr;
}
use of org.infinispan.configuration.parsing.ConfigurationBuilderHolder in project hibernate-orm by hibernate.
the class InfinispanRegionFactory method loadConfiguration.
private ConfigurationBuilderHolder loadConfiguration(ServiceRegistry serviceRegistry, String configFile) {
final FileLookup fileLookup = FileLookupFactory.newInstance();
final ClassLoader infinispanClassLoader = InfinispanRegionFactory.class.getClassLoader();
return serviceRegistry.getService(ClassLoaderService.class).workWithClassLoader(new ClassLoaderService.Work<ConfigurationBuilderHolder>() {
@Override
public ConfigurationBuilderHolder doWork(ClassLoader classLoader) {
InputStream is = null;
try {
is = fileLookup.lookupFile(configFile, classLoader);
if (is == null) {
// when it's not a user-provided configuration file, it might be a default configuration file,
// and if that's included in [this] module might not be visible to the ClassLoaderService:
classLoader = infinispanClassLoader;
// This time use lookupFile*Strict* so to provide an exception if we can't find it yet:
is = FileLookupFactory.newInstance().lookupFileStrict(configFile, classLoader);
}
final ParserRegistry parserRegistry = new ParserRegistry(infinispanClassLoader);
final ConfigurationBuilderHolder holder = parseWithOverridenClassLoader(parserRegistry, is, infinispanClassLoader);
return holder;
} catch (IOException e) {
throw log.unableToCreateCacheManager(e);
} finally {
Util.close(is);
}
}
});
}
Aggregations