diff options
author | jestin | 2004-12-23 16:12:25 +0000 |
---|---|---|
committer | jestin | 2004-12-23 16:12:25 +0000 |
commit | ccaba8df37149f7e744ebf9ff6a1dc350a32942b (patch) | |
tree | 04ecb2aeab20dec5e3ed13419e4dc50390f2a316 /src/IvyWatcher.java | |
parent | 031f955efd5fa20041f7344041f290b15b20c019 (diff) | |
download | ivy-java-ccaba8df37149f7e744ebf9ff6a1dc350a32942b.zip ivy-java-ccaba8df37149f7e744ebf9ff6a1dc350a32942b.tar.gz ivy-java-ccaba8df37149f7e744ebf9ff6a1dc350a32942b.tar.bz2 ivy-java-ccaba8df37149f7e744ebf9ff6a1dc350a32942b.tar.xz |
preparing the 1.2.7 release
Diffstat (limited to 'src/IvyWatcher.java')
-rwxr-xr-x | src/IvyWatcher.java | 53 |
1 files changed, 41 insertions, 12 deletions
diff --git a/src/IvyWatcher.java b/src/IvyWatcher.java index 3ac5ef9..5009c03 100755 --- a/src/IvyWatcher.java +++ b/src/IvyWatcher.java @@ -14,6 +14,10 @@ * thing. * * CHANGELOG: + * 1.2.7: + * - better handling of multiple connexions from the same remote agent when + * there are different broadcast addresses ( introduced the alreadyBroadcasted + * function ) * 1.2.6: * - IOException now goes silent when we asked the bus to stop() * - use a new buffer for each Datagram received, to prevent an old bug @@ -60,13 +64,14 @@ import java.net.*; import java.io.*; import java.util.StringTokenizer; import org.apache.regexp.*; +import java.util.Hashtable; import java.util.Vector; import java.util.Enumeration; class IvyWatcher implements Runnable { private static boolean debug = (System.getProperty("IVY_DEBUG")!=null); private boolean isMulticastAddress = false; - private Ivy bus; /* master bus controler */ + private Ivy bus; /* master bus controler */ private DatagramSocket broadcast; /* supervision socket */ private InetAddress localhost,loopback; private String domainaddr; @@ -112,6 +117,7 @@ class IvyWatcher implements Runnable { traceDebug("beginning of a watcher Thread"); InetAddress remotehost=null; try { + int remotePort=0; while( listenThread==thisThread ) { try { byte buf[] = new byte[256]; @@ -130,26 +136,33 @@ class IvyWatcher implements Runnable { continue; } int version = Integer.parseInt(re.getParen(1)); - if ( version < bus.PROTOCOLMINIMUM ) { + if ( version < Ivy.PROTOCOLMINIMUM ) { System.err.println("Ignoring bad format broadcast from "+ remotehostname+":"+packet.getPort() - +" protocol version "+remotehost+" we need "+bus.PROTOCOLMINIMUM+" minimum"); + +" protocol version "+remotehost+" we need "+Ivy.PROTOCOLMINIMUM+" minimum"); continue; } - int port = Integer.parseInt(re.getParen(2)); - if (bus.applicationPort==port) { + remotePort = Integer.parseInt(re.getParen(2)); + if (bus.applicationPort==remotePort) { traceDebug("ignoring a broadcast from "+ remotehostname+":"+packet.getPort() - +" on my port number ("+port+"), it's probably me"); + +" on my port number ("+remotePort+"), it's probably me"); // TODO check better - // if bus.applicationPort=port + // if bus.applicationPort=remotePort // parse the list of Watchers and check for each // iw.broadcast.getInetAddress().equals(packet().getAddress() // if one is true, "continue" ( ignore the broadcast ) continue; } traceDebug("broadcast accepted from " +remotehostname - +":"+packet.getPort()+", port:"+port+", protocol version:"+version); - new IvyClient(bus,new Socket(remotehost,port),port); + +":"+packet.getPort()+", port:"+remotePort+", protocol version:"+version); + // 1.2.7 ? TODO two connexions from the same host on different broadcast + // addresses (e.g. sam simu) + if (!alreadyBroadcasted(remotehost.toString(),remotePort)) { + traceDebug("no known agent originating from " + remotehost + ":" + remotePort); + new IvyClient(bus,new Socket(remotehost,remotePort),remotePort); + } else { + traceDebug("there is already a request originating from " + remotehost + ":" + remotePort); + } } catch (RESyntaxException ree) { ree.printStackTrace(); System.exit(-1); @@ -159,7 +172,8 @@ class IvyWatcher implements Runnable { } catch ( UnknownHostException e ) { System.err.println("Unkonwn host "+remotehost +","+e.getMessage()); } catch ( IOException e) { - System.err.println("can't connect to "+remotehost+" port "+ port+e.getMessage()); + System.err.println("can't connect to "+remotehost+" port "+ remotePort+e.getMessage()); + e.printStackTrace(); } } catch (InterruptedIOException jii ){ if (thisThread!=listenThread) { break ;} @@ -188,6 +202,7 @@ class IvyWatcher implements Runnable { } private class PacketSender implements Runnable { + // TODO do I need multiple packetsenders ? DatagramPacket packet; String data; public PacketSender(String data) { @@ -216,13 +231,28 @@ class IvyWatcher implements Runnable { } synchronized void start() throws IvyException { - String hello = bus.PROTOCOLVERSION + " " + bus.applicationPort + "\n"; + String hello = Ivy.PROTOCOLVERSION + " " + bus.applicationPort + "\n"; if (broadcast==null) throw new IvyException("IvyWatcher PacketSender null broadcast address"); new PacketSender(hello); // notifies our arrival on each domain: protocol version + port listenThread.start(); } /* + * since 1.2.7 pre .... + * checks if there is already a broadcast received from the same address + * on the same port + */ + static private Hashtable alreadySocks=new Hashtable(); + static private synchronized boolean alreadyBroadcasted(String s,int port) { + // System.out.println("DEBUUUUUUUG " + s+ ":" + port); + if (s==null) return false; + Integer i = (Integer)alreadySocks.get(s); + if (((i!=null)&&(i.compareTo(new Integer(port)))==0)) return true; + alreadySocks.put(s,new Integer(port)); + return false; + } + + /* private boolean isInDomain( InetAddress host ){ return true; // TODO check if this function is useful. for now, it always returns true @@ -282,5 +312,4 @@ class IvyWatcher implements Runnable { if (debug) System.out.println("-->IvyWatcher["+myserial+","+bus.getSerial()+"]<-- "+s); } - } // class IvyWatcher |