3

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?

skaffman
  • 398,947
  • 96
  • 818
  • 769
Reusable
  • 1,888
  • 7
  • 27
  • 46
  • Excuse my ignorance - but why isn't the channel physical address the same as the node physical address (that you can get using InetAddress)? – Ran Biron Jun 14 '12 at 14:13

3 Answers3

3

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();
    }
}
Cavyn VonDeylen
  • 4,189
  • 9
  • 37
  • 52
1

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.

ecle
  • 3,952
  • 1
  • 18
  • 22
0

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.

robertvoliva
  • 902
  • 6
  • 6
  • I concur. `JGroups` doesn't provide a direct method to retrieve a channel's physical address – ee. Dec 05 '11 at 09:21