Mercurial > hg > FederatedLinda
changeset 26:d7d70edc9c7c
META_STOP worked.
author | kono |
---|---|
date | Wed, 20 Aug 2008 17:05:33 +0900 |
parents | 330fa49bc4fd |
children | 1acf423ffdcb |
files | src/fdl/FDLindaServ.java src/fdl/MetaLinda.java src/fdl/MetaReply.java src/fdl/PSX.java src/fdl/PSXLinda.java src/fdl/test/TestPSXLinda.java |
diffstat | 6 files changed, 34 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/src/fdl/FDLindaServ.java Wed Aug 20 14:12:15 2008 +0900 +++ b/src/fdl/FDLindaServ.java Wed Aug 20 17:05:33 2008 +0900 @@ -23,7 +23,7 @@ private AbstractSelector selector; private ServerSocketChannel ssChannel; public TupleSpace tupleSpace; - public NullMetaEngine me; + public MetaEngine me; public static void main(final String[] args) { final String usages = "usage: FDLindaServ [-p port]"; @@ -51,11 +51,9 @@ private void mainLoop() { MetaLinda ml = new MetaLinda(tupleSpace, this); - me = new NullMetaEngine(ml); - // MetaEngine me = new MetaEngine(ml); - while(true) { - me.mainLoop(); - } + // me = new NullMetaEngine(ml); + me = new MetaLogEngine(ml); + me.mainLoop(); } public FDLindaServ(int port) throws IOException {
--- a/src/fdl/MetaLinda.java Wed Aug 20 14:12:15 2008 +0900 +++ b/src/fdl/MetaLinda.java Wed Aug 20 17:05:33 2008 +0900 @@ -32,7 +32,8 @@ public FDLindaServ fds; public FederatedLinda fdl=null; public PSXLinda next=null; - public LinkedList<MetaReply> replies = new LinkedList<MetaReply>(); + private MetaReply replies=new MetaReply(0, 0, ts); + private MetaReply last=replies; public MetaLinda(TupleSpace ts,FDLindaServ fds) { this.ts = ts; @@ -44,7 +45,12 @@ } public void in(int id, PSXCallback callback) { - replies.add(new MetaReply(PSX.PSX_IN,id,ts, callback)); + MetaReply r = new MetaReply(PSX.PSX_IN,id,ts, callback); + addReply(r); + } + + private void addReply(MetaReply r) { + last.next = r; last = r; } public PSXReply ck(int id) { @@ -53,12 +59,13 @@ } public void ck(int id, PSXCallback callback) { - replies.add(new MetaReply(PSX.PSX_CHECK,id,ts,callback)); + MetaReply r = new MetaReply(PSX.PSX_CHECK,id,ts,callback); + addReply(r); } public PSXReply out(int id, ByteBuffer data) { MetaReply r = new MetaReply(PSX.PSX_OUT,id,ts,data,null); - replies.add(r); + addReply(r); return r; } @@ -69,7 +76,7 @@ public void update(int id, ByteBuffer data,PSXCallback callback) { MetaReply r = new MetaReply(PSX.PSX_UPDATE,id,ts,data,callback); - replies.add(r); + addReply(r); } public PSXReply rd(int id) { @@ -78,7 +85,8 @@ } public void rd(int id, PSXCallback callback) { - replies.add(new MetaReply(PSX.PSX_RD,id,ts,callback)); + MetaReply r = new MetaReply(PSX.PSX_RD,id,ts,callback); + addReply(r); } public PSXLinda add(PSXLinda linda) { @@ -93,10 +101,11 @@ public int sync(long timeout) { fds.checkTuple(timeout); - for(MetaReply r: replies) { - if (r.ready()) { - replies.remove(); + for(PSXReply r=replies;r!=null&&r.next!=null;r = r.next) { + if (r.next.ready()) { + r.next = r.next.next; } + if(r!=null) last = (MetaReply)r; } if (fdl!=null) { try {
--- a/src/fdl/MetaReply.java Wed Aug 20 14:12:15 2008 +0900 +++ b/src/fdl/MetaReply.java Wed Aug 20 17:05:33 2008 +0900 @@ -31,6 +31,7 @@ if (data!=null) { this.data = data; mode = PSX.PSX_ANSWER; + if (callback!=null) callback.callback(data); } }
--- a/src/fdl/PSX.java Wed Aug 20 14:12:15 2008 +0900 +++ b/src/fdl/PSX.java Wed Aug 20 17:05:33 2008 +0900 @@ -58,9 +58,9 @@ static final int PRIVILEGED_ID_START = 32768; static final int PRIVILEGED_ID_END = 36864; - static final int META_STOP = PRIVILEGED_ID_START; - static final int META_MONITOR = PRIVILEGED_ID_START+1; - static final int META_MONITOR_DATA = PRIVILEGED_ID_START+2; + static public final int META_STOP = PRIVILEGED_ID_START; + static public final int META_MONITOR = PRIVILEGED_ID_START+1; + static public final int META_MONITOR_DATA = PRIVILEGED_ID_START+2; static void printCommand(String comment, ByteBuffer command, ByteBuffer data) {
--- a/src/fdl/PSXLinda.java Wed Aug 20 14:12:15 2008 +0900 +++ b/src/fdl/PSXLinda.java Wed Aug 20 17:05:33 2008 +0900 @@ -29,4 +29,6 @@ public int sync() throws IOException ; public int sync(long mtime) throws IOException ; + + public void send(ByteBuffer command, ByteBuffer data); }
--- a/src/fdl/test/TestPSXLinda.java Wed Aug 20 14:12:15 2008 +0900 +++ b/src/fdl/test/TestPSXLinda.java Wed Aug 20 17:05:33 2008 +0900 @@ -20,6 +20,7 @@ import fdl.FederatedLinda; import fdl.PSXLinda; import fdl.PSXReply; +import fdl.PSX; /** @@ -73,6 +74,11 @@ } print_id(r); + + data.clear(); + psx.out(PSX.META_STOP, data); + psx.sync(); + } catch (IOException e) { System.err.println("Communication failure."); }