aboutsummaryrefslogtreecommitdiff
path: root/src/Ivy.java
diff options
context:
space:
mode:
authorjestin2004-07-27 16:21:38 +0000
committerjestin2004-07-27 16:21:38 +0000
commitfd9c3e8ea4c7093bff92ec2162ca0be338024fa2 (patch)
treee4f6ea91828a3780310f0381cebf17f20ab9d705 /src/Ivy.java
parent9ab98e8b79688821f85649fa3a04137f83467b73 (diff)
downloadivy-java-fd9c3e8ea4c7093bff92ec2162ca0be338024fa2.zip
ivy-java-fd9c3e8ea4c7093bff92ec2162ca0be338024fa2.tar.gz
ivy-java-fd9c3e8ea4c7093bff92ec2162ca0be338024fa2.tar.bz2
ivy-java-fd9c3e8ea4c7093bff92ec2162ca0be338024fa2.tar.xz
see upstream Changelog and each file's header for detail ...
Diffstat (limited to 'src/Ivy.java')
-rwxr-xr-xsrc/Ivy.java57
1 files changed, 38 insertions, 19 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();
}
}