2nd cache not replicated at startup
kburns Sep 10, 2004 3:14 AMHi,
I'm having problems with replication at startup of a second cache.
Using the code below, I'm starting 2 CacheTest applications (each configured as a replicated asyn service), one as a server the other as a client.
1. I start the server first, it adds objects into the cache (under /a/b) ok. After these objects have been added, I start the client and query it for objects under /a/b. The getChildrenNames() returns null.
2. I start the client first, then start the server, objects are added into both caches ok.
The xml config file "META-INF/replAsync-service.xml" is unchanged from the release.
Each CacheTest is started from a separate DOS window under Windows XP with Java 1.4.2 under the same host (PC).
I'm at a loss for why the client is not being replicated upon its startup (case 1).
Any help is much appreciated.
Many Thanks.
import org.jboss.cache.*;
import org.jboss.cache.aop.TreeCacheAop;
import org.jboss.cache.lock.*;
import java.lang.System.*;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.Set;
public class CacheTest implements TreeCacheListener
{
 public TreeCacheAop myTree;
 public String myType;
 public CacheTest(String theCacheType)
 {
 System.out.println("Start");
 myType = theCacheType;
 try
 {
 myTree = new TreeCacheAop();
 myTree.addTreeCacheListener(this);
 PropertyConfigurator config = new PropertyConfigurator(); // configure tree cache.
 config.configure(myTree, "META-INF/replAsync-service.xml");
 myTree.setClusterName("vtest");
 long time0 = System.currentTimeMillis();
 myTree.start();
 if (theCacheType.compareTo("server") == 0)
 {
 createObjects();
 }
 long time1 = System.currentTimeMillis();
 long time = time1 - time0;
 System.out.println("Start Service took [" + time + "]");
 }
 catch (Exception excep)
 {
 System.out.println("Exception");
 }
 System.out.println("End");
 }
 public void cacheStopped(TreeCache theCache)
 {
 }
 public void cacheStarted(TreeCache theCache)
 {
 System.out.println("cacheStarted");
 }
 public void nodeCreated(Fqn theFqn)
 {
 System.out.println("nodeCreated");
 }
 public void nodeVisited(Fqn theFqn)
 {
 }
 public void nodeRemoved(Fqn theFqn)
 {
 }
 public void nodeEvicted(Fqn theFqn)
 {
 }
 public void nodeLoaded(Fqn theFqn)
 {
 System.out.println("nodeLoaded");
 }
 public void nodeModified(Fqn theFqn)
 {
 }
 public void viewChange(org.jgroups.View new_view)
 {
 }
 public void queryCache()
 {
 try
 {
 // Query for names
 Set aset = myTree.getChildrenNames("/a/b");
 if (aset == null)
 {
 System.out.println("Cache contents is EMPTY");
 }
 else
 {
 System.out.println("Cache contents = " + aset.toString());
 }
 }
 catch (LockingException excep)
 {
 System.out.println("query cache LockingException");
 }
 catch (TimeoutException excep)
 {
 System.out.println("query cache TimeoutException");
 }
 }
 public void stopCache()
 {
 myTree.stop();
 }
 public static void main(String args[])
 {
 System.out.println("args=" + args[0]);
 CacheTest ct = new CacheTest(args[0]);
 String line;
 BufferedReader keyInput = new BufferedReader(new InputStreamReader(System.in));
 System.out.println("Options:");
 System.out.println("1 exit");
 System.out.println("2 ...");
 try
 {
 while ((line = keyInput.readLine()) != null)
 {
 if (line.compareTo("1") == 0)
 {
 ct.stopCache();
 break;
 }
 else if (line.compareTo("3") == 0)
 {
 ct.queryCache();
 }
 System.out.println("Options:");
 System.out.println("1 = exit");
 System.out.println("2 = start cache");
 System.out.println("3 = query cache");
 System.out.print("Enter Option: ");
 }
 }
 catch (IOException exception)
 {
 }
 }
public void createObjects()
{
.... create an object, "object" ...
 try
 {
 myTree.putObject("/a/b", object);
 }
 catch (Exception excpt)
 {
 }
}
}
 
    