1 Reply Latest reply on Jan 19, 2010 5:21 AM by ustaudinger

    Replication: simplest assumption not working ... with source code ...

           Hi there,

       

      I want to use the replication of objects. Unfortunately I do not get it running properly.

       

      I have one server, to which multiple clients connect over JGroups/TCP.

       

      The following classes are the code I use.

       

      Problem description:

      The initial lookup in the client succeeds and it contains a snapshot of object when the lookup occured. Later set calls on the server are not updating the object on the client side.

       

      However, when decomment in the server spot [1] and move in the client the find into the loop, then I see that it works.

       

      ???

       

      Any help appreciated. I somehow have the impression that the client state is not transferred upon calling a setter on the server side. Mind that in my scenario, only the server side will set values and the clients will be receiving these values. Actually I want to use the pojo cache to easily push an object tree over the wire to a bunch of clients. As only some values change from time to time, sending the full object tree might be too much.

       

      Thanks,

      Ulrich

       

       

       

      The Server app:

       

       

      @PojoCacheListener
      public class JbossCacheLayer
      {
          private transient Cache cache;
          private transient CacheModelDelegate cacheModelDelegate;
          private transient Node root;
          private TransactionManager txManager;
          private transient Transaction tx;
          private Quotes quotes = new Quotes();
      
          @Attached
          public void handleAttached(AttachedEvent event)
          {
              System.out.println("Attached = " + event.getSource());
          }
      
          
          
          @Attached
          @Detached
          @FieldModified
          @ListModified
          @MapModified
          @SetModified
          @TransactionRegistered
          @TransactionCompleted    
          public void handleAll(Event event)
          {
              System.out.println(event);
          }
          
          @NodeCreated
          public void handleNodeCreated(NodeCreatedEvent event)
          {
              System.out.println(event);
          }
          
          @NodeRemoved
          public void handleNodeRemoved(NodeRemovedEvent event)
          {
              System.out.println(event);
          }
          
          @NodeModified
          public void handleNodeModified(NodeModifiedEvent event)
          {
              System.out.println(event);
          }
          
          @NodeEvicted
          public void handleNodeEvent(NodeEvictedEvent event)
          {
              System.out.println(event);
          }
          
          
      
          public JbossCacheLayer()
              throws Exception
          {     
              PojoCache pc = PojoCacheFactory.createCache("replSync.xml", true);
              
              pc.addListener(this);
              pc.addListener(this, Pattern.compile("pojos/quotes"));
             
              
              Quotes q = new Quotes();
              pc.attach(Fqn.fromString("pojos/quotes"), q);
              
              q = (Quotes)pc.find(Fqn.fromString("pojos/quotes"));
              List list = q.getQuotes();
              
              //cache.put(Fqn.fromString("Test"+Math.random()), null);        
              
              while(true)
              {
                  
                  q.getQuotes().add("TEST");
                  q.setRand(Math.random());  
                  // [1]    pc.attach(Fqn.fromString("pojos/quotes"), q);
                  Thread.sleep(1000);            
              }
              
          }
      
          public static void main(String[] args)
              throws Exception
          {
              new JbossCacheLayer();
          }
      
      }
      

       

       

      The client app:

       

      
      public class JbossCacheClient
      {
          
          public JbossCacheClient()
              throws Exception
          {
            
              PojoCache pc = PojoCacheFactory.createCache("replSync.xml", true);        
              Quotes q = (Quotes)pc.find(Fqn.fromString("pojos/quotes"));
              
              while(true)
              {          
                  System.out.println(q.getRand());
                  System.out.println(q.getQuotes().size());            
                  Thread.sleep(1000);            
              }
              
            
          }
      
          public static void main(String[] args) throws Exception
          {
              new JbossCacheClient();
          }
      
      }
      
        • 1. Re: Replication: simplest assumption not working ... with source code ...

          forgot to add the aop.xml file to the java executable ..

          -Djboss.aop.path=./src/main/resources/pojocache-aop.xml

           

          Now i can see in the console:

          updated to 0.7900468852042599
          org.jboss.cache.pojo.notification.event.FieldModifiedEvent[source=com.imc.fo.venus.containers.Quotes@56f0cb3c]
          updated to 0.3239987967102794
          org.jboss.cache.pojo.notification.event.FieldModifiedEvent[source=com.imc.fo.venus.containers.Quotes@56f0cb3c]

           

          However, the second computer can't find the object.