annotate src/fdl/MetaLinda.java @ 71:0352536c33fa

(example: writer) get linda server addr from commandline arg.
author kazz@e065701.local
date Fri, 23 Oct 2009 14:11:07 +0900
parents 865bf7f1bb8d
children c0591636a71a a1d796c0e975
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
1
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
2 /*
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
3 * @(#)MetaLinda.java 1.1 06/04/01
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
4 *
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
5 * Copyright 2008 Shinji KONO
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
6 *
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
7
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
8 Meta Lidna
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
9 Trasport layer of Meta Linda API
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
10
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
11 */
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
12
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
13 package fdl;
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
14
19
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
15 import java.io.IOException;
15
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
16 import java.nio.ByteBuffer;
31
846c6c14cf04 worked?
kono
parents: 30
diff changeset
17 import java.util.LinkedList;
15
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
18
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
19 /**
19
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
20 MetaLinda
15
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
21 *
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
22 * @author Shinji Kono
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
23 *
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
24
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
25 meta tuple interface in Linda Server
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
26
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
27 */
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
28
25
330fa49bc4fd *** empty log message ***
kono
parents: 23
diff changeset
29 public class MetaLinda implements PSXLinda {
15
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
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;
39
81abceebc869 *** empty log message ***
kono
parents: 38
diff changeset
33 public FederatedLinda fdl=FederatedLinda.init();
25
330fa49bc4fd *** empty log message ***
kono
parents: 23
diff changeset
34 public PSXLinda next=null;
31
846c6c14cf04 worked?
kono
parents: 30
diff changeset
35 private LinkedList<MetaReply> replies=new LinkedList<MetaReply>();
15
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
36
21
fac6e0073b1a *** empty log message ***
kono
parents: 19
diff changeset
37 public MetaLinda(TupleSpace ts,FDLindaServ fds) {
19
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
38 this.ts = ts;
21
fac6e0073b1a *** empty log message ***
kono
parents: 19
diff changeset
39 this.fds = fds;
15
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
40 }
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
41
39
81abceebc869 *** empty log message ***
kono
parents: 38
diff changeset
42 public PSXLinda open(String _host,int _port)
81abceebc869 *** empty log message ***
kono
parents: 38
diff changeset
43 throws IOException {
81abceebc869 *** empty log message ***
kono
parents: 38
diff changeset
44 return fdl.openFromMetaLinda(this, _host, _port);
81abceebc869 *** empty log message ***
kono
parents: 38
diff changeset
45 }
81abceebc869 *** empty log message ***
kono
parents: 38
diff changeset
46
15
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
47 public PSXReply in(int id) {
55
865bf7f1bb8d metaTranse two
axmo
parents: 39
diff changeset
48 MetaReply r = new MetaReply(PSX.PSX_IN,id,ts);
865bf7f1bb8d metaTranse two
axmo
parents: 39
diff changeset
49 addReply(r);
865bf7f1bb8d metaTranse two
axmo
parents: 39
diff changeset
50 return r;
15
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
51 }
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
52
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
53 public void in(int id, PSXCallback callback) {
26
d7d70edc9c7c META_STOP worked.
kono
parents: 25
diff changeset
54 MetaReply r = new MetaReply(PSX.PSX_IN,id,ts, callback);
d7d70edc9c7c META_STOP worked.
kono
parents: 25
diff changeset
55 addReply(r);
d7d70edc9c7c META_STOP worked.
kono
parents: 25
diff changeset
56 }
d7d70edc9c7c META_STOP worked.
kono
parents: 25
diff changeset
57
d7d70edc9c7c META_STOP worked.
kono
parents: 25
diff changeset
58 private void addReply(MetaReply r) {
36
d5bca4b5ee95 meta.sync() recursive call fix.
kono
parents: 33
diff changeset
59 replies.addLast(r);
15
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
60 }
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
61
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
62 public PSXReply ck(int id) {
19
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
63 MetaReply r = new MetaReply(PSX.PSX_CHECK,id,ts);
15
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
64 return r;
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
65 }
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
66
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
67 public void ck(int id, PSXCallback callback) {
26
d7d70edc9c7c META_STOP worked.
kono
parents: 25
diff changeset
68 MetaReply r = new MetaReply(PSX.PSX_CHECK,id,ts,callback);
d7d70edc9c7c META_STOP worked.
kono
parents: 25
diff changeset
69 addReply(r);
15
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
70 }
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
71
23
b4fd7fb9135a Simple Test run.
kono
parents: 21
diff changeset
72 public PSXReply out(int id, ByteBuffer data) {
19
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
73 MetaReply r = new MetaReply(PSX.PSX_OUT,id,ts,data,null);
26
d7d70edc9c7c META_STOP worked.
kono
parents: 25
diff changeset
74 addReply(r);
19
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
75 return r;
15
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
76 }
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
77
23
b4fd7fb9135a Simple Test run.
kono
parents: 21
diff changeset
78 public PSXReply update(int id, ByteBuffer data) {
19
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
79 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
80 return r;
15
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
81 }
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
82
23
b4fd7fb9135a Simple Test run.
kono
parents: 21
diff changeset
83 public void update(int id, ByteBuffer data,PSXCallback callback) {
19
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
84 MetaReply r = new MetaReply(PSX.PSX_UPDATE,id,ts,data,callback);
26
d7d70edc9c7c META_STOP worked.
kono
parents: 25
diff changeset
85 addReply(r);
15
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
86 }
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
87
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
88 public PSXReply rd(int id) {
19
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
89 MetaReply r = new MetaReply(PSX.PSX_RD,id,ts);
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
90 return r;
15
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
91 }
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
92
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
93 public void rd(int id, PSXCallback callback) {
26
d7d70edc9c7c META_STOP worked.
kono
parents: 25
diff changeset
94 MetaReply r = new MetaReply(PSX.PSX_RD,id,ts,callback);
d7d70edc9c7c META_STOP worked.
kono
parents: 25
diff changeset
95 addReply(r);
15
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
96 }
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
97
25
330fa49bc4fd *** empty log message ***
kono
parents: 23
diff changeset
98 public PSXLinda add(PSXLinda linda) {
15
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
99 next = linda;
19
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
100 return this;
15
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
101 }
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
102
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
103
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
104 public int sync() {
19
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
105 return sync(0);
15
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
106 }
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
107
19
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
108 public int sync(long timeout) {
39
81abceebc869 *** empty log message ***
kono
parents: 38
diff changeset
109 fds.checkTuple(timeout); // fdl sync is also handled here
36
d5bca4b5ee95 meta.sync() recursive call fix.
kono
parents: 33
diff changeset
110 /*
d5bca4b5ee95 meta.sync() recursive call fix.
kono
parents: 33
diff changeset
111 * r.callback() may call meta.sync() and modifies the
d5bca4b5ee95 meta.sync() recursive call fix.
kono
parents: 33
diff changeset
112 * replies queue. Do current size of queue only. The
d5bca4b5ee95 meta.sync() recursive call fix.
kono
parents: 33
diff changeset
113 * rest is checked on the next sync call including
d5bca4b5ee95 meta.sync() recursive call fix.
kono
parents: 33
diff changeset
114 * the recursive case.
d5bca4b5ee95 meta.sync() recursive call fix.
kono
parents: 33
diff changeset
115 */
39
81abceebc869 *** empty log message ***
kono
parents: 38
diff changeset
116 int count = replies.size();
81abceebc869 *** empty log message ***
kono
parents: 38
diff changeset
117 while(count-->0) {
81abceebc869 *** empty log message ***
kono
parents: 38
diff changeset
118 MetaReply r = replies.poll();
81abceebc869 *** empty log message ***
kono
parents: 38
diff changeset
119 // previous call back may call this sync and make
81abceebc869 *** empty log message ***
kono
parents: 38
diff changeset
120 // replies shorter.
81abceebc869 *** empty log message ***
kono
parents: 38
diff changeset
121 if (r==null) break;
81abceebc869 *** empty log message ***
kono
parents: 38
diff changeset
122 if (r.ready()) {
81abceebc869 *** empty log message ***
kono
parents: 38
diff changeset
123 } else {
81abceebc869 *** empty log message ***
kono
parents: 38
diff changeset
124 addReply(r);
36
d5bca4b5ee95 meta.sync() recursive call fix.
kono
parents: 33
diff changeset
125 }
39
81abceebc869 *** empty log message ***
kono
parents: 38
diff changeset
126 }
15
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
127 return 0;
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
128 }
25
330fa49bc4fd *** empty log message ***
kono
parents: 23
diff changeset
129
330fa49bc4fd *** empty log message ***
kono
parents: 23
diff changeset
130 public void send(ByteBuffer command, ByteBuffer data) {
37
2a366abc3f1f *** empty log message ***
kono
parents: 36
diff changeset
131 }
2a366abc3f1f *** empty log message ***
kono
parents: 36
diff changeset
132
2a366abc3f1f *** empty log message ***
kono
parents: 36
diff changeset
133 public void setTupleSpaceHook(IOHandlerHook hook) {
2a366abc3f1f *** empty log message ***
kono
parents: 36
diff changeset
134 ts.hook = hook;
25
330fa49bc4fd *** empty log message ***
kono
parents: 23
diff changeset
135 }
15
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
136 }
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
137
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
138
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents:
diff changeset
139 /* end */