Permalink
Browse files

Fixed FD_ICMP (https://issues.jboss.org/browse/JGRP-1380)

  • Loading branch information...
1 parent 2720767 commit 699b4a58650def73a855456f4e30cd766b3de041 Bela Ban committed Oct 27, 2011
Showing with 27 additions and 29 deletions.
  1. +1 −0 conf/jg-protocol-ids.xml
  2. +3 −0 src/org/jgroups/protocols/FD.java
  3. +23 −29 src/org/jgroups/protocols/FD_ICMP.java
View
@@ -27,6 +27,7 @@
<class id="25" name="org.jgroups.protocols.ENCRYPT"/>
<class id="26" name="org.jgroups.protocols.SEQUENCER"/>
<class id="27" name="org.jgroups.protocols.FD_SIMPLE"/>
+ <class id="28" name="org.jgroups.protocols.FD_ICMP"/>
<class id="29" name="org.jgroups.protocols.FD_ALL"/>
<class id="31" name="org.jgroups.protocols.pbcast.FLUSH"/>
<class id="33" name="org.jgroups.protocols.AUTH"/>
@@ -192,6 +192,9 @@ private void stopMonitor() {
}
}
+ @ManagedAttribute(description="Whether the failure detection monitor is running",writable=false)
+ public boolean isMonitorRunning() {return monitor_future != null && !monitor_future.isDone();}
+
/** Restarts the monitor if the ping destination has changed. If not, this is a no-op.
* Requires lock to be held by the caller */
@GuardedBy("lock")
@@ -2,25 +2,24 @@
import org.jgroups.Event;
import org.jgroups.Global;
+import org.jgroups.PhysicalAddress;
import org.jgroups.annotations.Experimental;
import org.jgroups.annotations.LocalAddress;
import org.jgroups.annotations.Property;
import org.jgroups.conf.PropertyConverters;
import org.jgroups.stack.IpAddress;
-import org.jgroups.util.Util;
-import java.lang.reflect.Method;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.Map;
/**
* Protocol which uses InetAddress.isReachable() to check whether a given host
* is up or not, taking 1 argument; the host name of the host to be pinged.
- * <em>Note that this protocol only works with JDK 5 !</em> The implementation
+ * <em>Note that this protocol only works with a JDK version >= 5 !</em> The implementation
* of this may or may not use ICMP ! An alternative is to create a TCP
* connection to port 7 (echo service) and see whether it works ! This is
- * obviously done in JDK 5, so unless an echo service is configured to run, this
+ * done in JDK 5, so unless an echo service is configured to run, this
* won't work...
*
* @author Bela Ban
@@ -42,36 +41,18 @@
description="The interface (NIC) which should be used by this transport", dependsUpon="bind_addr")
protected String bind_interface_str=null;
- private Method is_reacheable;
-
/** Time-to-live for InetAddress.isReachable() */
@Property
- private int ttl=32;
+ protected int ttl=32;
public void init() throws Exception {
super.init();
if(bind_addr != null)
intf=NetworkInterface.getByInetAddress(bind_addr);
-
- try {
- Class<?> is_reacheable_class=Util.loadClass("java.net.InetAddress", this.getClass());
- is_reacheable=is_reacheable_class.getMethod("isReachable", NetworkInterface.class, int.class, int.class);
- }
- catch(ClassNotFoundException e) {
- // should never happen since we require JDK 1.5
- Error error=new NoClassDefFoundError("failed checking for InetAddress.isReachable() method - requires JDK 5 or higher");
- error.initCause(e);
- throw error;
- }
- catch(NoSuchMethodException e) {
- // log.error("didn't find InetAddress.isReachable() method - requires JDK 5 or higher");
- Error error=new NoSuchMethodError("didn't find InetAddress.isReachable() method - requires JDK 5 or higher");
- error.initCause(e);
- throw error;
- }
}
+ @SuppressWarnings("unchecked")
public Object up(Event evt) {
switch(evt.getType()) {
case Event.CONFIG:
@@ -101,27 +82,40 @@ public void run() {
if(ping_dest == null) {
if(log.isWarnEnabled())
log.warn("ping_dest is null: members=" + members + ", pingable_mbrs=" +
- pingable_mbrs + ", local_addr=" + local_addr);
+ pingable_mbrs + ", local_addr=" + local_addr);
return;
}
// 1. execute ping command
- InetAddress host=ping_dest instanceof IpAddress? ((IpAddress)ping_dest).getIpAddress() : null;
+ InetAddress host=null;
+ PhysicalAddress physical_addr;
+ if(ping_dest instanceof PhysicalAddress) {
+ physical_addr=(PhysicalAddress)ping_dest;
+ }
+ else {
+ physical_addr=(PhysicalAddress)down_prot.down(new Event(Event.GET_PHYSICAL_ADDRESS, ping_dest));
+ }
+
+ if(physical_addr == null)
+ log.warn("failed fetching physical address for " + ping_dest);
+ else
+ host=((IpAddress)physical_addr).getIpAddress();
+
if(host == null)
throw new IllegalArgumentException("ping_dest is not of type IpAddress - FD_ICMP only works with these");
try {
if(log.isTraceEnabled())
log.trace("pinging " + host + " (ping_dest=" + ping_dest + ") using interface " + intf);
start=System.currentTimeMillis();
- Boolean rc=(Boolean)is_reacheable.invoke(host, intf, new Integer(ttl), new Integer((int)timeout));
+ boolean rc=host.isReachable(intf, ttl,(int)timeout);
stop=System.currentTimeMillis();
num_heartbeats++;
- if(rc.booleanValue()) { // success
+ if(rc) {
num_tries=0;
if(log.isTraceEnabled())
log.trace("successfully received response from " + host + " (after " + (stop-start) + "ms)");
}
- else { // failure
+ else {
num_tries++;
if(log.isDebugEnabled())
log.debug("could not ping " + ping_dest + " (tries=" + num_tries + ") after " + (stop-start) + "ms)");

0 comments on commit 699b4a5

Please sign in to comment.