Mercurial > hg > FederatedLinda
changeset 21:fac6e0073b1a meta-engine-written
*** empty log message ***
author | kono |
---|---|
date | Tue, 19 Aug 2008 10:48:22 +0900 |
parents | a0fd653d1121 |
children | 56e015e8f5dc |
files | src/fdl/FDLindaServ.java src/fdl/FederatedLinda.java src/fdl/MetaEngine.java src/fdl/MetaLinda.java src/fdl/MetaLogEngine.java src/fdl/NullMetaEngine.java src/fdl/TestEtc.java src/fdl/TestPSXLinda.java src/fdl/test/TestEtc.java src/fdl/test/TestPSXLinda.java |
diffstat | 10 files changed, 201 insertions(+), 173 deletions(-) [+] |
line wrap: on
line diff
--- a/src/fdl/FDLindaServ.java Tue Aug 19 06:26:20 2008 +0900 +++ b/src/fdl/FDLindaServ.java Tue Aug 19 10:48:22 2008 +0900 @@ -48,7 +48,8 @@ private void mainLoop() { MetaLinda ml = new MetaLinda(tupleSpace, this); - MetaEngine me = new MetaEngine(ml); + MetaEngine me = new NullMetaEngine(ml); + // MetaEngine me = new MetaEngine(ml); while(true) { me.mainLoop(); }
--- a/src/fdl/FederatedLinda.java Tue Aug 19 06:26:20 2008 +0900 +++ b/src/fdl/FederatedLinda.java Tue Aug 19 10:48:22 2008 +0900 @@ -53,7 +53,7 @@ public PSXReply r_top,r_end; public Hashtable<Integer,PSXReply> seqHash; - static FederatedLinda init() + public static FederatedLinda init() throws IOException { if (fdl==null) { fdl = new FederatedLinda();
--- a/src/fdl/MetaEngine.java Tue Aug 19 06:26:20 2008 +0900 +++ b/src/fdl/MetaEngine.java Tue Aug 19 10:48:22 2008 +0900 @@ -1,44 +1,5 @@ package fdl; -import java.nio.ByteBuffer; - -/** - * @author kono - * Meta Protocol Engine for each Linda Server - */ - -public class MetaEngine { - MetaLinda meta; - boolean running = true; - CommDebugHook commDebug; - - public MetaEngine(MetaLinda meta) { - this.meta = meta; - } - - PSXCallback monitor_callback_start = - new PSXCallback() {public void callback(ByteBuffer reply) { - meta.ts.hook = commDebug = new CommDebugHook(); - ByteBuffer data = ByteBuffer.allocate(0) ; - meta.out(PSX.META_MONITOR_DATA, data, 0); - meta.in(PSX.META_MONITOR,monitor_callback); - }}; - PSXCallback monitor_callback = - new PSXCallback() {public void callback(ByteBuffer reply) { - ByteBuffer data; - do { - data = commDebug.getLog(); - if (data!=null) break; - meta.sync(); - } while (true); - meta.out(PSX.META_MONITOR_DATA, data, data.limit()); - meta.in(PSX.META_MONITOR,monitor_callback); - }}; - - void mainLoop() { - meta.in(PSX.META_MONITOR,monitor_callback_start); - meta.in(PSX.META_STOP, new PSXCallback() {public void callback(ByteBuffer reply) { running = false;}}); - while(running) - meta.sync(); - } -} +public interface MetaEngine { + void mainLoop(); +} \ No newline at end of file
--- a/src/fdl/MetaLinda.java Tue Aug 19 06:26:20 2008 +0900 +++ b/src/fdl/MetaLinda.java Tue Aug 19 10:48:22 2008 +0900 @@ -30,13 +30,13 @@ public TupleSpace ts; public FDLindaServ fds; - public FederatedLinda fdl; - public PSXLindaInterface next; - public LinkedList<MetaReply> replies; + public FederatedLinda fdl=null; + public PSXLindaInterface next=null; + public LinkedList<MetaReply> replies = new LinkedList<MetaReply>(); - public MetaLinda(TupleSpace ts,FDLindaServ fdl) { + public MetaLinda(TupleSpace ts,FDLindaServ fds) { this.ts = ts; - this.fds = fdl; + this.fds = fds; } public PSXReply in(int id) {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/fdl/MetaLogEngine.java Tue Aug 19 10:48:22 2008 +0900 @@ -0,0 +1,44 @@ +package fdl; + +import java.nio.ByteBuffer; + +/** + * @author kono + * Meta Protocol Engine for each Linda Server + */ + +public class MetaLogEngine implements MetaEngine { + MetaLinda meta; + boolean running = true; + CommDebugHook commDebug; + + public MetaLogEngine(MetaLinda meta) { + this.meta = meta; + } + + PSXCallback monitor_callback_start = + new PSXCallback() {public void callback(ByteBuffer reply) { + meta.ts.hook = commDebug = new CommDebugHook(); + ByteBuffer data = ByteBuffer.allocate(0) ; + meta.out(PSX.META_MONITOR_DATA, data, 0); + meta.in(PSX.META_MONITOR,monitor_callback); + }}; + PSXCallback monitor_callback = + new PSXCallback() {public void callback(ByteBuffer reply) { + ByteBuffer data; + do { + data = commDebug.getLog(); + if (data!=null) break; + meta.sync(); + } while (true); + meta.out(PSX.META_MONITOR_DATA, data, data.limit()); + meta.in(PSX.META_MONITOR,monitor_callback); + }}; + + void mainLoop() { + meta.in(PSX.META_MONITOR,monitor_callback_start); + meta.in(PSX.META_STOP, new PSXCallback() {public void callback(ByteBuffer reply) { running = false;}}); + while(running) + meta.sync(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/fdl/NullMetaEngine.java Tue Aug 19 10:48:22 2008 +0900 @@ -0,0 +1,16 @@ +package fdl; + +public class NullMetaEngine implements MetaLogEngine, MetaEngine { + public MetaLinda meta; + public boolean running=true; + + public NullMetaEngine(MetaLinda meta) { + this.meta = meta; + } + + @Override + void mainLoop() { + while(running) + meta.fds.checkTuple(); + } +}
--- a/src/fdl/TestEtc.java Tue Aug 19 06:26:20 2008 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,43 +0,0 @@ - -package fdl; - -import java.io.IOException; -//import java.nio.ByteBuffer; - -public class TestEtc { - static final int MAX_REQ = 1; - static final int FAIL = (-1); - static final int MAX_UAER = 4; - static final int MAX_TUPLE = 65536; - static final int MAX_BUFFSIZE = 2048; - static final int DEF_PORT = 10000; - static final String PATHNAME = "/tmp/ldserv"; - - - static final int LINDA_MODE_OFFSET = 0; - static final int LINDA_ID_OFFSET = 1; - static final int LINDA_SEQ_OFFSET = 3; - static final int LINDA_DATA_LENGTH_OFFSET = 7; - static final int LINDA_HEADER_SIZE = 12; - - static final boolean debug = true; - public PSXQueue tuple_space; - public PSXQueue tp; - - public static void main(String[] args) throws IOException { - String socketString = "java.nio.channels.SocketChannel[connected local=/133.13.57.210:10001 remote=/133.13.57.210:50634]"; - String[] split = socketString.split("/"); - String local[] = split[1].split(" "); - String remote[] = split[2].split("]"); - - @SuppressWarnings("unused") - final String localAddress = local[0]; - @SuppressWarnings("unused") - final String remoteAddress = remote[0]; - - System.out.println(local[0]); - System.out.println(remote[0]); -// System.out.println("tmpTuple "+tmpTuple.toString()); -// System.out.println("testTS "+testTS[MAX_TUPLE-1].toString()); - } -}
--- a/src/fdl/TestPSXLinda.java Tue Aug 19 06:26:20 2008 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,81 +0,0 @@ - -/* - * @(#)TestPSXLinda.java 1.1 06/04/01 - * - * Copyright 2006 Shinji KONO - * - - Test PSX Lidna - - */ - -package fdl; - -import java.io.IOException; -import java.nio.ByteBuffer; - - -/** - * PSXLinda stream - * - * @author Shinji Kono - * - * @param host The host to connect to - * @param port The port to connect to at the host - - */ - - -class TestPSXLinda { - static int id; - public static void main (String args[]) { - - FederatedLinda fdl; - PSXLindaInterface psx; - String host = "localhost"; - int port = 10000; - PSXReply r; - - - // try { - // port = Integer.parseInt(args[1]); - // } catch (NumberFormatException nfex) { } - try { - fdl = FederatedLinda.init(); - psx = fdl.open(host,port); - r = psx.in(65535); - //for(int i=0;i<100;i++) { - //if (1==0) { - //} - fdl.sync(1); - //} - System.out.println("Connected."); - - ByteBuffer data = ByteBuffer.allocate(10); - data.putInt(10); - - psx.out(1,data,4); - - while(!r.ready()) { - psx.sync(1000); - // System.out.println("Waiting...."); - } - } catch (IOException nfex) { - nfex.printStackTrace(); - System.out.println("Faild."); - return; - } - - print_id(r); - - - } - - public static void print_id (PSXReply ans) { - ByteBuffer r = ans.getData(); - id = r.getShort(); - System.out.print("ID = "); - System.out.println(id); - } -} -
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/fdl/test/TestEtc.java Tue Aug 19 10:48:22 2008 +0900 @@ -0,0 +1,45 @@ + +package fdl.test; + +import java.io.IOException; +//import java.nio.ByteBuffer; + +import fdl.PSXQueue; + +public class TestEtc { + static final int MAX_REQ = 1; + static final int FAIL = (-1); + static final int MAX_UAER = 4; + static final int MAX_TUPLE = 65536; + static final int MAX_BUFFSIZE = 2048; + static final int DEF_PORT = 10000; + static final String PATHNAME = "/tmp/ldserv"; + + + static final int LINDA_MODE_OFFSET = 0; + static final int LINDA_ID_OFFSET = 1; + static final int LINDA_SEQ_OFFSET = 3; + static final int LINDA_DATA_LENGTH_OFFSET = 7; + static final int LINDA_HEADER_SIZE = 12; + + static final boolean debug = true; + public PSXQueue tuple_space; + public PSXQueue tp; + + public static void main(String[] args) throws IOException { + String socketString = "java.nio.channels.SocketChannel[connected local=/133.13.57.210:10001 remote=/133.13.57.210:50634]"; + String[] split = socketString.split("/"); + String local[] = split[1].split(" "); + String remote[] = split[2].split("]"); + + @SuppressWarnings("unused") + final String localAddress = local[0]; + @SuppressWarnings("unused") + final String remoteAddress = remote[0]; + + System.out.println(local[0]); + System.out.println(remote[0]); +// System.out.println("tmpTuple "+tmpTuple.toString()); +// System.out.println("testTS "+testTS[MAX_TUPLE-1].toString()); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/fdl/test/TestPSXLinda.java Tue Aug 19 10:48:22 2008 +0900 @@ -0,0 +1,85 @@ + +/* + * @(#)TestPSXLinda.java 1.1 06/04/01 + * + * Copyright 2006 Shinji KONO + * + + Test PSX Lidna + + */ + +package fdl.test; + +import java.io.IOException; +import java.nio.ByteBuffer; + +import fdl.FederatedLinda; +import fdl.PSXLindaInterface; +import fdl.PSXReply; + + +/** + * PSXLinda stream + * + * @author Shinji Kono + * + * @param host The host to connect to + * @param port The port to connect to at the host + + */ + + +class TestPSXLinda { + static int id; + public static void main (String args[]) { + + FederatedLinda fdl; + PSXLindaInterface psx; + String host = "localhost"; + int port = 10000; + PSXReply r; + + + // try { + // port = Integer.parseInt(args[1]); + // } catch (NumberFormatException nfex) { } + try { + fdl = FederatedLinda.init(); + psx = fdl.open(host,port); + r = psx.in(65535); + //for(int i=0;i<100;i++) { + //if (1==0) { + //} + fdl.sync(1); + //} + System.out.println("Connected."); + + ByteBuffer data = ByteBuffer.allocate(10); + data.putInt(10); + + psx.out(1,data,4); + + while(!r.ready()) { + psx.sync(1000); + // System.out.println("Waiting...."); + } + } catch (IOException nfex) { + nfex.printStackTrace(); + System.out.println("Faild."); + return; + } + + print_id(r); + + + } + + public static void print_id (PSXReply ans) { + ByteBuffer r = ans.getData(); + id = r.getShort(); + System.out.print("ID = "); + System.out.println(id); + } +} +