Search in sources :

Example 1 with FileLookup

use of org.infinispan.commons.util.FileLookup 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

IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ClassLoaderService (org.hibernate.boot.registry.classloading.spi.ClassLoaderService)1 FileLookup (org.infinispan.commons.util.FileLookup)1 ConfigurationBuilderHolder (org.infinispan.configuration.parsing.ConfigurationBuilderHolder)1 ParserRegistry (org.infinispan.configuration.parsing.ParserRegistry)1