1 Reply Latest reply on Sep 18, 2008 10:27 AM by Manik Surtani

    Application doesn't see additions/changes to cache made by o

    Twan Prive Newbie

      Good morning,

      I have a strange problem with my distributed cache:
      I have 2 applications that access the cache: app1 and app2
      - app1 starts and puts a objectX in the cache
      - app2 starts and sees the objectX in the cache
      - app1 puts objectY in cache
      - app2 doesn't sees objectY

      app2 does sees objectY only after i create the whole cache again:
      PojoCache cache = PojoCacheFactory.createCache("jbosscachetest/replSync-service.xml");

      I made a little test:

      public class MainApp {
       public MainApp(String[] args) {
       PojoCache cache = PojoCacheFactory.createCache("jbosscachetest/replSync-service.xml");
       ItemManager im = (ItemManager) cache.find("pojo/itemmanager");
       if (args[0].equals("create")) {
       if (im == null) {
       System.out.println("Creating itemmanger");
       cache.attach("pojo/itemmanager", new ItemManager());
       im = (ItemManager) cache.find("pojo/itemmanager");
       }
      
       im.addItem(new Item("twan"));
       im.addItem(new Item("marie"));
       try {
       System.out.println("Sleeping...");
       Thread.sleep(1000 * 10);
       }
       catch (InterruptedException ex) {
       }
       System.out.println("Adding joop");
       im.addItem(new Item("joop"));
       try {
       System.out.println("Sleeping...");
       Thread.sleep(1000 * 30);
       }
       catch (InterruptedException ex) {
       }
       }
       else if (args[0].equals("query")) {
       cache.addListener(new MyListener());
       while(true){
       System.out.println(im.getItem("joop"));
       try {
       Thread.sleep(1000 * 1);
       }
       catch (InterruptedException ex) {
       }
      
       }
       }
       }
      
       public static void main(String[] args) {
       MainApp mainapp = new MainApp(args);
       }
      }
      

      app1 is started with MainApp create
      app2 is started with MainApp query

      App2 only prints "null", but it should print "joop" after app1 added "joop" to the cache (after 10 seconds).

      My pojo's:

      @Replicable
       class ItemManager implements Serializable{
       ArrayList<Item> items;
       public ItemManager(){
       items=new ArrayList<Item>(10);
       }
       public void addItem(Item item){
       items.add(item);
       }
       public Item getItem(String name){
       for(Item i:items){
       if(i.getName().equals(name)){
       return i;
       }
       }
       return null;
       }
      
       public ArrayList getItems() {
       return items;
       }
      
       public void setItems(ArrayList items) {
       this.items = items;
       }
      }
      


      @Replicable
       class Item implements Serializable{
       String name;
       public Item(String name){
       this.name=name;
       }
       public String getName(){
       return name;
       }
       public void setName(String name){
       this.name=name;
       }
       public String toString(){
       return name;
       }
       }
      


      Can somebody offer me a helping hand?

      Thanks,
      Twan