From: Tom E. <te...@us...> - 2004-12-20 18:56:42
|
User: telrod Date: 04/12/20 10:56:33 Modified: src/main/org/jboss/remoting/detection AbstractDetector.java AbstractDetectorMBean.java Log: JBREM-17: Updated to allow for better configuration of detectors, added throwing of CannotConnectExceptions within transports, and updated tests cases. Revision Changes Path 1.17 +73 -17 jboss-remoting/src/main/org/jboss/remoting/detection/AbstractDetector.java Index: AbstractDetector.java =================================================================== RCS file: /cvsroot/jboss/jboss-remoting/src/main/org/jboss/remoting/detection/AbstractDetector.java,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- AbstractDetector.java 4 Nov 2004 06:42:12 -0000 1.16 +++ AbstractDetector.java 20 Dec 2004 18:56:33 -0000 1.17 @@ -17,6 +17,7 @@ import org.jboss.remoting.ident.Identity; import org.jboss.remoting.network.NetworkRegistryFinder; import org.jboss.remoting.transport.ClientInvoker; +import org.jboss.system.ConfigurationException; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; @@ -30,13 +31,13 @@ * AbstractDetector * * @author <a href="mailto:jh...@vo...">Jeff Haynie</a> - * @version $Revision: 1.16 $ + * @author <a href="mailto:tom...@jb...">Tom Elrod</a> + * @version $Revision: 1.17 $ */ public abstract class AbstractDetector implements Detector, AbstractDetectorMBean { - protected static final boolean DETECTOR_DEBUG = Boolean.getBoolean("jboss.remoting.detector.debug"); - private static final long DEFAULT_TIME_DELAY = Integer.parseInt(System.getProperty("jboss.remoting.detector.ping", "5000")); - private static final long HEARTBEAT_TIME_DELAY = Integer.parseInt(System.getProperty("jboss.remoting.detector.heartbeat", "1000")); + private long defaultTimeDelay = 5000; + private long heartbeatTimeDelay = 1000; protected final Logger log = Logger.getLogger(getClass()); protected MBeanServer mbeanserver; protected ObjectName objectName; @@ -46,7 +47,6 @@ private Timer heartbeatTimer; private Timer failureTimer; private Map servers = new HashMap(); - private long maxTimeDelay = DEFAULT_TIME_DELAY; private Element xml; private Set domains = new HashSet(); @@ -54,6 +54,62 @@ { } + /** + * The amount of time to wait between sending (and sometimes receiving) detection messages. + * @param heartbeatTimeDelay + * @throws ConfigurationException + */ + public void setHeartbeatTimeDelay(long heartbeatTimeDelay) throws ConfigurationException + { + if(heartbeatTimeDelay > 0 && heartbeatTimeDelay < defaultTimeDelay) + { + this.heartbeatTimeDelay = heartbeatTimeDelay; + } + else + { + throw new ConfigurationException("Can not set heartbeat time delay (" + heartbeatTimeDelay + ") to a negative number or " + + "to a number greater than the default time delay (" + defaultTimeDelay + ")."); + } + } + + /** + * The amount of time to wait between sending (and sometimes receiving) detection messages. + * @return + */ + public long getHeartbeatTimeDelay() + { + return heartbeatTimeDelay; + } + + /** + * The amount of time which can elapse without receiving a detection event before a server + * will be suspected as being dead and peroforming an explicit invocation on it to verify it is alive. + * @param defaultTimeDelay time in milliseconds + * @throws ConfigurationException + */ + public void setDefaultTimeDelay(long defaultTimeDelay) throws ConfigurationException + { + if(defaultTimeDelay >= heartbeatTimeDelay) + { + this.defaultTimeDelay = defaultTimeDelay; + } + else + { + throw new ConfigurationException("Can not set the default time delay (" + defaultTimeDelay + ") to be less" + + " than that of the heartbeat time delay (" + heartbeatTimeDelay + ")."); + } + } + + /** + * + * @return The amount of time which can elapse without receiving a detection event before a server + * will be suspected as being dead and peroforming an explicit invocation on it to verify it is alive. + */ + public long getDefaultTimeDelay() + { + return defaultTimeDelay; + } + /** * called by MBeanServer to start the mbean lifecycle * @@ -268,7 +324,7 @@ */ protected long getHeartbeatPeriod() { - return HEARTBEAT_TIME_DELAY; + return heartbeatTimeDelay; } /** @@ -284,11 +340,11 @@ */ protected void detect(Detection detection) { - if(DETECTOR_DEBUG && log.isDebugEnabled()) + if(log.isTraceEnabled()) { - log.debug("Detection message received."); - log.debug("Id = " + detection.getIdentity().getInstanceId()); - log.debug("isRemoteDetection() = " + isRemoteDetection(detection)); + log.trace("Detection message received."); + log.trace("Id = " + detection.getIdentity().getInstanceId()); + log.trace("isRemoteDetection() = " + isRemoteDetection(detection)); } // we only track detections within our own domain and not ourself if(isRemoteDetection(detection)) @@ -314,7 +370,7 @@ } if(found == false) { - if(DETECTOR_DEBUG && log.isDebugEnabled()) + if(log.isDebugEnabled()) { log.debug("detected NEW server: " + detection.getIdentity()); } @@ -326,9 +382,9 @@ { // update hash server.rehash(detection); - if(DETECTOR_DEBUG && log.isDebugEnabled()) + if(log.isTraceEnabled()) { - log.debug("detected UPDATE for server: " + detection.getIdentity()); + log.trace("detected UPDATE for server: " + detection.getIdentity()); } mbeanserver.invoke(registryObjectName, "updateServer", new Object[]{detection.getIdentity(), detection.getLocators()}, new String[]{Identity.class.getName(), InvokerLocator[].class.getName()}); } @@ -343,9 +399,9 @@ log.error("Error during detection of: " + detection, e); } } - else if(DETECTOR_DEBUG && log.isDebugEnabled()) + else if(log.isTraceEnabled()) { - log.debug("detection from myself - ignored"); + log.trace("detection from myself - ignored"); } } @@ -447,11 +503,11 @@ lastDetection = server.lastDetection; } long duration = System.currentTimeMillis() - lastDetection; - if(duration >= maxTimeDelay) + if(duration >= defaultTimeDelay) { if(log.isDebugEnabled()) { - log.debug("detection for: " + detection + " has not been received in: " + maxTimeDelay + " ms, contacting.."); + log.debug("detection for: " + detection + " has not been received in: " + defaultTimeDelay + " ms, contacting.."); } // OK, we've exceeded the time delay since the last time we've detected // this dude, he might be down, let's walk through each of his transports and 1.2 +28 -0 jboss-remoting/src/main/org/jboss/remoting/detection/AbstractDetectorMBean.java Index: AbstractDetectorMBean.java =================================================================== RCS file: /cvsroot/jboss/jboss-remoting/src/main/org/jboss/remoting/detection/AbstractDetectorMBean.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- AbstractDetectorMBean.java 16 Jul 2003 05:56:19 -0000 1.1 +++ AbstractDetectorMBean.java 20 Dec 2004 18:56:33 -0000 1.2 @@ -1,6 +1,7 @@ package org.jboss.remoting.detection; import org.w3c.dom.Element; +import org.jboss.system.ConfigurationException; /** * This provides a MBean accessible interface for setting domain configuration @@ -28,4 +29,31 @@ */ public Element getConfiguration(); + /** + * The amount of time to wait between sending (and sometimes receiving) detection messages. + * @param heartbeatTimeDelay + * @throws org.jboss.system.ConfigurationException + */ + void setHeartbeatTimeDelay(long heartbeatTimeDelay) throws ConfigurationException; + + /** + * The amount of time to wait between sending (and sometimes receiving) detection messages. + * @return + */ + long getHeartbeatTimeDelay(); + + /** + * The amount of time which can elapse without receiving a detection event before a server + * will be suspected as being dead and peroforming an explicit invocation on it to verify it is alive. + * @param defaultTimeDelay time in milliseconds + * @throws org.jboss.system.ConfigurationException + */ + void setDefaultTimeDelay(long defaultTimeDelay) throws ConfigurationException; + + /** + * + * @return The amount of time which can elapse without receiving a detection event before a server + * will be suspected as being dead and peroforming an explicit invocation on it to verify it is alive. + */ + long getDefaultTimeDelay(); } |