From: Tom E. <tom...@jb...> - 2006-07-03 18:55:37
|
User: telrod Date: 06/07/03 14:55:32 Modified: src/main/org/jboss/remoting/detection/multicast MulticastDetector.java Log: JBREM-532 - updated detector api to include method to synchronously get the servers on a network. Revision Changes Path 1.8 +52 -7 JBossRemoting/src/main/org/jboss/remoting/detection/multicast/MulticastDetector.java (In the diff below, changes in quantity of whitespace are not shown.) Index: MulticastDetector.java =================================================================== RCS file: /cvsroot/jboss/JBossRemoting/src/main/org/jboss/remoting/detection/multicast/MulticastDetector.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -b -r1.7 -r1.8 --- MulticastDetector.java 1 Jun 2006 15:57:05 -0000 1.7 +++ MulticastDetector.java 3 Jul 2006 18:55:32 -0000 1.8 @@ -40,7 +40,7 @@ * @author <a href="mailto:jh...@vo...">Jeff Haynie</a> * @author <a href="mailto:adr...@ha...">Adrian Brock</a> * @author <a href="mailto:tom...@jb...">Tom Elrod</a> - * @version $Revision: 1.7 $ + * @version $Revision: 1.8 $ */ public class MulticastDetector extends AbstractDetector implements MulticastDetectorMBean { @@ -234,6 +234,41 @@ } } + protected void forceHeartbeat() + { + if(socket != null) + { + String msg = "Send heartbeat"; + try + { + ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); + ObjectOutputStream objectOut = new ObjectOutputStream(byteOut); + objectOut.writeObject(msg); + objectOut.flush(); + byteOut.flush(); + byte buf[] = byteOut.toByteArray(); + DatagramPacket p = new DatagramPacket(buf, buf.length, addr, port); + socket.send(p); + + /** + * This is a bit of a hack, but am going to wait a few seconds to + * allow for any group members (other multicast detectors) to receive + * the msg and then respond themselves with their detection messages. + * Since don't know number of servers that are members of the group, + * can't really wait until all detection messages, just hope they come + * in before end of waiting. + */ + Thread.currentThread().sleep(2000); + + } + catch(Throwable ex) + { + // its failed + log.debug("forced heartbeat failed", ex); + } + } + } + private void listen(DatagramPacket p, byte[] buf) { if(socket != null) @@ -246,7 +281,10 @@ // take the multicast, and deserialize into the detection event ByteArrayInputStream byteInput = new ByteArrayInputStream(buf); ObjectInputStream objectInput = new ObjectInputStream(byteInput); - Detection msg = (Detection) objectInput.readObject(); + Object obj = objectInput.readObject(); + if(obj instanceof Detection) + { + Detection msg = (Detection)obj; if(log.isTraceEnabled()) { log.trace("received detection: " + msg); @@ -255,6 +293,13 @@ // let the subclass do the hard work off handling detection detect(msg); } + else + { + // for now, assume anything *not* of type Detection + // is a prompt to send out detection msg + heartbeat(); + } + } catch(Throwable e) { if(e instanceof java.io.InvalidClassException) |