aboutsummaryrefslogtreecommitdiff
path: root/src/Puppet.java
diff options
context:
space:
mode:
authorjestin2011-07-22 16:49:57 +0000
committerjestin2011-07-22 16:49:57 +0000
commit750f33265d208df8218f85359e3f027900c58363 (patch)
tree105db356fc9b87fc04f1c09a4c2a567e93b37eed /src/Puppet.java
parent90ac7a3566995cc244f9fdaff41e6c5122c7ca2e (diff)
downloadivy-java-750f33265d208df8218f85359e3f027900c58363.zip
ivy-java-750f33265d208df8218f85359e3f027900c58363.tar.gz
ivy-java-750f33265d208df8218f85359e3f027900c58363.tar.bz2
ivy-java-750f33265d208df8218f85359e3f027900c58363.tar.xz
Passage en 1.2.14
Diffstat (limited to 'src/Puppet.java')
-rw-r--r--src/Puppet.java52
1 files changed, 29 insertions, 23 deletions
diff --git a/src/Puppet.java b/src/Puppet.java
index 5398798..17844ea 100644
--- a/src/Puppet.java
+++ b/src/Puppet.java
@@ -7,6 +7,9 @@
* (c) CENA 1998-2004
*
* CHANGELOG:
+ * 1.2.14
+ * - switch from gnu regexp (deprecated) to the built in java regexp
+ * - add generic types to declarations
* 1.2.13:
* - adds support for RESyntaxException
*/
@@ -16,13 +19,13 @@ import java.lang.Thread;
import java.net.*;
import java.io.*;
import java.util.*;
-import org.apache.regexp.*;
+import java.util.regex.*;
class Puppet {
// the mapping between Ghost regexp and local bus regexp numbers
- Hashtable bound = new Hashtable(); // ghostID localID
- Hashtable regexps = new Hashtable(); // ghostID textRegexp
+ Hashtable<String,String> bound = new Hashtable<String,String>(); // ghostID localID
+ Hashtable<String,String>regexps = new Hashtable<String,String>(); // ghostID textRegexp
String domain;
String appName;
ProxyClient pc;
@@ -42,13 +45,19 @@ class Puppet {
String localId,ghostId;
public ForwardMessenger(String ghostId,String re) throws IvyException {
this.ghostId=ghostId;
- this.localId = (new Integer(bus.bindMsg(re,ForwardMessenger.this))).toString();
+ this.localId = Integer.valueOf(bus.bindMsg(re,ForwardMessenger.this)).toString();
bound.put(ghostId,localId);
}
public void receive(IvyClient ic,String args[]) {
- String tosend = IvyClient.Msg+" "+ghostId+IvyClient.StartArg;
- for (int i=0;i<args.length;i++) tosend+=args[i]+IvyClient.EndArg;
- sendGhost(tosend);
+ StringBuffer tosend = new StringBuffer(IvyClient.Msg);
+ tosend.append(" ");
+ tosend.append(ghostId);
+ tosend.append(IvyClient.StartArg);
+ for (int i=0;i<args.length;i++) {
+ tosend.append(args[i]);
+ tosend.append(IvyClient.EndArg);
+ }
+ sendGhost(tosend.toString());
}
} // ForwardMessenger
@@ -70,12 +79,12 @@ class Puppet {
}
// ivy forwarded protocol message
- static RE ivyProto;
+ static Pattern ivyProto;
static {
try {
- ivyProto = new RE("(\\d+) (\\d+)\\02(.*)");
- } catch ( RESyntaxException res ) {
+ ivyProto = Pattern.compile("(\\d+) (\\d+)\\02(.*)");
+ } catch (PatternSyntaxException res ) {
res.printStackTrace();
System.out.println("Regular Expression bug in Ivy source code ... bailing out");
System.exit(0);
@@ -83,10 +92,11 @@ class Puppet {
}
void parse(String s) throws IvyException {
- if (!ivyProto.match(s)) { System.out.println("Puppet error, can't parse "+s); return; }
- int pcode=Integer.parseInt(ivyProto.getParen(1));
- String pid=ivyProto.getParen(2);
- String args=ivyProto.getParen(3);
+ Matcher m;
+ if (!(m=ivyProto.matcher(s)).matches()) { System.out.println("Puppet error, can't parse "+s); return; }
+ int pcode=Integer.parseInt(m.group(1));
+ String pid=m.group(2);
+ String args=m.group(3);
trace("must parse code:"+pcode+" id:"+pid+" args:"+args);
switch (pcode) {
case IvyClient.AddRegexp: // the Ghost's peer subscribes to something
@@ -105,16 +115,12 @@ class Puppet {
case IvyClient.Msg:
// the Ghost's peer sends a message to ProxyClient, with regard to one
// of our subscriptions
- // TODO à qui le faire passer ?
+ // TODO a qui le faire passer ?
break;
case IvyClient.SchizoToken:
appName = args;
bus = new PuppetIvy(appName,appName+" fakeready",null);
- for (Enumeration e = regexps.keys();e.hasMoreElements();) {
- String ghostId=(String)e.nextElement();
- String re=(String)regexps.get(ghostId);
- new ForwardMessenger(ghostId,re);
- }
+ for ( String ghostId: regexps.keySet() )new ForwardMessenger(ghostId,regexps.get(ghostId));
started=true;
trace("starting the bus on "+domain);
bus.start(domain);
@@ -129,15 +135,15 @@ class Puppet {
}
}
- class PuppetIvy extends Ivy {
+ static class PuppetIvy extends Ivy {
PuppetIvy(String name,String ready,IvyApplicationListener ial){super(name,ready,ial);}
protected IvyClient createIvyClient(Socket s,int port, boolean domachin) throws IOException {
return new PuppetIvyClient(PuppetIvy.this,s,port,domachin);
}
- int getAP() {return applicationPort;}
+ int getAP() {return getAppPort();}
}
- class PuppetIvyClient extends IvyClient {
+ static class PuppetIvyClient extends IvyClient {
PuppetIvyClient(Ivy bus,Socket s,int port,boolean b) throws IOException { super(bus,s,port,b); }
protected synchronized void sendBuffer( String s ) throws IvyException {
super.sendBuffer(s); // and to all the agents on the Ghost bus ? I'm not sure