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