hi,
I'm trying to use DistributedStateCache in shoal. I wrote a SimpleTest class as follows.
import java.io.Serializable;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.List;
import java.util.Properties;
import java.util.Vector;
import com.sun.enterprise.ee.cms.core.CallBack;
import com.sun.enterprise.ee.cms.core.DistributedStateCache;
import com.sun.enterprise.ee.cms.core.GMSException;
import com.sun.enterprise.ee.cms.core.GMSFactory;
import com.sun.enterprise.ee.cms.core.GroupManagementService;
import com.sun.enterprise.ee.cms.core.ServiceProviderConfigurationKeys;
import com.sun.enterprise.ee.cms.core.Signal;
import com.sun.enterprise.ee.cms.core.SignalAcquireException;
import com.sun.enterprise.ee.cms.core.SignalReleaseException;
import com.sun.enterprise.ee.cms.impl.client.FailureNotificationActionFactoryImpl;
import com.sun.enterprise.ee.cms.impl.client.JoinNotificationActionFactoryImpl;
import com.sun.enterprise.ee.cms.impl.client.MessageActionFactoryImpl;
import com.sun.enterprise.ee.cms.impl.client.MessageActionImpl;
public class SimpleTest implements CallBack{
public GroupManagementService gms;
public static void main(String[] args) {
SimpleTest simpleTest = new SimpleTest();
try {
String serverName = args[0];
Properties configProps = new Properties();
configProps.put(ServiceProviderConfigurationKeys.MULTICASTADDRESS.toString(), "229.9.1.1");
configProps.put(ServiceProviderConfigurationKeys.MULTICASTPORT.toString(),2299);
simpleTest.gms=(GroupManagementService) GMSFactory.startGMSModule(serverName,
"DemoGroup", GroupManagementService.MemberType.CORE, configProps);
simpleTest.gms.addActionFactory(new JoinNotificationActionFactoryImpl(simpleTest));
simpleTest.gms.addActionFactory(new FailureNotificationActionFactoryImpl(simpleTest));
simpleTest.gms.addActionFactory(new MessageActionFactoryImpl(simpleTest), "DemoComponent");
simpleTest.gms.join();
Vector<String> value = new Vector<String>();
value.add(serverName+"apple");
DistributedStateCache dsc = simpleTest.gms.getGroupHandle().getDistributedStateCache();
dsc.addToCache("DemoComponent", serverName, serverName, value);
new Thread(simpleTest.new SimpleEcho(simpleTest.gms)).start();
} catch (GMSException e) {
e.printStackTrace();
}
}
public void processNotification(Signal notification) {
try {
notification.acquire();
System.out.println("leader:"+gms.getGroupHandle().getGroupLeader());
notification.release();
} catch (SignalAcquireException e) {
e.printStackTrace();
} catch (SignalReleaseException e) {
e.printStackTrace();
}
}
class SimpleEcho implements Runnable{
private GroupManagementService gms;
private DistributedStateCache dsc;
private Vector<String> hosts;
public SimpleEcho(GroupManagementService gms){
this.gms = gms;
this.hosts = new Vector<String>();
hosts.add("133.133.133.30");
hosts.add("133.133.133.94");
hosts.add("133.133.133.95");
hosts.add("133.133.133.123");
}
public void run() {
while(true){
try {
Thread.sleep(5000);
Object obj = null;
Vector<String> value = null;
dsc = gms.getGroupHandle().getDistributedStateCache();
for(int i=0;i<hosts.size();i++){
obj = dsc.getFromCache("DemoComponent",hosts.elementAt(i),(hosts.elementAt(i)));
if(obj != null){
value = (Vector<String>) obj;
for(int j=0;j<value.size();j++)
System.out.println(value.elementAt(j));
}
}
System.out.println("leader:"+gms.getGroupHandle().getGroupLeader());
} catch (InterruptedException e) {
e.printStackTrace();
} catch (GMSException e) {
e.printStackTrace();
}
}
}
}
}
Then, I type java SimpleTest 133.133.133.94 on machineA(133.133.133.94), and type java SimpleTest 133.133.133.95 on machineB(133.133.133.95).
The console prints infos like this:
machineA:
133.133.133.30apple
133.133.133.94apple
leader:133.133.133.30
...
machineB:
133.133.133.30apple
leader:133.133.133.30
...
Why machineB can't get machineA's info? It seems that machineA and machineB have different dsc view. How to get the same dsc view?
From the console, I know machineA and machineB have the same member view, i.e. they can discover each other.
--------------
leehui
2008-04-18