aboutsummaryrefslogtreecommitdiff
path: root/src/ProxyClient.java
diff options
context:
space:
mode:
authorjestin2006-08-01 21:42:25 +0000
committerjestin2006-08-01 21:42:25 +0000
commitfdb4cc200dca5db5b374fc40ab3723eb8bf96886 (patch)
tree0398ad466257c6cacb5c1b28fa6597474025ec3b /src/ProxyClient.java
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...
Diffstat (limited to 'src/ProxyClient.java')
-rw-r--r--src/ProxyClient.java32
1 files changed, 28 insertions, 4 deletions
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);
}
+
+
}