aboutsummaryrefslogtreecommitdiff
path: root/src/Ivy.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/Ivy.java')
-rwxr-xr-xsrc/Ivy.java66
1 files changed, 56 insertions, 10 deletions
diff --git a/src/Ivy.java b/src/Ivy.java
index 15926bc..5e149ec 100755
--- a/src/Ivy.java
+++ b/src/Ivy.java
@@ -22,7 +22,12 @@ import java.util.*;
*</pre>
*
* CHANGELOG:
- * 1.0.12:
+ * 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)
+ * 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
@@ -55,7 +60,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.0";
+ public static final String libVersion ="1.2.1";
private boolean debug;
private static int serial=0; /* an unique ID for each regexp */
@@ -107,6 +112,7 @@ public class Ivy implements Runnable {
*
*/
public void start(String domainbus) throws IvyException {
+ if (domainbus==null) domainbus=DEFAULT_DOMAIN;
try {
app = new ServerSocket(0);
app.setSoTimeout(TIMEOUTLENGTH);
@@ -117,13 +123,10 @@ public class Ivy implements Runnable {
traceDebug("lib: "+libVersion+" protocol: "+PROCOCOLVERSION+" TCP service open on port "+applicationPort);
watchers = new Vector();
+ Domain[] d = parseDomains(domainbus);
// readies the rendezvous : an IvyWatcher (thread) per domain bus
- StringTokenizer st = new StringTokenizer(domainbus,",");
- while ( st.hasMoreTokens()) {
- String s = st.nextToken() ;
- String domainaddr=IvyWatcher.getDomain(s);
- int port=IvyWatcher.getPort(s);
- IvyWatcher watcher =new IvyWatcher(this,domainaddr,port);
+ for (int index=0;index<d.length;index++){
+ IvyWatcher watcher =new IvyWatcher(this,d[index].domainaddr,d[index].port);
watchers.addElement(watcher);
}
serverThread = new Thread(this);
@@ -132,6 +135,17 @@ public class Ivy implements Runnable {
for (int i=0;i<watchers.size();i++){ ((IvyWatcher)watchers.elementAt(i)).start(); }
}
+ public Domain[] parseDomains(String domainbus) {
+ StringTokenizer st = new StringTokenizer(domainbus,",");
+ Domain[] d = new Domain[st.countTokens()];
+ int index=0;
+ while ( st.hasMoreTokens()) {
+ String s = st.nextToken() ;
+ d[index++]=new Domain(IvyWatcher.getDomain(s),IvyWatcher.getPort(s));
+ }
+ return d;
+ }
+
/**
* disconnects from the Ivy bus
*/
@@ -142,7 +156,7 @@ public class Ivy implements Runnable {
// stopping the serverThread
Thread t=serverThread;
serverThread=null;
- t.interrupt();
+ if (t!=null) t.interrupt(); // The serverThread might be stopped even before having been created
app.close();
// stopping the IvyWatchers
for (int i=0;i<watchers.size();i++){ ((IvyWatcher)watchers.elementAt(i)).stop(); }
@@ -234,6 +248,28 @@ public class Ivy implements Runnable {
}
/**
+ * unsubscribes a regular expression
+ *
+ * @return a boolean, true if the regexp existed, false otherwise or
+ * whenever an exception occured during unbinding
+ * @param String the string for the regular expression
+ */
+ public boolean unBindMsg(String re) {
+ for (Enumeration e=regexp_out.keys();e.hasMoreElements();) {
+ Integer k = (Integer)e.nextElement();
+ if ( ((String)regexp_out.get(k)).compareTo(re) == 0) {
+ try {
+ unBindMsg(k.intValue());
+ } catch (IvyException ie) {
+ return false;
+ }
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
* adds an application listener to a bus
* @param callback is an object implementing the IvyApplicationListener
* interface
@@ -425,13 +461,23 @@ public class Ivy implements Runnable {
return s;
}
+ class Domain {
+ private String domainaddr;
+ private 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; }
+ public int getPort() { return port; }
+ }
+
+
/*
* unitary test. Normally, running java fr.dgac.ivy.Ivy should stop in 2.3 seconds :)
*/
public static void main(String[] args) {
Ivy bus = new Ivy("Test Unitaire","TU ready",null);
try {
- bus.start(DEFAULT_DOMAIN);
+ bus.start(null);
try { Thread.sleep(2000); } catch (InterruptedException ie) { }
bus.stop();
} catch (IvyException ie) {