aboutsummaryrefslogtreecommitdiff
path: root/src/Ivy.java
diff options
context:
space:
mode:
authorjestin2003-01-07 10:39:13 +0000
committerjestin2003-01-07 10:39:13 +0000
commit2e2578904b5c3b6e2470bff1fa147631142ee5df (patch)
tree676a38bc0c42987b1bea86b7e6d6e379e3605d8a /src/Ivy.java
parentc23f7ec61f2b57ffb6cf5057a453dafe89416ef1 (diff)
downloadivy-java-2e2578904b5c3b6e2470bff1fa147631142ee5df.zip
ivy-java-2e2578904b5c3b6e2470bff1fa147631142ee5df.tar.gz
ivy-java-2e2578904b5c3b6e2470bff1fa147631142ee5df.tar.bz2
ivy-java-2e2578904b5c3b6e2470bff1fa147631142ee5df.tar.xz
Lotsa changes. Voire Changelog pour les détails, ou les en-têtes de chaque
fichier.
Diffstat (limited to 'src/Ivy.java')
-rwxr-xr-xsrc/Ivy.java85
1 files changed, 43 insertions, 42 deletions
diff --git a/src/Ivy.java b/src/Ivy.java
index b3f8bfb..fbc9161 100755
--- a/src/Ivy.java
+++ b/src/Ivy.java
@@ -1,20 +1,9 @@
/**
* a software bus package
*
- * @author François-Régis Colin
* @author Yannick Jestin
* @author <a href="http://www.tls.cena.fr/products/ivy/">http://www.tls.cena.fr/products/ivy/</a>
*
- */
-package fr.dgac.ivy ;
-
-import java.net.*;
-import java.io.*;
-import java.util.*;
-
-/**
- * A class connecting to the Ivy software bus.
- * For example:
*<pre>
*Ivy bus = new Ivy("Dummy agent","ready",null);
*bus.bindMsg("(.*)",myMessageListener);
@@ -22,25 +11,34 @@ import java.util.*;
*</pre>
*
* CHANGELOG:
+ * 1.2.3:
+ * - adds a IVYBUS property to propagate the domain once set. This way,
+ * children forked through Ivy java can inherit from the current value.
+ * - adds synchronized flags to allow early disconnexion
* 1.2.2:
- * - added the String domains(String d) function, in order to display the
+ * added the String domains(String d) function, in order to display the
* domain list
* 1.2.1:
- * - bus.start(null) now starts on DEFAULT_DOMAIN
- * - added the getDomains in order to correctly display the domain list
- * - checks if the serverThread exists before interrupting it
- * - no has unBindMsg(String)
+ * bus.start(null) now starts on DEFAULT_DOMAIN
+ * added the getDomains in order to correctly display the domain list
+ * checks if the serverThread exists before interrupting it
+ * no has unBindMsg(String)
* 1.2.0:
- * - setSoTimeout is back on the server socket
- * - added a regression test main()
- * - clients is now a Hashtable. the deletion now works better
- * - getIvyClientsByName allows the research of IvyClient by name
- * - getDomain doesnt throw IvyException anymore
- * - removed the close() disconnect(IvyClient c). Fixes a big badaboum bug
- * - getDomain becomes public
- * - adding the sendToSelf feature
- * - fixed the printStackTrace upon closing of the ServerSocket after a close()
+ * setSoTimeout is back on the server socket
+ * added a regression test main()
+ * clients is now a Hashtable. the deletion now works better
+ * getIvyClientsByName allows the research of IvyClient by name
+ * getDomain doesnt throw IvyException anymore
+ * removed the close() disconnect(IvyClient c). Fixes a big badaboum bug
+ * getDomain becomes public
+ * adding the sendToSelf feature
+ * fixed the printStackTrace upon closing of the ServerSocket after a close()
*/
+package fr.dgac.ivy ;
+import java.net.*;
+import java.io.*;
+import java.util.*;
+
public class Ivy implements Runnable {
/**
@@ -63,7 +61,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.2";
+ public static final String libVersion ="1.2.3";
private boolean debug;
private static int serial=0; /* an unique ID for each regexp */
@@ -116,6 +114,8 @@ public class Ivy implements Runnable {
*/
public void start(String domainbus) throws IvyException {
if (domainbus==null) domainbus=DEFAULT_DOMAIN;
+ Properties sysProp = System.getProperties();
+ sysProp.put("IVYBUS",domainbus);
try {
app = new ServerSocket(0);
app.setSoTimeout(TIMEOUTLENGTH);
@@ -152,8 +152,9 @@ public class Ivy implements Runnable {
/**
* disconnects from the Ivy bus
*/
- public void stop() {
- if (stopped ) return;
+ public synchronized void stop() {
+ if (stopped) return;
+ stopped=true;
traceDebug("beginning stopping the bus");
try {
// stopping the serverThread
@@ -173,7 +174,6 @@ public class Ivy implements Runnable {
traceDebug("IOexception Stop ");
}
traceDebug("the bus should have stopped so far");
- stopped = true;
}
/**
@@ -360,9 +360,9 @@ public class Ivy implements Runnable {
//
/////////////////////////////////////////////////////////////////:
- void addClient(Socket socket,boolean peerCalling) throws IOException {
- IvyClient client = new IvyClient(
- this, socket,peerCalling,new Integer(clientSerial++));
+ synchronized void addClient(Socket socket,boolean peerCalling) throws IOException {
+ if (stopped) return;
+ IvyClient client = new IvyClient( this, socket,peerCalling,new Integer(clientSerial++));
clients.put(client.getClientKey(),client);
traceDebug(getClientNames());
}
@@ -379,16 +379,16 @@ public class Ivy implements Runnable {
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.addElement(s.substring(last,length));
- break;
- } else if (index<s.length()) {
- v.addElement(s.substring(last,index));
- last=index+1;
- } else {
- break;
- }
+ index=s.indexOf(separator,last);
+ if (index==-1) {
+ v.addElement(s.substring(last,length));
+ break;
+ } else if (index<s.length()) {
+ v.addElement(s.substring(last,index));
+ last=index+1;
+ } else {
+ break;
+ }
}
String[] tab = new String[v.size()];
v.copyInto(tab);
@@ -439,6 +439,7 @@ public class Ivy implements Runnable {
while(thisThread==serverThread){
try {
Socket socket = app.accept();
+ if ((thisThread!=serverThread)||stopped) break; // early disconnexion
addClient(socket,true); // the peer called me
} catch (InterruptedIOException ie) {
if (thisThread!=serverThread) break;