aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjestin2006-08-01 21:42:25 +0000
committerjestin2006-08-01 21:42:25 +0000
commitfdb4cc200dca5db5b374fc40ab3723eb8bf96886 (patch)
tree0398ad466257c6cacb5c1b28fa6597474025ec3b
parent21cec28549587db7e34d0ac455244fe4d73a0ed4 (diff)
downloadivy-java-fdb4cc200dca5db5b374fc40ab3723eb8bf96886.zip
ivy-java-fdb4cc200dca5db5b374fc40ab3723eb8bf96886.tar.gz
ivy-java-fdb4cc200dca5db5b374fc40ab3723eb8bf96886.tar.bz2
ivy-java-fdb4cc200dca5db5b374fc40ab3723eb8bf96886.tar.xz
small steps towards the Ivy tunnel . This is work in progress...
-rw-r--r--src/Ghost.java15
-rw-r--r--src/Makefile4
-rw-r--r--src/ProxyClient.java32
-rw-r--r--src/ProxyMaster.java8
-rw-r--r--src/Puppet.java39
5 files changed, 83 insertions, 15 deletions
diff --git a/src/Ghost.java b/src/Ghost.java
index ad6e78c..fd7465d 100644
--- a/src/Ghost.java
+++ b/src/Ghost.java
@@ -22,18 +22,21 @@ class Ghost extends IvyClient {
super(bus,socket,remotePort,incoming);
this.id=id;
this.pc=pc;
+ System.out.println("new Ghost: "+id+" pc:"+pc);
}
+ // ProxyClient -> Ghost -> Ivy Bus
protected synchronized void sendBuffer( String buffer ) throws IvyException {
- System.out.println("out buffer: "+buffer);
- pc.forward(id,buffer);
- super.sendBuffer(buffer);
+ // System.out.println("out buffer: "+buffer+" for:"+pc+" id:"+id);
+ super.sendBuffer(buffer); // and to all the agents on the Ghost bus ? I'm not sure
}
+ // Bus -> Ghost -> ProxyClient -> ProxyMaster -> other buses
protected boolean newParseMsg(String s) throws IvyException {
- System.out.println("in buffer: "+s);
- pc.forward(id,buffer);
- return super.newParseMsg(s);
+ // I received a message from an agent on the bus
+ System.out.println("in buffer to forward from "+id+": "+s);
+ if (pc!=null) pc.forward(id,s); // forward to all the puppets
+ return super.newParseMsg(s); // I'll take no action
}
}
diff --git a/src/Makefile b/src/Makefile
index e6a478f..692bbe1 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -2,8 +2,8 @@ include ../java.mk
#.SUFFIXES: .java .class
#SRCS = *.java
- SRCS = IvyApplicationAdapter.java IvyApplicationListener.java IvyBindListener.java IvyClient.java IvyException.java Ivy.java IvyMessageListener.java IvyWatcher.java SelfIvyClient.java WaiterClient.java Waiter.java PingCallback.java
- TOOLS= IvyDaemon.java Probe.java After.java ProxyMaster.java ProxyClient.java Ghost.java
+ SRCS = IvyApplicationAdapter.java IvyApplicationListener.java IvyBindListener.java IvyClient.java IvyException.java Ivy.java IvyMessageListener.java IvyWatcher.java SelfIvyClient.java WaiterClient.java Waiter.java PingCallback.java Puppet.java ProxyClient.java Ghost.java
+ TOOLS= IvyDaemon.java Probe.java After.java ProxyMaster.java
OBJS = $(SRCS:.java=.class)
DOCS = ../doc/html/api
diff --git a/src/ProxyClient.java b/src/ProxyClient.java
index 3f616c5..d6c6932 100644
--- a/src/ProxyClient.java
+++ b/src/ProxyClient.java
@@ -26,6 +26,8 @@ public class ProxyClient extends Ivy {
private volatile Thread clientThread;// volatile to ensure the quick communication
private Hashtable id=new Hashtable();
private Vector ghosts = new Vector();
+ private Hashtable puppets =new Hashtable(); // key=id value=Puppet
+ String domain=null;
public static int DEFAULT_SERVICE_PORT = 3456 ;
public static final String DEFAULTNAME = "ProxyClient";
@@ -69,10 +71,9 @@ public class ProxyClient extends Ivy {
}
String hostname="localhost";
try {
- ProxyClient pc = new ProxyClient(hostname,servicePort);
+ ProxyClient pc = new ProxyClient(hostname,servicePort,domain);
if (!quiet) System.out.println("broadcasting on "+pc.domains(domain));
if (!quiet) System.out.println("contacting tcp:"+hostname+":"+servicePort);
- pc.start(domain);
System.out.println("client running...");
} catch (IvyException ie) {
System.out.println("error, can't connect to Ivy");
@@ -85,29 +86,39 @@ public class ProxyClient extends Ivy {
}
}
- public ProxyClient(String hostname,int servicePort) throws IOException {
+ public ProxyClient(String hostname,int servicePort,String domain) throws IOException, IvyException {
super(name,name+" ready",null);
clientSocket = new Socket(hostname,servicePort) ;
in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
out = new PrintWriter(new OutputStreamWriter(clientSocket.getOutputStream()));
clientThread=new Thread(new Servicer());
clientThread.start();
+ this.domain=domain;
+ start(domain);
}
RE getId=new RE("^ID id=(.*) value=(.*)");
RE fwd=new RE("^Forward id=(.*) buffer=(.*)");
+ RE puppetRe=new RE("^CreatePuppet id=(.*)");
void parseMsg(String msg) {
System.out.println("parsing "+msg);
if (getId.match(msg)) {
id.put(getId.getParen(1),getId.getParen(2));
+ } else if (puppetRe.match(msg)) {
+ // I must create a puppet
+ puppets.put(puppetRe.getParen(1),new Puppet(this,domain));
} else if (fwd.match(msg)) {
// received a forward request
// TODO give it to the puppet
+ Puppet p = (Puppet)puppets.get(fwd.getParen(1));
+ p.parse(fwd.getParen(2));
} else {
System.out.println("unknown message "+msg);
}
}
+ void removePuppet(Puppet p){puppets.remove(p);}
+
class Servicer implements Runnable {
public void run() {
Thread thisThread = Thread.currentThread();
@@ -126,9 +137,15 @@ public class ProxyClient extends Ivy {
}
traceDebug("Subreader Thread stopped");
System.out.println("ProxyClient disconnected");
+ stop(); // leave the bus TODO: make a disconnexion/reconnexion possible ?
}
}
+ /*
+ * here, I create a ghost instead of a normal Ivy Client, to catch the
+ * protocol and forward everything to the proxies.
+ * TODO: remember everything in case a new proxy client comes ?
+ */
protected IvyClient createIvyClient(Socket s,int port, boolean domachin) throws IOException {
String key = getWBUId();
System.out.println("asking for a key");
@@ -143,7 +160,12 @@ public class ProxyClient extends Ivy {
return new Ghost(this,s,port,domachin,(String)id.get(key),this);
}
- private void forward(String id,String buffer) {
+ /*
+ * the function to forward the protocol to all the Puppets through the
+ * ProxyMaster
+ *
+ */
+ protected void forward(String id,String buffer) {
out.println("Forward id="+id+" buffer="+buffer);
out.flush();
}
@@ -152,4 +174,6 @@ public class ProxyClient extends Ivy {
if (debug) System.out.println("-->ProxyClient "+name+"<-- "+s);
}
+
+
}
diff --git a/src/ProxyMaster.java b/src/ProxyMaster.java
index 7ed9460..09216ed 100644
--- a/src/ProxyMaster.java
+++ b/src/ProxyMaster.java
@@ -9,7 +9,7 @@
* changelog:
* 1.2.12
*/
-package fr.dgac.ivy ;
+package fr.dgac.ivy ; // TODO go into sub tools, and build a shell/.BAT script
import java.io.*;
import java.net.*;
import java.util.* ;
@@ -122,8 +122,10 @@ public class ProxyMaster {
out.println("ID id="+getId.getParen(1)+" value="+newGhostId);
out.flush();
// TODO create Puppets in each other ProxyClient
- for (Enumeration e=proxyClients.elements();e.hasMoreElements();)
- ((SubReader)e.nextElement()).send("CreatePuppet id="+newGhostId);
+ for (Enumeration e=proxyClients.elements();e.hasMoreElements();) {
+ SubReader sr = (SubReader)e.nextElement();
+ if (sr!=SubReader.this) sr.send("CreatePuppet id="+newGhostId);
+ }
} else if (fwd.match(msg)) {
System.out.println("forwarding "+msg);
// TODO forward the message to all relevant puppets
diff --git a/src/Puppet.java b/src/Puppet.java
new file mode 100644
index 0000000..d122d52
--- /dev/null
+++ b/src/Puppet.java
@@ -0,0 +1,39 @@
+package fr.dgac.ivy ;
+import java.lang.Thread;
+import java.net.*;
+import java.io.*;
+import java.util.*;
+import org.apache.regexp.*;
+
+class Puppet extends Ivy {
+
+ Hashtable bound = new Hashtable(); // clef: l'ID de la regexp choisi par le ghost, valeur: l'Int de l'abonnement local
+ String myDomain;
+ ProxyClient pc;
+
+ Puppet(ProxyClient pc,String domain) {
+ super("noname","noname not ready",null);
+ myDomain=domain;
+ this.pc=pc;
+ }
+
+ void parse(String s){
+ System.out.println("the puppet must parse "+s);
+ }
+
+ protected IvyClient createIvyClient(Socket s,int port, boolean domachin) throws IOException {
+ return new PuppetClient();
+ }
+
+ class PuppetClient extends IvyClient {
+ protected synchronized void sendBuffer( String buffer ) throws IvyException {
+ super.sendBuffer(buffer); // and to all the agents on the Ghost bus ? I'm not sure
+ }
+
+ protected boolean newParseMsg(String s) throws IvyException {
+ return super.newParseMsg(s);
+ }
+ } // class PuppetClient
+
+}
+