Search in sources :

Example 1 with MarshallableTypeHints

use of org.infinispan.commons.marshall.MarshallableTypeHints in project indy by Commonjava.

the class CacheProducer method startCacheManager.

private EmbeddedCacheManager startCacheManager(EmbeddedCacheManager cacheMgr, String configFile, Boolean isCluster) {
    // FIXME This is just here to trigger shutdown hook init for embedded log4j in infinispan-embedded-query.
    // FIXES:
    // 
    // Thread-15 ERROR Unable to register shutdown hook because JVM is shutting down.
    // java.lang.IllegalStateException: Cannot add new shutdown hook as this is not started. Current state: STOPPED
    // 
    new MarshallableTypeHints().getBufferSizePredictor(CacheHandle.class);
    File confDir = indyConfiguration.getIndyConfDir();
    File ispnConf = new File(confDir, configFile);
    EmbeddedCacheManager mgr = cacheMgr;
    try (InputStream resouceStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(configFile)) {
        String resourceStr = interpolateStrFromStream(resouceStream, "CLASSPATH:" + configFile);
        if (ispnConf.exists()) {
            try (InputStream confStream = FileUtils.openInputStream(ispnConf)) {
                String confStr = interpolateStrFromStream(confStream, ispnConf.getPath());
                mgr = mergedCachesFromConfig(mgr, confStr, "CUSTOMER");
                mgr = mergedCachesFromConfig(mgr, resourceStr, "CLASSPATH");
            } catch (IOException e) {
                throw new RuntimeException("Cannot read infinispan configuration from file: " + ispnConf, e);
            }
        } else {
            try {
                logger.info("Using CLASSPATH resource Infinispan configuration:\n\n{}\n\n", resourceStr);
                if (mgr == null) {
                    mgr = new DefaultCacheManager(new ByteArrayInputStream(resourceStr.getBytes(StandardCharsets.UTF_8)));
                }
            } catch (IOException e) {
                throw new RuntimeException("Failed to construct ISPN cacheManger due to CLASSPATH xml stream read error.", e);
            }
        }
        if (isCluster) {
            String[] cacheNames = mgr.getCacheNames().toArray(new String[] {});
            logger.info("Starting cluster caches to make sure they existed: {}", Arrays.toString(cacheNames));
            mgr.startCaches(cacheNames);
        }
    } catch (IOException e) {
        throw new RuntimeException("Failed to construct ISPN cacheManger due to CLASSPATH xml stream read error.", e);
    }
    return mgr;
}
Also used : DefaultCacheManager(org.infinispan.manager.DefaultCacheManager) MarshallableTypeHints(org.infinispan.commons.marshall.MarshallableTypeHints) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) File(java.io.File)

Example 2 with MarshallableTypeHints

use of org.infinispan.commons.marshall.MarshallableTypeHints in project indy by Commonjava.

the class CacheProducer method start.

@PostConstruct
public void start() {
    // FIXME This is just here to trigger shutdown hook init for embedded log4j in infinispan-embedded-query.
    // FIXES:
    //
    // Thread-15 ERROR Unable to register shutdown hook because JVM is shutting down.
    // java.lang.IllegalStateException: Cannot add new shutdown hook as this is not started. Current state: STOPPED
    //
    new MarshallableTypeHints().getBufferSizePredictor(CacheHandle.class);
    File confDir = indyConfiguration.getIndyConfDir();
    File ispnConf = new File(confDir, ISPN_XML);
    String configuration;
    if (ispnConf.exists()) {
        try {
            configuration = FileUtils.readFileToString(ispnConf);
        } catch (IOException e) {
            throw new RuntimeException("Cannot read infinispan configuration from file: " + ispnConf, e);
        }
    } else {
        try (InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream(ISPN_XML)) {
            configuration = IOUtils.toString(stream);
        } catch (IOException e) {
            throw new RuntimeException("Cannot read infinispan configuration from classpath: " + ISPN_XML, e);
        }
    }
    StringSearchInterpolator interpolator = new StringSearchInterpolator();
    interpolator.addValueSource(new PropertiesBasedValueSource(System.getProperties()));
    try {
        configuration = interpolator.interpolate(configuration);
    } catch (InterpolationException e) {
        throw new RuntimeException("Cannot resolve expressions in infinispan configuration.", e);
    }
    Logger logger = LoggerFactory.getLogger(getClass());
    logger.info("Using Infinispan configuration:\n\n{}\n\n", configuration);
    try {
        cacheManager = new DefaultCacheManager(new ByteArrayInputStream(configuration.getBytes(StandardCharsets.UTF_8)));
    } catch (IOException e) {
        throw new RuntimeException("Cannot read infinispan configuration.", e);
    }
}
Also used : DefaultCacheManager(org.infinispan.manager.DefaultCacheManager) StringSearchInterpolator(org.codehaus.plexus.interpolation.StringSearchInterpolator) MarshallableTypeHints(org.infinispan.commons.marshall.MarshallableTypeHints) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) InterpolationException(org.codehaus.plexus.interpolation.InterpolationException) Logger(org.slf4j.Logger) File(java.io.File) PropertiesBasedValueSource(org.codehaus.plexus.interpolation.PropertiesBasedValueSource) PostConstruct(javax.annotation.PostConstruct)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)2 File (java.io.File)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 MarshallableTypeHints (org.infinispan.commons.marshall.MarshallableTypeHints)2 DefaultCacheManager (org.infinispan.manager.DefaultCacheManager)2 PostConstruct (javax.annotation.PostConstruct)1 InterpolationException (org.codehaus.plexus.interpolation.InterpolationException)1 PropertiesBasedValueSource (org.codehaus.plexus.interpolation.PropertiesBasedValueSource)1 StringSearchInterpolator (org.codehaus.plexus.interpolation.StringSearchInterpolator)1 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)1 Logger (org.slf4j.Logger)1