aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rwxr-xr-xsrc/Ivy.java57
-rwxr-xr-xsrc/IvyApplicationListener.java5
-rwxr-xr-xsrc/IvyClient.java120
-rw-r--r--src/IvyDaemon.java1
-rwxr-xr-xsrc/IvyWatcher.java60
-rw-r--r--src/Makefile18
-rw-r--r--src/Probe.java29
-rw-r--r--src/SelfIvyClient.java21
8 files changed, 166 insertions, 145 deletions
diff --git a/src/Ivy.java b/src/Ivy.java
index e3cc0bb..3486765 100755
--- a/src/Ivy.java
+++ b/src/Ivy.java
@@ -4,6 +4,8 @@
* @author Yannick Jestin
* @author <a href="http://www.tls.cena.fr/products/ivy/">http://www.tls.cena.fr/products/ivy/</a>
*
+ * (c) CENA 1998-2004
+ *
*<pre>
*Ivy bus = new Ivy("Dummy agent","ready",null);
*bus.bindMsg("(.*)",myMessageListener);
@@ -11,6 +13,14 @@
*</pre>
*
* CHANGELOG:
+ * 1.2.6:
+ * - changed the semantic of -b a,b:port,c:otherport if no port is
+ * specified for a, it take the port from the next one. If none is
+ * specified, it takes DEFAULT_PORT
+ * - no more asynchronous sending of message ( async bind is ok though )
+ * because the tests are sooooo unsuccessful
+ * 1.2.5:
+ * - protection of newlines
* 1.2.4:
* - added an accessor for doSendToSelf
* - waitForMsg() and waitForClient() to make the synchronization with
@@ -80,7 +90,7 @@ public class Ivy implements Runnable {
* the library version, useful for development purposes only, when java is
* invoked with -DIVY_DEBUG
*/
- public static final String libVersion ="1.2.4";
+ public static final String libVersion ="1.2.6";
private boolean debug;
private static int clientSerial=0; /* an unique ID for each IvyClient */
@@ -211,6 +221,13 @@ public class Ivy implements Runnable {
// do nothing
}
}
+ // fixes the port values ...
+ int lastport = Ivy.DEFAULT_PORT;
+ for (index--;index>=0;index--) {
+ Domain dom=d[index];
+ if (dom.port==0) dom.port=lastport;
+ lastport=dom.port;
+ }
return d;
}
@@ -265,12 +282,12 @@ public class Ivy implements Runnable {
/**
* Toggles the encoding/decoding of messages to prevent bugs related to the
* presence of a "\n"
- * @param boolean true if you want to send the message to yourself. Default
- * is false.
- * @since 1.2.5?
+ * @param boolean true if you want to enforce encoding of newlines. Default
+ * is false. Every receiver will have to decode newlines
+ * @since 1.2.5
* The default escape character is a ESC 0x1A
*/
- private void protectNewlines(boolean b) {doProtectNewlines=b;}
+ public void protectNewlines(boolean b) {doProtectNewlines=b;}
/**
* Performs a pattern matching according to everyone's regexps, and sends
@@ -284,20 +301,21 @@ public class Ivy implements Runnable {
return sendMsg(message,false);
}
- /**
+ /*
* Performs a pattern matching according to everyone's regexps, and sends
* the results to the relevant ivy agents, using as many threads as needed.
*
+ * disappeared in 1.2.6
* @since 1.2.4
* @param message A String which will be compared to the regular
* expressions of the different clients
* @return always returns -1
- */
public int sendAsyncMsg(String message,boolean async) throws IvyException {
return sendMsg(message,true);
}
+ */
- /**
+ /*
* Performs a pattern matching according to everyone's regexps, and sends
* the results to the relevant ivy agents.
*
@@ -308,8 +326,9 @@ public class Ivy implements Runnable {
* default is false
* @return if async is true, always returns -1, else returns the number of messages actually sent
*/
- public int sendMsg(String message,boolean async) throws IvyException {
+ protected int sendMsg(String message,boolean async) throws IvyException {
int count = 0;
+ if (async) throw new IvyException("Async sending not supported anymore");
if (doProtectNewlines)
message=IvyClient.encode(message);
else if ( (message.indexOf(IvyClient.newLineChar)!=-1)||(message.indexOf(IvyClient.endArgChar)!=-1))
@@ -352,7 +371,7 @@ public class Ivy implements Runnable {
* another one sent before
*
* @since 1.2.4
- * @param regexp a perl regular expression, groups are done with parenthesis
+ * @param regexp a perl compatible regular expression, groups are done with parenthesis
* @param callback any objects implementing the IvyMessageListener
* interface, on the AWT/Swing framework
* @return the int ID of the regular expression.
@@ -494,11 +513,11 @@ public class Ivy implements Runnable {
*/
void removeClient(IvyClient c) { clients.remove(c.getClientKey()); }
- /**
+ /*
* invokes the application listeners when we are summoned to die
* then stops
*/
- public void dieReceived(IvyClient client, int id,String message){
+ protected void dieReceived(IvyClient client, int id,String message){
for ( int i=0 ;i<ivyApplicationListenerList.size();i++ ) {
((IvyApplicationListener)ivyApplicationListenerList.elementAt(i)).die(client,id,message);
}
@@ -594,13 +613,13 @@ public class Ivy implements Runnable {
* the service socket thread reader main loop
*/
public void run() {
- // System.out.println("Ivy service Thread started"); // THREADDEBUG
+ traceDebug("Ivy service Thread started"); // THREADDEBUG
Thread thisThread=Thread.currentThread();
while(thisThread==serverThread){
try {
Socket socket = app.accept();
if ((thisThread!=serverThread)||stopped) break; // early disconnexion
- addClient(socket,true,0); // the peer called me TODO I don't know his protocol version
+ addClient(socket,true,0); // the peer called me TODO I can't know his protocol version
} catch (InterruptedIOException ie) {
if (thisThread!=serverThread) break;
} catch( IOException e ) {
@@ -612,8 +631,7 @@ public class Ivy implements Runnable {
} else { traceDebug("my server socket has been closed"); }
}
}
- traceDebug("stopping the server Thread");
- // System.out.println("Ivy service Thread stopped"); // THREADDEBUG
+ traceDebug("Ivy service Thread stopped"); // THREADDEBUG
}
@@ -628,10 +646,10 @@ public class Ivy implements Runnable {
void waitForAll() {
Thread t;
- System.out.println("DEVELOPMENT WAITFORALL sendThreads size : " + sendThreads.size());
+ traceDebug("DEVELOPMENT WAITFORALL sendThreads size : " + sendThreads.size());
try { while ((t=getOneThread())!=null) { t.join(); } }
catch (InterruptedException ie) { System.out.println("waitForAll Interrupted"); }
- System.out.println("DEVELOPMENT END WAITFORALL");
+ traceDebug("DEVELOPMENT END WAITFORALL");
}
/* a small private method for debbugging purposes */
@@ -655,7 +673,7 @@ public class Ivy implements Runnable {
class Domain {
private String domainaddr;
- private int port;
+ int port;
public Domain(String domainaddr,int port) {this.domainaddr=domainaddr;this.port=port;}
public String toString() {return domainaddr+":"+port;}
public String getDomainaddr() { return domainaddr; }
@@ -676,6 +694,7 @@ public class Ivy implements Runnable {
System.out.println(((bus.waitForClient("IVYPROBE",5000))!=null)?"Ivyprobe joined the bus":"nobody came");
bus.stop();
} catch (IvyException ie) {
+ System.out.println("Ivy main test error");
ie.printStackTrace();
}
}
diff --git a/src/IvyApplicationListener.java b/src/IvyApplicationListener.java
index 456a85f..2dac989 100755
--- a/src/IvyApplicationListener.java
+++ b/src/IvyApplicationListener.java
@@ -37,6 +37,11 @@ public interface IvyApplicationListener extends java.util.EventListener {
* @param client the peer
* @param id
* @param msgarg the message itself
+ *
+ * there is no need to use a bus close() or stop() operation within a die()
+ * method, it will be called automatically. Furthermore, it is considered
+ * poor style to enforce the end of a program with System.exit(), you should
+ * consider terminating all threads ( AWT, etc )
*/
public abstract void directMessage( IvyClient client, int id,String msgarg );
}
diff --git a/src/IvyClient.java b/src/IvyClient.java
index b69c8d3..d3deb8b 100755
--- a/src/IvyClient.java
+++ b/src/IvyClient.java
@@ -1,5 +1,5 @@
/**
- * A private Class for the the peers on the bus.
+ * the peers on the bus.
*
* @author Yannick Jestin
* @author <a href="http://www.tls.cena.fr/products/ivy/">http://www.tls.cena.fr/products/ivy/</a>
@@ -10,6 +10,14 @@
* created for each remote client.
*
* CHANGELOG:
+ * 1.2.6
+ * - now sends back an error message when an incorrect regexp is sent
+ * the message is supposed to be readable
+ * 1.2.5:
+ * - no more java ping ...
+ * 1.2.5:
+ * - use org.apache.regexp instead of gnu-regexp
+ * http://jakarta.apache.org/regexp/apidocs/
* 1.2.4:
* - sendBuffer goes synchronized
* - sendMsg now has a async parameter, allowing the use of threads to
@@ -50,7 +58,8 @@ import java.lang.Thread;
import java.net.*;
import java.io.*;
import java.util.*;
-import gnu.regexp.*;
+/* import gnu.regexp.*; GNURETOAPACHERE */
+import org.apache.regexp.*;
public class IvyClient implements Runnable {
@@ -62,11 +71,9 @@ public class IvyClient implements Runnable {
final static int DelRegexp = 4;/* the peer removes one of his regex */
final static int EndRegexp = 5;/* no more regexp in the handshake */
final static int SchizoToken = 6; /* avoid race condition in concurrent connexions */
- /* SchizoToken is aka BeginRegexp in other implementations */
+ /* SchizoToken is aka BeginRegexp in other implementations */
final static int DirectMsg = 7;/* the peer sends a direct message */
final static int Die = 8; /* the peer wants us to quit */
- final static int Ping = 9; /* checks the presence of the other */
- final static int Pong = 10; /* checks the presence of the other */
final static String MESSAGE_TERMINATOR = "\n"; /* the next protocol will use \r */
final static String StartArg = "\u0002";/* begin of arguments */
final static String EndArg = "\u0003"; /* end of arguments */
@@ -85,10 +92,6 @@ public class IvyClient implements Runnable {
private boolean peerCalling;
private volatile Thread clientThread;// volatile to ensure the quick communication
private Integer clientKey ;
- private static boolean doping = (System.getProperty("IVY_PING")!=null) ;
- private final static int PINGTIMEOUT = 5000;
- private PINGER pinger;
- private volatile Thread pingerThread;
private boolean discCallbackPerformed = false;
// protected variables
@@ -115,22 +118,17 @@ public class IvyClient implements Runnable {
// the ID is the couple "host name,application Port", the host name
// information is in the socket itself, the port is not known if we
// initiate the connexion
- send(SchizoToken,bus.applicationPort,bus.appName);
+ sendString(SchizoToken,bus.applicationPort,bus.appName);
// sends our regexps to the peer
for (Enumeration e = tosend.keys(); e.hasMoreElements(); ) {
Integer ikey = (Integer)e.nextElement();
sendRegexp(ikey.intValue(),(String)tosend.get(ikey));
}
- send( EndRegexp,0,"");
+ sendString( EndRegexp,0,"");
// spawns a thread to manage the incoming traffic on this
// socket. We should be ready to receive messages now.
clientThread = new Thread(this);
- clientThread .start();
- if (doping) {
- pinger = new PINGER();
- pingerThread=new Thread(pinger);
- pingerThread.start();
- }
+ clientThread.start();
}
public String toString() { return "IvyClient "+bus.appName+":"+appName; }
@@ -147,7 +145,7 @@ public class IvyClient implements Runnable {
* allow the notification of regexp addition and deletion
* The content is not modifyable because String are not mutable, and cannot
* be modified once they are create.
- * @see getRegexpsArray to get a String[] result
+ * @see IvyClient#getRegexpsArray() getRegexpsArray to get a String[] result
*/
public Enumeration getRegexps() { return regexpsText.elements(); }
@@ -172,14 +170,13 @@ public class IvyClient implements Runnable {
public void sendDirectMsg(int id,String message) throws IvyException {
if ( (message.indexOf(IvyClient.newLineChar)!=-1)||(message.indexOf(IvyClient.endArgChar)!=-1))
throw new IvyException("newline character not allowed in Ivy messages");
- send(DirectMsg,id,message);
+ sendString(DirectMsg,id,message);
}
/* closes the connexion to the peer */
protected void close(boolean notify) throws IOException {
bus.waitForAll();
traceDebug("closing connexion to "+appName);
- if (doping&&(pinger!=null)) { pinger.stopPinging(); }
if (notify) sendBye("hasta la vista");
stopListening();
socket.close();
@@ -189,7 +186,7 @@ public class IvyClient implements Runnable {
* asks the remote client to leave the bus.
* @param message the message that will be carried
*/
- public void sendDie(String message) { send(Die,0,message); }
+ public void sendDie(String message) { sendString(Die,0,message); }
/**
* checks the "validity" of a regular expression.
@@ -213,12 +210,13 @@ public class IvyClient implements Runnable {
// PROTECTED METHODS
//
///////////////////////////////////////////////////
+
static String decode(String s) { return s.replace(escapeChar,'\n'); }
static String encode(String s) { return s.replace('\n',escapeChar); }
Integer getClientKey() { return clientKey ; }
int getAppPort() { return appPort ; }
- void sendRegexp(int id,String regexp) {send(AddRegexp,id,regexp);}
- void delRegexp(int id) {send( DelRegexp,id,"");}
+ void sendRegexp(int id,String regexp) {sendString(AddRegexp,id,regexp);}
+ void delRegexp(int id) {sendString(DelRegexp,id,"");}
int sendMsg(String message,boolean async) {
if (async) {
@@ -232,11 +230,18 @@ public class IvyClient implements Runnable {
for (Enumeration e = regexps.keys();e.hasMoreElements();) {
Integer key = (Integer)e.nextElement();
RE regexp = (RE)regexps.get(key);
+ /*
+ * GNURETOAPACHERE
int nb = regexp.getNumSubs();
REMatch result = regexp.getMatch(message);
if (result==null) continue; // no match
count++; // match
send(Msg,key,regexp.getNumSubs(),result);
+ *
+ */
+ if (!regexp.match(message)) continue; // no match
+ count++; // match
+ sendResult(Msg,key,regexp);
}
return count;
}
@@ -280,7 +285,6 @@ public class IvyClient implements Runnable {
try {
if ((msg=in.readLine()) != null ) {
if (clientThread!=thisThread) break; // early stop during readLine()
- if (doping && (pingerThread!=null)) pingerThread.interrupt();
if (!newParseMsg(msg)) {
close(true);
break;
@@ -290,6 +294,7 @@ public class IvyClient implements Runnable {
break;
}
} catch (IvyException ie) {
+ traceDebug("IvyClient caught an exception");
ie.printStackTrace();
} catch (InterruptedIOException ioe) {
traceDebug("I have been interrupted. I'm about to leave my thread loop");
@@ -326,7 +331,7 @@ public class IvyClient implements Runnable {
}
}
- private void send(int type, int id, String arg) {
+ private void sendString(int type, int id, String arg) {
try {
sendBuffer(type+" "+id+StartArg+arg);
} catch (IvyException ie ) {
@@ -335,10 +340,16 @@ public class IvyClient implements Runnable {
}
}
+ /* GNURETOAPACHERE
private void send(int type, Integer id, int nbsub, REMatch result) {
+ */
+
+ private void sendResult(int type,Integer id, RE regexp) {
String buffer = type+" "+id+StartArg;
+ /*
for(int sub = 1; sub <= nbsub; sub++) if (result.getStartIndex(sub) > -1)
- buffer += result.toString(sub)+EndArg;
+ */
+ for(int i=1;i<regexp.getParenCount();i++) buffer+=regexp.getParen(i)+EndArg;
try {
sendBuffer(buffer);
} catch (IvyException ie ) {
@@ -375,25 +386,25 @@ public class IvyClient implements Runnable {
while ((to<b.length)&&(b[to]!=' ')) to++;
// return false au lieu de throw
if (to>=b.length) {
- System.out.println("protocol error from "+appName);
+ System.out.println("Ivy protocol error from "+appName);
return false;
}
try {
msgType = Integer.parseInt(s.substring(from,to));
} catch (NumberFormatException nfe) {
- System.out.println("protocol error on msgType from "+appName);
+ System.out.println("Ivy protocol error on msgType from "+appName);
return false;
}
from=to+1;
while ((to<b.length)&&(b[to]!=2)) to++;
if (to>=b.length) {
- System.out.println("protocol error from "+appName);
+ System.out.println("Ivy protocol error from "+appName);
return false;
}
try {
msgId = new Integer(s.substring(from,to));
} catch (NumberFormatException nfe) {
- System.out.println("protocol error from "+appName+" "+s.substring(from,to)+" is not a number");
+ System.out.println("Ivy protocol error from "+appName+" "+s.substring(from,to)+" is not a number");
return false;
}
from=to+1;
@@ -434,10 +445,10 @@ public class IvyClient implements Runnable {
regexps.put(msgId,new RE(regexp));
regexpsText.put(msgId,regexp);
bus.regexpReceived(this,msgId.intValue(),regexp);
- } catch (REException e) {
+ } catch (RESyntaxException e) {
// the remote client sent an invalid regexp !
- System.out.println("invalid regexp sent by " +appName+" ("+regexp+"), I will ignore this regexp");
- return true;
+ traceDebug("invalid regexp sent by " +appName+" ("+regexp+"), I will ignore this regexp");
+ sendBuffer(Error+e.toString());
}
} else {
throw new IvyException("regexp Warning exp='"+regexp+"' can't match removing from "+appName);
@@ -467,23 +478,11 @@ public class IvyClient implements Runnable {
}
}
String[] tab = new String[v.size()];
- for (int i=0;i<v.size();i++) {
- tab[i]=(String)v.elementAt(i);
- // for developpemnt purposes
- // System.out.println(" *"+tab[i]+"* "+(tab[i]).length());
- }
+ for (int i=0;i<v.size();i++) tab[i]=(String)v.elementAt(i);
+ // for developpemnt purposes
+ traceDebug(tab);
bus.selfIvyClient.callCallback(this,msgId,tab);
break;
- case Pong:
- String paramPong=s.substring(from,b.length);
- traceDebug("Ping msg from "+appName+" : "+paramPong);
- break;
- case Ping:
- // I receive a ping. I can answer a pong.
- String param=s.substring(from,b.length);
- traceDebug("Ping msg from "+appName+" : "+param);
- sendPong(param);
- break;
case Error:
String error=s.substring(from,b.length);
traceDebug("Error msg "+msgId+" "+error);
@@ -511,10 +510,8 @@ public class IvyClient implements Runnable {
return true;
}
- protected void sendPong(String s) {send(Pong,0,s);}
- protected void sendPing(String s) {send(Ping,0,s);}
- private void sendBye() {send(Bye,0,"");}
- private void sendBye(String message) {send(Bye,0,message);}
+ private void sendBye() {sendString(Bye,0,"");}
+ private void sendBye(String message) {sendString(Bye,0,message);}
private InetAddress getRemoteAddress() { return socket.getInetAddress(); }
@@ -522,21 +519,10 @@ public class IvyClient implements Runnable {
if (debug) System.out.println("-->IvyClient "+bus.appName+":"+appName+"<-- "+s);
}
- class PINGER implements Runnable {
- boolean isPinging = false;
- public void run() {
- isPinging=true;
- traceDebug("Pinger Thread started");
- while (isPinging) {
- try {
- Thread.sleep(PINGTIMEOUT);
- sendPing("are you here ?");
- } catch (InterruptedException ie) {
- }
- }
- traceDebug("Pinger Thread stopped");
- }
- public void stopPinging() { isPinging=false; pingerThread.interrupt();}
+ private void traceDebug(String[] tab){
+ String s = "String array " + tab.length + " elements: ";
+ for (int i=0;i<tab.length;i++) s+="("+tab[i]+") ";
+ if (debug) System.out.println("-->IvyClient "+bus.appName+":"+appName+"<-- "+s);
}
// a class to perform the threaded execution of each new message
diff --git a/src/IvyDaemon.java b/src/IvyDaemon.java
index b843a63..363337b 100644
--- a/src/IvyDaemon.java
+++ b/src/IvyDaemon.java
@@ -27,6 +27,7 @@ import java.io.*;
import java.net.*;
import java.util.Properties ;
import gnu.getopt.Getopt;
+
public class IvyDaemon implements Runnable {
diff --git a/src/IvyWatcher.java b/src/IvyWatcher.java
index 7698632..dafa6f9 100755
--- a/src/IvyWatcher.java
+++ b/src/IvyWatcher.java
@@ -16,10 +16,13 @@
* CHANGELOG:
* 1.2.5:
* - getDomain now sends IvyException for malformed broadcast addresses
+ * - uses apache jakarta-regexp instead of gnu-regexp
+ * - throws an IvyException if the broadcast domain cannot be resolved
* 1.2.4:
* - sends the broadcast before listening to the other's broadcasts.
- * TODO wait for all the broadcast to be sent before starting the listen
- * mode
+ * I can't wait for all the broadcast to be sent before starting the listen
+ * mode, otherwise another agent behaving likewise could be started
+ * meanwhile, and one would not "see" each other.
* - (REMOVED) allows the connexion from a remote host with the same port number
* it's too complicated to know if the packet is from ourselves...
* - deals with the protocol errors in a more efficient way. The goal is not
@@ -53,7 +56,8 @@ import java.lang.Thread;
import java.net.*;
import java.io.*;
import java.util.StringTokenizer;
-import gnu.regexp.*;
+/* import gnu.regexp.*; GNURETOAPACHERE */
+import org.apache.regexp.*;
import java.util.Vector;
import java.util.Enumeration;
@@ -99,7 +103,7 @@ class IvyWatcher implements Runnable {
* the behaviour of each thread watching the UDP socket.
*/
public void run() {
- // System.out.println("IvyWatcher Thread started"); // THREADDEBUG
+ traceDebug("IvyWatcher Thread started"); // THREADDEBUG
Thread thisThread=Thread.currentThread();
traceDebug("beginning of a watcher Thread");
byte buf[] = new byte[256];
@@ -116,32 +120,31 @@ class IvyWatcher implements Runnable {
// BUGFIX ? I change 0 to 10 in order to avoid a bug
remotehost = packet.getAddress();
traceDebug("BUSWATCHER Receive Broadcast from "+remotehost.getHostName()+":"+packet.getPort());
- // TODO if ( !isInDomain( remotehost ) ) continue;
+ // if ( !isInDomain( remotehost ) ) continue;
try {
RE re = new RE("([0-9]*) ([0-9]*)");
- REMatch result = re.getMatch(msg);
- if (result==null) {
+ if (!(re.match(msg))) {
System.err.println("Ignoring bad format broadcast from "+remotehost);
continue;
}
- int version = Integer.parseInt(result.toString(1));
+ int version = Integer.parseInt(re.getParen(1));
if ( version < bus.PROTOCOLMINIMUM ) {
System.err.println("Ignoring bad protocol version "+remotehost+" we need "+ bus.PROTOCOLMINIMUM+" minimum");
continue;
}
- int port = Integer.parseInt(result.toString(2));
+ int port = Integer.parseInt(re.getParen(2));
// allows the connexion from a remote host with the same port number
// if ( ( (remotehost.equals(localhost)) || (remotehost.equals(loopback)) )
// && (bus.applicationPort==port)) {
if (bus.applicationPort==port) {
- traceDebug("ignoring my own broadcast. OK");
+ traceDebug("ignoring a broadcast on my port number, it's *probably* me");
continue; // it's me
}
traceDebug("Broadcast de " +packet.getAddress().getHostName()
+":"+packet.getPort()+" port "+port+" version "+version);
Socket socket = new Socket( remotehost, port );
bus.addClient(socket,false,version);
- } catch (REException ree) {
+ } catch (RESyntaxException ree) {
ree.printStackTrace();
System.exit(-1);
} catch (NumberFormatException nfe) {
@@ -157,12 +160,15 @@ class IvyWatcher implements Runnable {
}
} // while
} catch (java.net.SocketException se ){
- if (thisThread==listenThread) { se.printStackTrace(); }
+ if (thisThread==listenThread) {
+ System.out.println("IvyWatcher error, continuing anyway");
+ se.printStackTrace();
+ }
} catch (IOException ioe ){
+ System.out.println("IvyWatcher IO Exception, continuing anyway");
ioe.printStackTrace();
}
- traceDebug("end of a watcher thread");
- // System.out.println("IvyWatcher Thread stopped"); // THREADDEBUG
+ traceDebug("IvyWatcher Thread stopped"); // THREADDEBUG
}
/**
@@ -206,14 +212,18 @@ class IvyWatcher implements Runnable {
synchronized void start() throws IvyException {
String hello = bus.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();
}
/*
- * deprecated since we use Multicast. How to check when we are in UDP
- * broadcast ?
private boolean isInDomain( InetAddress host ){
+ return true;
+ // TODO check if this function is useful. for now, it always returns true
+ // deprecated since we use Multicast. How to check when we are in UDP
+ // broadcast ?
+ //
byte rem_addr[] = host.getAddress();
for ( int i = 0 ; i < domainaddrList.size(); i++ ) {
byte addr[] = ((InetAddress)domainaddrList.elementAt(i)).getAddress();
@@ -228,22 +238,26 @@ class IvyWatcher implements Runnable {
traceDebug( "host " + host + " Not in domain\n" );
return false;
}
- */
+ */
- // TODO this is buggy :-\ try it on a named multicast address just to see
static String getDomain(String net) throws IvyException {
// System.out.println("debug: net=[" + net+ "]");
int sep_index = net.lastIndexOf( ":" );
if ( sep_index != -1 ) { net = net.substring(0,sep_index); }
try {
+ RE numbersPoint = new RE("([0-9]|\\.)+");
+ if (!numbersPoint.match(net)) {
+ // traceDebug("should only have numbers and point ? I won't add anything... " + net);
+ return net;
+ }
net += ".255.255.255";
RE exp = new RE( "^(\\d+\\.\\d+\\.\\d+\\.\\d+).*");
- net = exp.substitute( net , "$1" );
- if (net==null) {
+ if (!exp.match(net)) {
System.out.println("Bad broascat addr " + net);
throw new IvyException("bad broadcast addr");
}
- } catch ( REException e ){
+ net=exp.getParen(1);
+ } catch ( RESyntaxException e ){
System.out.println(e);
System.exit(0);
}
@@ -251,9 +265,9 @@ class IvyWatcher implements Runnable {
return net;
}
- static int getPort(String net) {
+ static int getPort(String net) { // returns 0 if no port is set
int sep_index = net.lastIndexOf( ":" );
- int port= ( sep_index == -1 ) ? Ivy.DEFAULT_PORT :Integer.parseInt( net.substring( sep_index +1 ));
+ int port= ( sep_index == -1 ) ? 0 :Integer.parseInt( net.substring( sep_index +1 ));
// System.out.println("net: ["+net+"]\nsep_index: "+sep_index+"\nport: "+port);
return port;
}
diff --git a/src/Makefile b/src/Makefile
index 54cfdec..8a12da1 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -1,13 +1,13 @@
-GNUPATH=/usr/share/java/repository:/usr/share/java/gnu-regexp-1.1.3.jar
+GNUPATH=/usr/share/java/gnu-getopt.jar:/usr/share/java/regexp.jar
#GNUPATH=/usr/share/java/repository:/usr/share/java/gnu.getopt.0.9.jar:/usr/share/java/gnu-regexp-1.1.3.jar
-#GNUPATH=${HOME}/JavaFactory
+#GNUPATH=${HOME}/java/jars/gnu-getopt.jar:${HOME}/java/jars/regexp.jar
#######################################
# generic setup
#######################################
-# JAVAC = javac
-#JAVACOPTS = -d . -deprecation
-#CLASSPATH = -classpath .:$(GNUPATH)
+ JAVAC = javac
+JAVACOPTS = -d . -deprecation
+CLASSPATH = -classpath .:$(GNUPATH)
#######################################
# gcj setup
@@ -19,10 +19,10 @@ GNUPATH=/usr/share/java/repository:/usr/share/java/gnu-regexp-1.1.3.jar
#######################################
# jikes setup on my box
#######################################
- RTPATH = /usr/lib/j2se/1.4/jre/lib/rt.jar
-JAVACOPTS = -d . -deprecation
- JAVAC = jikes
-CLASSPATH = -classpath .:$(RTPATH):$(GNUPATH)
+# RTPATH = /usr/lib/j2se/1.4/jre/lib/rt.jar
+#JAVACOPTS = -d . -deprecation
+# JAVAC = jikes
+#CLASSPATH = -classpath .:$(RTPATH):$(GNUPATH)
#######################################
# blackdown jdk118 setup
diff --git a/src/Probe.java b/src/Probe.java
index 8e4f9c2..c83b9ac 100644
--- a/src/Probe.java
+++ b/src/Probe.java
@@ -7,6 +7,10 @@
* (c) CENA
*
* Changelog:
+ * 1.2.6
+ * - no more java ping
+ * 1.2.5
+ * - uses apache regexp instead of gnu regexp
* 1.2.4
* - now uses the bindListener paradigm to display the binding/unbinding dynamically
* - adds the -s (send to self) command line switch
@@ -41,11 +45,12 @@ package fr.dgac.ivy ;
import java.io.*;
import java.util.*;
import gnu.getopt.Getopt;
-import gnu.regexp.*;
+/* import gnu.regexp.*; GNURETOAPACHERE */
+import org.apache.regexp.*;
public class Probe implements IvyApplicationListener, IvyMessageListener, IvyBindListener, Runnable {
- public static final String helpCommands = "Available commands:\n.die CLIENTNAME sends a die message\n.direct CLIENTNAME ID MESSAGE sends the direct message to the client, with a message id set to the numerical ID\n.bye quits the application\n.quit idem\n.list lists the available clients\n.ping sends a ping request if IVY_PING is enabled\n.bind REGEXP binds to a regexp at runtime\n.unbind REGEXP unbinds to a regexp at runtime";
+ public static final String helpCommands = "Available commands:\n.die CLIENTNAME sends a die message\n.direct CLIENTNAME ID MESSAGE sends the direct message to the client, with a message id set to the numerical ID\n.bye quits the application\n.quit idem\n.list lists the available clients\n.bind REGEXP binds to a regexp at runtime\n.unbind REGEXP unbinds to a regexp at runtime";
public static final String helpmsg = "usage: java fr.dgac.ivy.Probe [options] [regexp]\n\t-b BUS\tspecifies the Ivy bus domain\n\t-n ivyname (default JPROBE)\n\t-q\tquiet, no tty output\n\t-d\tdebug\n\t-t\ttime stamp each message\n\t-s\tsends to self\n\t-h\thelp\n\n\t regexp is a Perl5 compatible regular expression";
@@ -102,7 +107,7 @@ public class Probe implements IvyApplicationListener, IvyMessageListener, IvyBin
this.debug = debug;
try {
directMsgRE = new RE("^\\.direct ([^ ]*) ([0-9]+) (.*)");
- } catch (REException ree) {
+ } catch (RESyntaxException ree) {
System.err.println("Regexp fatal error in the Probe program.");
ree.printStackTrace();
System.exit(0);
@@ -143,7 +148,6 @@ public class Probe implements IvyApplicationListener, IvyMessageListener, IvyBin
}
void parseCommand(String s) throws IOException {
- REMatch result;
traceDebug("parsing the ["+s+"] (length "+s.length()+") string");
// crude parsing of the ".xyz" commands
if (s.length()==0) {
@@ -152,10 +156,10 @@ public class Probe implements IvyApplicationListener, IvyMessageListener, IvyBin
} catch (IvyException ie) {
println("-> not sent, the message contains incorrect characters");
}
- } else if ((result=directMsgRE.getMatch(s))!=null) {
- String target = result.toString(1);
- int id = Integer.parseInt(result.toString(2));
- String message = result.toString(3);
+ } else if (directMsgRE.match(s)) {
+ String target = directMsgRE.getParen(1);
+ int id = Integer.parseInt(directMsgRE.getParen(2));
+ String message = directMsgRE.getParen(3);
Vector v=bus.getIvyClientsByName(target);
if (v.size()==0) println("no Ivy client with the name \""+target+"\"");
try {
@@ -184,15 +188,6 @@ public class Probe implements IvyApplicationListener, IvyMessageListener, IvyBin
} catch (IvyException ie) {
System.out.println("warning, the regular expression '" + regexp + "' is invalid. Not bound !");
}
- } else if (s.lastIndexOf(".ping ")>=0){
- String target=s.substring(6);
- Vector v=bus.getIvyClientsByName(target);
- if (v.size()==0) {
- println("no Ivy client with the name \""+target+"\"");
- }
- for (int i=0;i<v.size();i++) {
- ((IvyClient)v.elementAt(i)).sendPing("test");
- }
} else if ( (s.lastIndexOf(".quit")>=0)||(s.lastIndexOf(".bye")>=0)){
bus.stop();
System.exit(0);
diff --git a/src/SelfIvyClient.java b/src/SelfIvyClient.java
index 09d9f80..d6e6f1e 100644
--- a/src/SelfIvyClient.java
+++ b/src/SelfIvyClient.java
@@ -6,6 +6,8 @@
* @since 1.2.4
*
* CHANGELOG:
+ * 1.2.5:
+ * - uses apache regexp instead of gnu regexp
* 1.2.4:
* - adds a the threaded option for callbacks
* - Matthieu's bugreport on unBindMsg()
@@ -13,7 +15,8 @@
package fr.dgac.ivy ;
import java.util.*;
-import gnu.regexp.*;
+/* import gnu.regexp.*; GNURETOAPACHERE */
+import org.apache.regexp.*;
class SelfIvyClient extends IvyClient {
@@ -44,7 +47,7 @@ class SelfIvyClient extends IvyClient {
callbacks.put(key,callback);
threadedFlag.put(key,new Boolean(threaded));
return key.intValue();
- } catch (REException ree) {
+ } catch (RESyntaxException ree) {
throw new IvyException("Invalid regexp " + sregexp);
}
}
@@ -80,11 +83,9 @@ class SelfIvyClient extends IvyClient {
Integer key = (Integer)e.nextElement();
RE regexp = (RE)regexps.get(key);
String sre = (String)regexpsText.get(key);
- int nb = regexp.getNumSubs();
- REMatch result = regexp.getMatch(message);
- if (result==null) continue;
+ if (!regexp.match(message)) continue;
count++;
- callCallback(this,key,toArgs(nb,result));
+ callCallback(this,key,toArgs(regexp));
}
return count;
}
@@ -105,10 +106,10 @@ class SelfIvyClient extends IvyClient {
}
}
- private String[] toArgs(int nb,REMatch result) {
- String[] args = new String[nb];
- for(int sub=1;sub<=nb;sub++) {
- args[sub-1]=result.toString(sub);
+ private String[] toArgs(RE re) {
+ String[] args = new String[re.getParenCount()-1];
+ for(int sub=1;sub<re.getParenCount();sub++) {
+ args[sub-1]=re.getParen(sub);
if (bus.doProtectNewlines) args[sub-1]=decode(args[sub-1]);
}
return args;