2 Replies Latest reply on Jun 6, 2011 9:45 AM by ronsen

    Cache understanding

    ronsen

      Hello all,

       

      since im reading about Infinispan, I followed several tutorials and read in the docs. Everything works so far.

      But im still having problems in understanding what values/parts/etc. will be stored in distributed mode?

      Class variables? Objects?

       

      As for example, I wrote a small application, that sends messages to nodes, this message will be printed then with a counting number that will be incremented on serverside (Actually a typical example). Is it possible, that as for example the counting relies to the ejb's instead of sending the numbers from the client, that the numbers count continously even on failover? (1,2,3,4,failover,5,6,7) I couldnt observer this in testing -> (1,2,3,4,failover,1,2,3).

       

      Therefore I'd like to know, what exactly will be cached.

       

      Thanks a lot in advance,

        • 1. Re: Cache understanding
          sannegrinovero
          since im reading about Infinispan, I followed several tutorials and read in the docs. Everything works so far.

          But im still having problems in understanding what values/parts/etc. will be stored in distributed mode?

          Class variables? Objects?

          Both the Object that you pass as key as and the Object that you pass as value will be stored directly in the cache (not it's fields). To be sent to other nodes they will be transformed in byte[] by using Serialization or a custom Externalizer if you defined one.

           

          Then, depending on your configuration, it might be re-transformed in an object as a soon as possible, or stored in it's byte[] form. Of course each time the user-API asks for the object then it will be deserialized if needed, or you get a direct reference to the instance if one is available.

           

           

          As for example, I wrote a small application, that sends messages to nodes, this message will be printed then with a counting number that will be incremented on serverside (Actually a typical example). Is it possible, that as for example the counting relies to the ejb's instead of sending the numbers from the client, that the numbers count continously even on failover? (1,2,3,4,failover,5,6,7) I couldnt observer this in testing -> (1,2,3,4,failover,1,2,3).

          I'm sorry I'm not sure I understood your example, could you elaborate on it? How are you sending messages (with other means or using Infinispan commands?) ? Where is the message printed?

          The data in Infinispan does failover, if you don't see the failover in action, are you sure the nodes are connected? You should see logs about members joining the cluster when you start multiple nodes.

          • 2. Re: Cache understanding
            ronsen

            Hey Sanne,

             

            tahnks for your reply.

            I think it clarifies a lot if i get deeper into the example, because it seems you understood ut a bit wrong.

             

            At first, I have a client node, that starts a method "printCount" in a loop on an EJB that prints a count in a loop and prints. The EJB is deployed on all nodes through the farming service.

             

            Simple client extract:

             

            ctx = new 
            
            
            
            InitialContext(env);
            
            
            Failover f = (Failover) 
            
            ctx.lookup("ejb/FailoverBean" 
            
            
            );
            
            
            
            
            
            for(int 
            
            
            i = 0; i< 5000; 
            i++){
            
            
            f.printCount(i);
            Thread.sleep(1000);
            }
            
            

             

            The ejb then prints the message to the console.

             

            public int count;
            public void printCount(int counter){String host = 
            null;
            try {host = InetAddress.getLocalHost().getHostAddress();
            } 
            catch (UnknownHostException e) {e.printStackTrace();
            }
            
            
            count++;System.
            out.println(count+" from: "+host);}
            
            
            

             

            this is the most important actually. Whenever i start it, the loadbalancing policy in

            @Clustered

            (loadBalancePolicy="FirstAvailable")  applies. I can kick out servers and the failover applies. Thats the point were my question starts.

             

            If i kick out one of the nodes, the counting swaps to another node and continues BUT not with the value, were the other node stopped but from 0.

            If I do the incrementation of the value inside the node as in the above example(before i handed over the value from the client), the node continues with the value were it stopped on that node.

             

            My question is there a possibility to cache the "state" of it and let the other node on failover continue with it?

             

            Thanks in advance,

             

             

             

            One remark: It would be best if i could store it so that i dont have to call the cache manager or first having to call other methods to store the state somewhere. Probably a specific datatype or something would be best? Does Infinispan probably provide that?