9 Replies Latest reply on Sep 19, 2005 2:32 AM by belaban

    Distinguishing members

    motormind

      I have two sorts of processes using a certain cache: some non-interactive (functioning more like servers) and interactive ones with a gui. How can I distinguish between the two when I see a view change? I tried to distinguish by hostname, but that is not possible since both the clients and the servers can run on the same machine. Then I tried to distinguish by port namne, but I have no idea how a member can find out its own port under which it made a cache.

      Does anyone have any insights? Thanks in advance!

        • 1. Re: Distinguishing members
          belaban

          You can attach some bytes to a JGroups IpAddress, check out HAPartitionImpl in JBoss for how to do this

          • 2. Re: Distinguishing members
            motormind

             

            "bela@jboss.com" wrote:
            You can attach some bytes to a JGroups IpAddress, check out HAPartitionImpl in JBoss for how to do this


            I thought about that, but didn't see a way to obtain the IP-address & port of a process that uses the cache.

            • 3. Re: Distinguishing members
              belaban

              TreeCache.getLocalAddress() return an instance of org.jgroups.stack.IpAddress. The problem is that JBoss already uses the additional bytes to stick the logical node name into the IpAddress...

              • 4. Re: Distinguishing members
                motormind

                 

                "bela@jboss.com" wrote:
                TreeCache.getLocalAddress() return an instance of org.jgroups.stack.IpAddress. The problem is that JBoss already uses the additional bytes to stick the logical node name into the IpAddress...


                Hmm.. TreeCache.getLocalAddress() actually returns a null on my system

                • 5. Re: Distinguishing members
                  belaban

                  Only when the cache is replicated; and started

                  • 6. Re: Distinguishing members
                    motormind

                     

                    "bela@jboss.com" wrote:
                    Only when the cache is replicated; and started


                    Right. So how amd I going to distinguish between members?

                    • 7. Re: Distinguishing members
                      belaban

                      Look at AddDataTest:

                      JChannel c=new JChannel(properties);
                       Map m=new HashMap();
                       m.put("additional_data", new byte[]{'b', 'e', 'l', 'a'});
                       c.down(new Event(Event.CONFIG, m));
                       c.connect("bla");
                       IpAddress addr=(IpAddress)c.getLocalAddress();
                       System.out.println("address is " + addr);
                       assertNotNull(addr.getAdditionalData());
                       assertEquals(addr.getAdditionalData()[0], 'b');
                      


                      IpAddress.getAdditionalData() returns a byte[] buffer, that you can use

                      • 8. Re: Distinguishing members
                        motormind

                         

                        "bela@jboss.com" wrote:
                        Look at AddDataTest:
                        JChannel c=new JChannel(properties);
                         Map m=new HashMap();
                         m.put("additional_data", new byte[]{'b', 'e', 'l', 'a'});
                         c.down(new Event(Event.CONFIG, m));
                         c.connect("bla");
                         IpAddress addr=(IpAddress)c.getLocalAddress();
                         System.out.println("address is " + addr);
                         assertNotNull(addr.getAdditionalData());
                         assertEquals(addr.getAdditionalData()[0], 'b');
                        


                        IpAddress.getAdditionalData() returns a byte[] buffer, that you can use


                        But you're saying that it is already used by JBoss Cache... won't it upset the system when I set it myself?

                        • 9. Re: Distinguishing members
                          belaban

                          No, it is not used by JBossCache; it is used by JBoss Clustering. So for JBossCache, the additional data is available.
                          Another solution would be to replicate the information whether a node is a client or server across the cluster using clustering or cache, this is probably more portable and you don't need to worry about who's using additional_data.