comparison src/fdl/MetaLinda.java @ 19:0243987383b7

Meta Protocol Engine and sample implementation of event logger. ComDebug_Client needs fixes.
author kono
date Tue, 19 Aug 2008 05:33:32 +0900
parents 609b288f47f9
children fac6e0073b1a
comparison
equal deleted inserted replaced
18:2cbd98257d61 19:0243987383b7
10 10
11 */ 11 */
12 12
13 package fdl; 13 package fdl;
14 14
15 import java.io.IOException;
15 import java.nio.ByteBuffer; 16 import java.nio.ByteBuffer;
17 import java.util.LinkedList;
16 18
17 /** 19 /**
18 PSXLinda 20 MetaLinda
19 * 21 *
20 * @author Shinji Kono 22 * @author Shinji Kono
21 * 23 *
22 24
23 meta tuple interface in Linda Server 25 meta tuple interface in Linda Server
24 26
25 */ 27 */
26 28
27 public class MetaLinda implements PSXLindaInterface { 29 public class MetaLinda implements PSXLindaInterface {
28 30
31 public TupleSpace ts;
32 public FDLindaServ fds;
33 public FederatedLinda fdl;
34 public PSXLindaInterface next;
35 public LinkedList<MetaReply> replies;
29 36
30 public PSXLinda next; 37 public MetaLinda(TupleSpace ts,FDLindaServ fdl) {
31 38 this.ts = ts;
32 public MetaLinda(FederatedLinda _fdl,int _mytsid,String _host,int _port) { 39 this.fds = fdl;
33
34 } 40 }
35 41
36 public PSXReply in(int id) { 42 public PSXReply in(int id) {
37 return null; 43 return null;
38 } 44 }
39 45
40 public void in(int id, PSXCallback callback) { 46 public void in(int id, PSXCallback callback) {
47 replies.add(new MetaReply(PSX.PSX_IN,id,ts, callback));
41 } 48 }
42 49
43 public PSXReply ck(int id) { 50 public PSXReply ck(int id) {
44 PSXReply r = null; 51 MetaReply r = new MetaReply(PSX.PSX_CHECK,id,ts);
45 return r; 52 return r;
46 } 53 }
47 54
48 public void ck(int id, PSXCallback callback) { 55 public void ck(int id, PSXCallback callback) {
56 replies.add(new MetaReply(PSX.PSX_CHECK,id,ts,callback));
49 } 57 }
50 58
51 public PSXReply out(int id, ByteBuffer data,int size) { 59 public PSXReply out(int id, ByteBuffer data,int size) {
52 return null; 60 MetaReply r = new MetaReply(PSX.PSX_OUT,id,ts,data,null);
61 replies.add(r);
62 return r;
53 } 63 }
54 64
55 public PSXReply update(int id, ByteBuffer data,int size) { 65 public PSXReply update(int id, ByteBuffer data,int size) {
56 return null; 66 MetaReply r = new MetaReply(PSX.PSX_UPDATE,id,ts,data,null);
67 return r;
57 } 68 }
58 69
59 public void update(int id, ByteBuffer data,int size,PSXCallback callback) { 70 public void update(int id, ByteBuffer data,int size,PSXCallback callback) {
71 MetaReply r = new MetaReply(PSX.PSX_UPDATE,id,ts,data,callback);
72 replies.add(r);
60 } 73 }
61 74
62 public PSXReply rd(int id) { 75 public PSXReply rd(int id) {
63 return null; 76 MetaReply r = new MetaReply(PSX.PSX_RD,id,ts);
77 return r;
64 } 78 }
65 79
66 public void rd(int id, PSXCallback callback) { 80 public void rd(int id, PSXCallback callback) {
81 replies.add(new MetaReply(PSX.PSX_RD,id,ts,callback));
67 } 82 }
68 83
69 public PSXLinda add(PSXLinda linda) { 84 public PSXLindaInterface add(PSXLindaInterface linda) {
70 next = linda; 85 next = linda;
71 return null; 86 return this;
72 } 87 }
73 88
74 public void send(ByteBuffer command,ByteBuffer data) { 89 public void send(ByteBuffer command,ByteBuffer data) {
75 } 90 }
76 91
77 public int sync() { 92 public int sync() {
78 return 0; 93 return sync(0);
79 } 94 }
80 95
81 public int sync(long mtime) { 96 public int sync(long timeout) {
97 fds.checkTuple(timeout);
98 for(MetaReply r: replies) {
99 if (r.ready()) {
100 replies.remove();
101 }
102 }
103 if (fdl!=null) {
104 try {
105 fdl.sync(timeout);
106 } catch (IOException e) {
107 e.printStackTrace();
108 }
109 }
82 return 0; 110 return 0;
83 } 111 }
84 } 112 }
85 113
86 114