This is my Java implementation of Ignite as a caching layer.
public static void main(String[] args) throws IOException {
Properties conf = getConfiguration();
IgniteConfiguration cfg = new IgniteConfiguration();
CacheConfiguration configuration = new CacheConfiguration();
configuration.setName("ignt");
DataSource dataSource = new DataSource();
dataSource.setContactPoints(conf.getProperty("cass.contactPoints"));
RoundRobinPolicy robinPolicy = new RoundRobinPolicy();
dataSource.setLoadBalancingPolicy(robinPolicy);
dataSource.setReadConsistency("ONE");
dataSource.setWriteConsistency("ONE");
dataSource.setProtocolVersion(4);
dataSource.setPort(9042);
configuration.setWriteThrough(true);
configuration.setReadThrough(true);
configuration.setWriteBehindEnabled(true);
configuration.setWriteBehindFlushFrequency(30000);
String persistenceSettingsXml = FileUtils.readFileToString(new File(conf.getProperty("ignite.persistenceSettings")), "utf-8");
KeyValuePersistenceSettings persistenceSettings = new KeyValuePersistenceSettings(persistenceSettingsXml);
System.out.println(persistenceSettings.getKeyspace());
CassandraCacheStoreFactory cacheStoreFactory = new CassandraCacheStoreFactory();
cacheStoreFactory.setDataSource(dataSource);
cacheStoreFactory.setPersistenceSettings(persistenceSettings);
configuration.setCacheStoreFactory(cacheStoreFactory);
cfg.setCacheConfiguration(configuration);
cfg.setGridName("g1");
Ignite ignite=Ignition.getOrStart(cfg);
System.out.println(cfg.getNodeId());
cfg.setGridName("g2");
Ignite igTwo = Ignition.getOrStart(cfg);
}
Is there a way to run multiple nodes (on localhost) from the same JVM program? If it is not possible to run multiple nodes from the same Java program, is there a way to run all the nodes from the command prompt separately and then connect to them from the Java application?