aboutsummaryrefslogtreecommitdiff
path: root/src/Ivy.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/Ivy.java')
-rwxr-xr-xsrc/Ivy.java92
1 files changed, 40 insertions, 52 deletions
diff --git a/src/Ivy.java b/src/Ivy.java
index 7d26dff..2647434 100755
--- a/src/Ivy.java
+++ b/src/Ivy.java
@@ -13,6 +13,8 @@
*</pre>
*
* CHANGELOG:
+ * 1.2.12:
+ * - directMessage goes protected
* 1.2.9:
* - introducing setFilter()
* - introducing IVYRANGE in to allow the bus service socket to start on a
@@ -647,14 +649,14 @@ public class Ivy implements Runnable {
}
/* invokes the direct message callbacks */
- public void directMessage( IvyClient client, int id,String msgarg ){
+ protected void directMessage( IvyClient client, int id,String msgarg ){
for ( int i = 0 ; i < ivyApplicationListenerList.size(); i++ ) {
((IvyApplicationListener)ivyApplicationListenerList.elementAt(i)).directMessage(client,id, msgarg);
}
}
/**
- * gives the IvyClient() at a given instant
+ * gives the (Vectored) list of IvyClient at a given instant
*/
public Vector getIvyClients() {
Vector v=new Vector();
@@ -670,7 +672,7 @@ public class Ivy implements Runnable {
}
/**
- * gives a list of IvyClient(s) with the name given in parameter
+ * gives a list of IvyClient with the name given in parameter
*
* @param name The name of the Ivy agent you're looking for
*/
@@ -689,32 +691,7 @@ public class Ivy implements Runnable {
return v;
}
- /////////////////////////////////////////////////////////////////:
- //
- // Protected methods
- //
- /////////////////////////////////////////////////////////////////:
- 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.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);
- return tab;
- }
-
- /**
+ /**
* returns the domain bus
*
* @param domainbus if non null, returns the argument
@@ -722,13 +699,13 @@ public class Ivy implements Runnable {
* otherwise it returns the IVYBUS property if non null, otherwise it
* returns Ivy.DEFAULT_DOMAIN
*/
- public static String getDomain(String domainbus) {
+ public static String getDomain(String domainbus) {
if ( domainbus == null ) domainbus = System.getProperty("IVYBUS");
if ( domainbus == null ) domainbus = DEFAULT_DOMAIN;
return domainbus;
}
- /**
+ /**
* returns the domain bus
*
* @since 1.2.8
@@ -744,7 +721,7 @@ public class Ivy implements Runnable {
return getDomain(null);
}
- /**
+ /**
* returns a "wana be unique" ID to make requests on the bus
*
* @since 1.2.8
@@ -755,7 +732,31 @@ public class Ivy implements Runnable {
}
private synchronized long nextId() { return current++; }
- synchronized void addClient(IvyClient c) {
+
+ /**
+ * prints a human readable representation of the list of domains
+ *
+ * @since 1.2.9
+ */
+ public String domains(String toparse) {
+ String s="";
+ Ivy.Domain[] d = parseDomains(toparse);
+ for (int index=0;index<d.length;index++) {
+ s+=d[index].getDomainaddr()+":"+d[index].getPort()+" ";
+ }
+ return s;
+ }
+ /////////////////////////////////////////////////////////////////:
+ //
+ // Protected methods
+ //
+ /////////////////////////////////////////////////////////////////:
+
+ protected IvyClient createIvyClient(Socket s,int port, boolean domachin) throws IOException {
+ return new IvyClient(this,s,port,domachin);
+ }
+
+ protected synchronized void addClient(IvyClient c) {
if (clients==null||c==null) return;
synchronized (clients) {
clients.put(c.getClientKey(),c);
@@ -763,25 +764,25 @@ public class Ivy implements Runnable {
}
}
- synchronized void removeClient(IvyClient c) {
+ protected synchronized void removeClient(IvyClient c) {
synchronized (clients) {
clients.remove(c.getClientKey());
traceDebug("removed "+c+" from clients: "+getClientNames(clients));
}
}
- void addHalf(IvyClient c) {
+ protected void addHalf(IvyClient c) {
synchronized(half){half.put(c.getClientKey(),c);}
traceDebug("added "+c+" in half: "+getClientNames(half));
}
- void removeHalf(IvyClient c) {
+ protected void removeHalf(IvyClient c) {
if (half==null||c==null) return;
synchronized(half){half.remove(c.getClientKey());}
traceDebug("removed "+c+" from half: "+getClientNames(half));
}
- boolean shouldIleave(IvyClient ic) {
+ private boolean shouldIleave(IvyClient ic) {
traceDebug("looking for "+ic+" in "+getClientNames(half)+" and "+getClientNames(clients));
IvyClient peer=searchPeer(ic);
if (peer==null) return false;
@@ -816,7 +817,7 @@ public class Ivy implements Runnable {
try {
Socket socket = app.accept();
if ((thisThread!=serverThread)||stopped) break; // early disconnexion
- new IvyClient(this,socket,0,true); // the peer called me
+ createIvyClient(socket,0,true); // the peer called me
} catch (InterruptedIOException ie) {
// traceDebug("server socket was interrupted. good");
if (thisThread!=serverThread) break;
@@ -859,17 +860,7 @@ public class Ivy implements Runnable {
return s+")";
}
- public String domains(String toparse) {
- String s="";
- Ivy.Domain[] d = parseDomains(toparse);
- for (int index=0;index<d.length;index++) {
- s+=d[index].getDomainaddr()+":"+d[index].getPort()+" ";
- }
- return s;
- }
-
-
- class Domain {
+ private class Domain {
String domainaddr;
int port;
public Domain(String domainaddr,int port) {this.domainaddr=domainaddr;this.port=port;}
@@ -878,7 +869,6 @@ public class Ivy implements Runnable {
public int getPort() { return port; }
}
-
// 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);
@@ -897,5 +887,3 @@ public class Ivy implements Runnable {
}
} // class Ivy
-
-/* EOF */