Search in sources :

Example 1 with ConfigurationBuilderHolder

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);
}
Also used : ConfigurationBuilderHolder(org.infinispan.configuration.parsing.ConfigurationBuilderHolder)

Example 2 with ConfigurationBuilderHolder

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);
    }
}
Also used : ConfigurationBuilderHolder(org.infinispan.configuration.parsing.ConfigurationBuilderHolder)

Example 3 with ConfigurationBuilderHolder

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);
    }
}
Also used : TimestampsRegionImpl(org.hibernate.cache.infinispan.timestamp.TimestampsRegionImpl) DefaultCacheManager(org.infinispan.manager.DefaultCacheManager) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) ClusteringConfigurationBuilder(org.infinispan.configuration.cache.ClusteringConfigurationBuilder) GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) ConfigurationBuilderHolder(org.infinispan.configuration.parsing.ConfigurationBuilderHolder) InfinispanRegionFactory(org.hibernate.cache.infinispan.InfinispanRegionFactory) InputStream(java.io.InputStream) ParserRegistry(org.infinispan.configuration.parsing.ParserRegistry) Properties(java.util.Properties) Test(org.junit.Test)

Example 4 with ConfigurationBuilderHolder

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;
}
Also used : DefaultCacheManager(org.infinispan.manager.DefaultCacheManager) ConfigurationBuilderHolder(org.infinispan.configuration.parsing.ConfigurationBuilderHolder) ByteArrayInputStream(java.io.ByteArrayInputStream) ParserRegistry(org.infinispan.configuration.parsing.ParserRegistry) IOException(java.io.IOException) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) ConfigurationManager(org.infinispan.configuration.ConfigurationManager)

Example 5 with ConfigurationBuilderHolder

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);
            }
        }
    });
}
Also used : ConfigurationBuilderHolder(org.infinispan.configuration.parsing.ConfigurationBuilderHolder) InputStream(java.io.InputStream) ParserRegistry(org.infinispan.configuration.parsing.ParserRegistry) IOException(java.io.IOException) FileLookup(org.infinispan.commons.util.FileLookup) ClassLoaderService(org.hibernate.boot.registry.classloading.spi.ClassLoaderService)

Aggregations

ConfigurationBuilderHolder (org.infinispan.configuration.parsing.ConfigurationBuilderHolder)9 ParserRegistry (org.infinispan.configuration.parsing.ParserRegistry)6 DefaultCacheManager (org.infinispan.manager.DefaultCacheManager)5 IOException (java.io.IOException)3 GlobalConfigurationBuilder (org.infinispan.configuration.global.GlobalConfigurationBuilder)3 InputStream (java.io.InputStream)2 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)2 GlobalConfiguration (org.infinispan.configuration.global.GlobalConfiguration)2 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Serializable (java.io.Serializable)1 PrivilegedActionException (java.security.PrivilegedActionException)1 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)1 Properties (java.util.Properties)1 Callable (java.util.concurrent.Callable)1 ExoCache (org.exoplatform.services.cache.ExoCache)1 ExoCacheInitException (org.exoplatform.services.cache.ExoCacheInitException)1 DistributedExoCache (org.exoplatform.services.cache.impl.infinispan.distributed.DistributedExoCache)1 GenericExoCacheCreator (org.exoplatform.services.cache.impl.infinispan.generic.GenericExoCacheCreator)1 ClassLoaderService (org.hibernate.boot.registry.classloading.spi.ClassLoaderService)1