how to configure JVM for clustering
chandankumar50 Mar 27, 2009 5:22 AMI want to develop a chatting application. By the help of this chatting application I want to demonstrate the multiple JVM clustering.
I hav developed a sample program by reading the user guide which allows to create a cache and add a node and data to it. It run fine when I run as a stand alone application.
But my requirement is that even when I start the second instance of the same program the data should persist in the memory.
I want my one instance of the program putting the data on cache and other instance of the same program receiving the data.
Any help wil be appreciated!!!
My code is as follows:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import org.jboss.cache.*;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.Configuration.CacheMode;
import org.jboss.cache.lock.IsolationLevel;
import org.jboss.cache.transaction.GenericTransactionManagerLookup;
/* created on : Mar 26, 2009
author : chandan */
public class TrialProgram {
Cache cache;
Configuration config;
CacheFactory factory;
public void config(){
config = new Configuration();
config.setTransactionManagerLookupClass(
GenericTransactionManagerLookup.class.getName() );
config.setIsolationLevel(IsolationLevel.READ_COMMITTED);
config.setCacheMode(CacheMode.LOCAL);
config.setLockAcquisitionTimeout(15000);
factory = new DefaultCacheFactory();
cache = factory.createCache(config);
cache.start();
}
public void putData(){
Node rootNode = cache.getRoot();
Fqn chatFqn = Fqn.fromString("/chatting");
// Create a new Node
Node chat = rootNode.addChild(chatFqn);
// let's store some data in the node
chat.put("isCartoonCharacter", Boolean.TRUE);
chat.put("favoriteDrink", "thums up");
}
public void getData(){
String tempStr;
Node rootNode = cache.getRoot();
Fqn chatFqn = Fqn.fromString("/chatting");
// Create a new Node
Node chat = rootNode.getChild(chatFqn);
// let's store some data in the node
tempStr=(String)chat.get("favoriteDrink");
System.out.println(tempStr);
}
public static void main(String args[]){
TrialProgram ob = new TrialProgram();
ob.config();
while(true) {
System.out.println("1 to put the Data");
System.out.println("2 to get the Data");
System.out.println("3 to exit");
Integer i=0;
try {
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
String s = br.readLine();
i = new Integer(s);
} catch(Exception e){
e.printStackTrace();
}
switch(i){
case 1 : ob.putData(); break;
case 2 : ob.getData(); break;
case 3 : System.exit(0);
}
}
}
}