Mercurial > hg > FederatedLinda
annotate 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 |
rev | line source |
---|---|
15 | 1 |
2 /* | |
3 * @(#)MetaLinda.java 1.1 06/04/01 | |
4 * | |
5 * Copyright 2008 Shinji KONO | |
6 * | |
7 | |
8 Meta Lidna | |
9 Trasport layer of Meta Linda API | |
10 | |
11 */ | |
12 | |
13 package fdl; | |
14 | |
19
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
15 import java.io.IOException; |
15 | 16 import java.nio.ByteBuffer; |
19
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
17 import java.util.LinkedList; |
15 | 18 |
19 /** | |
19
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
20 MetaLinda |
15 | 21 * |
22 * @author Shinji Kono | |
23 * | |
24 | |
25 meta tuple interface in Linda Server | |
26 | |
27 */ | |
28 | |
17 | 29 public class MetaLinda implements PSXLindaInterface { |
15 | 30 |
19
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
31 public TupleSpace ts; |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
32 public FDLindaServ fds; |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
33 public FederatedLinda fdl; |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
34 public PSXLindaInterface next; |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
35 public LinkedList<MetaReply> replies; |
15 | 36 |
19
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
37 public MetaLinda(TupleSpace ts,FDLindaServ fdl) { |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
38 this.ts = ts; |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
39 this.fds = fdl; |
15 | 40 } |
41 | |
42 public PSXReply in(int id) { | |
43 return null; | |
44 } | |
45 | |
46 public void in(int id, PSXCallback callback) { | |
19
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
47 replies.add(new MetaReply(PSX.PSX_IN,id,ts, callback)); |
15 | 48 } |
49 | |
50 public PSXReply ck(int id) { | |
19
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
51 MetaReply r = new MetaReply(PSX.PSX_CHECK,id,ts); |
15 | 52 return r; |
53 } | |
54 | |
55 public void ck(int id, PSXCallback callback) { | |
19
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
56 replies.add(new MetaReply(PSX.PSX_CHECK,id,ts,callback)); |
15 | 57 } |
58 | |
59 public PSXReply out(int id, ByteBuffer data,int size) { | |
19
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
60 MetaReply r = new MetaReply(PSX.PSX_OUT,id,ts,data,null); |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
61 replies.add(r); |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
62 return r; |
15 | 63 } |
64 | |
65 public PSXReply update(int id, ByteBuffer data,int size) { | |
19
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
66 MetaReply r = new MetaReply(PSX.PSX_UPDATE,id,ts,data,null); |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
67 return r; |
15 | 68 } |
69 | |
70 public void update(int id, ByteBuffer data,int size,PSXCallback callback) { | |
19
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
71 MetaReply r = new MetaReply(PSX.PSX_UPDATE,id,ts,data,callback); |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
72 replies.add(r); |
15 | 73 } |
74 | |
75 public PSXReply rd(int id) { | |
19
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
76 MetaReply r = new MetaReply(PSX.PSX_RD,id,ts); |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
77 return r; |
15 | 78 } |
79 | |
80 public void rd(int id, PSXCallback callback) { | |
19
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
81 replies.add(new MetaReply(PSX.PSX_RD,id,ts,callback)); |
15 | 82 } |
83 | |
19
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
84 public PSXLindaInterface add(PSXLindaInterface linda) { |
15 | 85 next = linda; |
19
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
86 return this; |
15 | 87 } |
88 | |
89 public void send(ByteBuffer command,ByteBuffer data) { | |
90 } | |
91 | |
92 public int sync() { | |
19
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
93 return sync(0); |
15 | 94 } |
95 | |
19
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
96 public int sync(long timeout) { |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
97 fds.checkTuple(timeout); |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
98 for(MetaReply r: replies) { |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
99 if (r.ready()) { |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
100 replies.remove(); |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
101 } |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
102 } |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
103 if (fdl!=null) { |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
104 try { |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
105 fdl.sync(timeout); |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
106 } catch (IOException e) { |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
107 e.printStackTrace(); |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
108 } |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
109 } |
15 | 110 return 0; |
111 } | |
112 } | |
113 | |
114 | |
115 /* end */ |