aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rwxr-xr-xsrc/Ivy.java29
-rwxr-xr-xsrc/IvyClient.java22
-rw-r--r--src/Makefile6
-rw-r--r--src/Probe.java16
4 files changed, 50 insertions, 23 deletions
diff --git a/src/Ivy.java b/src/Ivy.java
index f7511ba..ad8a4e6 100755
--- a/src/Ivy.java
+++ b/src/Ivy.java
@@ -12,7 +12,6 @@ import java.net.*;
import java.io.*;
import java.util.Vector;
import java.util.Hashtable;
-import java.util.StringTokenizer;
/**
* A class connecting to the Ivy software bus.
@@ -260,11 +259,29 @@ public class Ivy implements Runnable, IvyApplicationListener {
if (callback==null){
throw new IvyException("(callCallback) Not regexp matching id "+key.intValue());
}
- StringTokenizer st = new StringTokenizer(msgarg,IvyClient.EndArg);
- String args[] = new String[st.countTokens()];
- int i=0;
- while (st.hasMoreTokens()){ args[i++] = st.nextToken();}
- callback.receive( client, args );
+ String[] tab= myTokenize(msgarg,IvyClient.EndArg);
+ System.out.println("received " + tab.length + " args");
+ callback.receive( client, tab);
+ }
+
+ private static String[] myTokenize(String s,String separator) {
+ int index=0, last=0, length=s.length();
+ Vector v = new Vector();
+ if (length!=0) while (true) {
+ index=s.indexOf(separator,last);
+ if (index==-1) {
+ v.add(s.substring(last,length));
+ break;
+ } else if (index<s.length()) {
+ v.add(s.substring(last,index));
+ last=index+1;
+ } else {
+ break;
+ }
+ }
+ String[] tab = new String[v.size()];
+ v.copyInto(tab);
+ return tab;
}
diff --git a/src/IvyClient.java b/src/IvyClient.java
index 069a45b..4faeb00 100755
--- a/src/IvyClient.java
+++ b/src/IvyClient.java
@@ -100,6 +100,10 @@ public class IvyClient extends Thread {
RE regexp = (RE)regexp_in.get(key);
REMatch result = regexp.getMatch(message);
if ( result != null ) {
+ // it's just to check if matching went right.... It is right.
+ //String tmp="";
+ //for (int i=1;i<=regexp.getNumSubs();i++) { tmp+="'"+result.toString(i)+"' "; }
+ //System.out.println(">> matching "+regexp.getNumSubs()+" blocks "+tmp);
send(Msg,key,regexp.getNumSubs(),result);
count++;
}
@@ -160,14 +164,8 @@ public class IvyClient extends Thread {
break;
}
if(!st.hasMoreTokens()){close("Bad format no id '"+msg+"'");break;}
- /* IST */
token=st.nextToken(StartArg).trim();
- /*
- * TODO
- * this doesn't work on jdk1.3 !!!
- * the token equals " 3992", which provoques a NumberFormatException
- */
try {
msgid=Integer.valueOf(token);
} catch ( NumberFormatException e ) {
@@ -175,13 +173,20 @@ public class IvyClient extends Thread {
break;
}
String msgarg="";
- if (st.hasMoreTokens()) msgarg=st.nextToken("\n").trim();
+ // if (st.hasMoreTokens()) msgarg=st.nextToken("\n").trim();
+ if (st.hasMoreTokens()) msgarg=st.nextToken("\n");
+ // TODO: here is a bug !
+ // quick and dirty fix: I do the trimming by hand later on.
+ // (cf ref: This method may be used to trim whitespace from the
+ // beginning and end of a string; in fact, it trims all ASCII control characters as well.
+
/*
* second stage: process the message
*/
switch (msgtype) {
case Bye: break;
case AddRegexp:
+ msgarg.trim();
if ( bus.CheckRegexp(msgarg) ) {
try {
regexp_in.put(msgid,new RE(msgarg));
@@ -208,7 +213,7 @@ public class IvyClient extends Thread {
break;
case Msg:
try {
- bus.callCallback(this,msgid,msgarg);
+ bus.callCallback(this,msgid,msgarg.substring(1,msgarg.length()-1));
} catch (IvyException ie) {
// calling an inexistant callback
System.err.println("calling an inexistant callback, the caller must be wrong !");
@@ -226,6 +231,7 @@ public class IvyClient extends Thread {
}
break;
case DirectMsg:
+ msgarg.trim();
bus.directMessage( this, msgid.intValue(), msgarg );
break;
case Die:
diff --git a/src/Makefile b/src/Makefile
index f37bae6..18beb1c 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -3,7 +3,7 @@
JAVACOPTS = -d . -deprecation $(CLASSPATH)
SRCS = *.java
JAR = ../lib/Ivy.jar
- VER = 1.0.5
+ VER = 1.0.7
DIST = ../lib/ivy-java-$(VER).jar
JAVAC = jikes
# JAVAC = javac
@@ -20,11 +20,11 @@ clean:
ctags $(SRCS)
jar:
- fastjar cvfm $(JAR) manifest fr
+ fastjar cvfm $(JAR) ../manifest fr
dist:
cd ..
- fastjar cvfm $(DIST) manifest fr src debian redhat doc Makefile manifest TODO
+ fastjar cvfm $(DIST) ../manifest fr src debian redhat doc Makefile manifest TODO
docs:
rm -fR $(DOCS)/*
diff --git a/src/Probe.java b/src/Probe.java
index 84e282f..6e4543b 100644
--- a/src/Probe.java
+++ b/src/Probe.java
@@ -12,11 +12,11 @@ import java.io.*;
*/
class Probe implements IvyApplicationListener, IvyMessageListener {
- public static void main(String[] args) {
+ public static void main(String[] args) throws IvyException {
Probe p = new Probe();
Getopt opt = new Getopt("Probe",args,"b:d");
int c;
- String domain=Ivy.DEFAULT_DOMAIN;
+ String domain=Ivy.getDomain(null);
while ((c = opt.getopt()) != -1) switch (c) {
case 'b':
domain=opt.getOptarg();
@@ -37,11 +37,10 @@ class Probe implements IvyApplicationListener, IvyMessageListener {
System.out.println("broadcasting on "+domain);
bus.start(domain);
String s;
- BufferedReader in =
- new BufferedReader(new InputStreamReader(System.in));
+ BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
// infinite loop on keyboard input
try {
- while ((s=in.readLine()).length()!=0)
+ while (p.looping() && (s=in.readLine()).length()!=0)
System.out.println("-> Sent to " +bus.sendMsg(s)+" peers");
} catch (NullPointerException e) {
bus.stop();
@@ -53,6 +52,10 @@ class Probe implements IvyApplicationListener, IvyMessageListener {
}
}
+ private boolean looping=true;
+
+ public boolean looping() { return looping ; } // accessor
+
public void connect(IvyClient client) {
System.out.println(client.getApplicationName() + " connected " );
for (java.util.Enumeration e=client.getRegexps();e.hasMoreElements();)
@@ -65,7 +68,8 @@ class Probe implements IvyApplicationListener, IvyMessageListener {
}
public void die(IvyClient client, int id) {
- System.out.println(client.getApplicationName() + " die "+ id );
+ looping=false;
+ System.out.println(client.getApplicationName() + " received die msg from "+ id );
}
public void directMessage(IvyClient client, int id, String arg) {