aboutsummaryrefslogtreecommitdiff
path: root/src/IvyWatcher.java
diff options
context:
space:
mode:
authorjestin2006-07-11 13:57:07 +0000
committerjestin2006-07-11 13:57:07 +0000
commitc9dbee9c2fb98a3ca467ac82a97a9d6f3dba9737 (patch)
tree19df9d4d9a3874f0a96a9ae6cee6716fe48bd9fd /src/IvyWatcher.java
parent5acff6b70cee194fbb74df827618169d2e2a6499 (diff)
downloadivy-java-c9dbee9c2fb98a3ca467ac82a97a9d6f3dba9737.zip
ivy-java-c9dbee9c2fb98a3ca467ac82a97a9d6f3dba9737.tar.gz
ivy-java-c9dbee9c2fb98a3ca467ac82a97a9d6f3dba9737.tar.bz2
ivy-java-c9dbee9c2fb98a3ca467ac82a97a9d6f3dba9737.tar.xz
voir chaque fichier pour les modifs.
Je rajoute les servlets dans la base, j'essayerai de fabriquer un ant file pour les construire
Diffstat (limited to 'src/IvyWatcher.java')
-rwxr-xr-xsrc/IvyWatcher.java48
1 files changed, 41 insertions, 7 deletions
diff --git a/src/IvyWatcher.java b/src/IvyWatcher.java
index b37fa6b..4b06b1b 100755
--- a/src/IvyWatcher.java
+++ b/src/IvyWatcher.java
@@ -14,6 +14,11 @@
* thing.
*
* CHANGELOG:
+ * 1.2.9:
+ * - added an application Id in the UDP broadcast. It seems to be ok with
+ * most implementations ( VERSION PORT APPID APPNAME \n) is compatible with (VERSION
+ * APPID). If I receive a broadcast with with the same TCP port number,
+ * I ignore the first and accept the new ones
* 1.2.8:
* - alreadyBroadcasted was static, thus Ivy Agents within the same JVM used
* to share the list of agents already connected. A nasty bug.
@@ -71,6 +76,7 @@ import java.util.Hashtable;
class IvyWatcher implements Runnable {
private static boolean debug = (System.getProperty("IVY_DEBUG")!=null);
private boolean isMulticastAddress = false;
+ private boolean alreadyIgnored = false;
private Ivy bus; /* master bus controler */
private DatagramSocket broadcast; /* supervision socket */
private InetAddress localhost,loopback;
@@ -80,6 +86,7 @@ class IvyWatcher implements Runnable {
private InetAddress group;
private static int serial=0;
private int myserial=serial++;
+ private String busWatcherId = null;
/**
* creates an Ivy watcher
@@ -90,6 +97,7 @@ class IvyWatcher implements Runnable {
this.bus = bus;
this.domainaddr=domainaddr;
this.port=port;
+ busWatcherId=bus.getWatcherId();
listenThread = new Thread(this);
// create the MulticastSocket
try {
@@ -143,12 +151,37 @@ class IvyWatcher implements Runnable {
continue;
}
remotePort = Integer.parseInt(re.getParen(2));
- if (bus.applicationPort==remotePort) {
- traceDebug("ignoring a broadcast from "+ remotehostname+":"+packet.getPort()
- +" on my port number ("+remotePort+"), it's probably me");
- // TODO check this in a better way
- continue;
- }
+ if (bus.applicationPort==remotePort) { // if (same port number)
+ RE reId = new RE("([0-9]*) ([0-9]*) ([^ ]*) (.*)");
+ if (reId.match(msg)&&(busWatcherId!=null)) {
+ traceDebug("there's an appId: "+reId.getParen(3));
+ String otherId=reId.getParen(3);
+ String otherName=reId.getParen(4);
+ if (busWatcherId.compareTo(otherId)==0) {
+ // same port #, same bus Id, It's me, I'm outta here
+ traceDebug("ignoring my own broadcast");
+ continue;
+ } else {
+ // same port #, different bus Id, it's another agent
+ // implementing the Oh Soooo Cool watcherId undocumented
+ // unprotocolar Ivy add on
+ traceDebug("accepting a broadcast from a same port by "+otherName);
+ }
+ } else {
+ // there's no watcherId in the broacast. I fall back to a
+ // crude strategy: I ignore the first broadcast with the same
+ // port number, and accept the following ones
+ if (alreadyIgnored) {
+ traceDebug("received another broadcast from "+ remotehostname+":"+packet.getPort()
+ +" on my port number ("+remotePort+"), it's probably someone else");
+ } else {
+ alreadyIgnored=true;
+ traceDebug("ignoring a broadcast from "+ remotehostname+":"+packet.getPort()
+ +" on my port number ("+remotePort+"), it's probably me");
+ continue;
+ }
+ }
+ } // end if (same port #)
traceDebug("broadcast accepted from " +remotehostname
+":"+packet.getPort()+", port:"+remotePort+", protocol version:"+version);
if (!alreadyBroadcasted(remotehost.toString(),remotePort)) {
@@ -231,7 +264,8 @@ class IvyWatcher implements Runnable {
}
synchronized void start() throws IvyException {
- String hello = Ivy.PROTOCOLVERSION + " " + bus.applicationPort + "\n";
+ // String hello = Ivy.PROTOCOLVERSION + " " + bus.applicationPort + "\n";
+ String hello = Ivy.PROTOCOLVERSION + " " + bus.applicationPort + " "+busWatcherId+" "+bus.selfIvyClient.getApplicationName()+"\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();