Question

I have a few server that is mirrored with JGroup. Recently there are some unexpected behavior where it is out of synch and base on the log, the Jgroup will disconnect from time to time. I would like to write a small program within the JGroup code to email out once the JGroup has disconnected and report which machine has disconnected.

The problem is, Base on the JavaDoc i cant seem to able to extract the Physical IP Address from the Member or View. Anyone knows how can i do that?

Was it helpful?

Solution

This is a hack, but it works. The JGroups team has stated that this is dangerous as they could change the underlying code at any time, so use with caution.

public void receive(Message msg) {
    String srcIp;   
    Address addr = msg.getSrc();

    PhysicalAddress physicalAddr = (PhysicalAddress)channel.down(new Event(Event.GET_PHYSICAL_ADDRESS, addr));

    if(physicalAddr instanceof IpAddress) {
        IpAddress ipAddr = (IpAddress)physicalAddr;
        InetAddress inetAddr = ipAddr.getIpAddress();
        srcIp = inetAddr.getHostAddress();
    }
}

OTHER TIPS

To elaborate Cavyn VonDeylen's approach: to get the physical address of a given channel

jgroups 2.x:

PhysicalAddress physicalAddress = (PhysicalAddress) 
      channel.downcall(
        new Event(
          Event.GET_PHYSICAL_ADDRESS, channel.getAddress()
        )
      );

jgroups 3.x: Channel.downcall() has been removed; so Channel.down() has been changed to replace former's functionality.

PhysicalAddress physicalAddress = (PhysicalAddress) 
      channel.down(
        new Event(
          Event.GET_PHYSICAL_ADDRESS, channel.getAddress()
        )
      );

Irrespectively of any jgroups version, the physicalAddress will return a String in the form of IP:port format.

I'm not sure you can, I wasn't able to figure out how either. What I ended up doing is adding the node's IP as part of the broadcast message. It requires some extra coding, but it works.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top