Mercurial > hg > FederatedLinda
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 |
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; |
31 | 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 | |
25 | 29 public class MetaLinda implements PSXLinda { |
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; |
39 | 33 public FederatedLinda fdl=FederatedLinda.init(); |
25 | 34 public PSXLinda next=null; |
31 | 35 private LinkedList<MetaReply> replies=new LinkedList<MetaReply>(); |
15 | 36 |
21 | 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 | 39 this.fds = fds; |
15 | 40 } |
41 | |
39 | 42 public PSXLinda open(String _host,int _port) |
43 throws IOException { | |
44 return fdl.openFromMetaLinda(this, _host, _port); | |
45 } | |
46 | |
15 | 47 public PSXReply in(int id) { |
55 | 48 MetaReply r = new MetaReply(PSX.PSX_IN,id,ts); |
49 addReply(r); | |
50 return r; | |
15 | 51 } |
52 | |
53 public void in(int id, PSXCallback callback) { | |
26 | 54 MetaReply r = new MetaReply(PSX.PSX_IN,id,ts, callback); |
55 addReply(r); | |
56 } | |
57 | |
58 private void addReply(MetaReply r) { | |
36 | 59 replies.addLast(r); |
15 | 60 } |
61 | |
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 | 64 return r; |
65 } | |
66 | |
67 public void ck(int id, PSXCallback callback) { | |
26 | 68 MetaReply r = new MetaReply(PSX.PSX_CHECK,id,ts,callback); |
69 addReply(r); | |
15 | 70 } |
71 | |
23 | 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 | 74 addReply(r); |
19
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
75 return r; |
15 | 76 } |
77 | |
23 | 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 | 81 } |
82 | |
23 | 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 | 85 addReply(r); |
15 | 86 } |
87 | |
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 | 91 } |
92 | |
93 public void rd(int id, PSXCallback callback) { | |
26 | 94 MetaReply r = new MetaReply(PSX.PSX_RD,id,ts,callback); |
95 addReply(r); | |
15 | 96 } |
97 | |
25 | 98 public PSXLinda add(PSXLinda linda) { |
15 | 99 next = linda; |
19
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
100 return this; |
15 | 101 } |
102 | |
103 | |
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 | 106 } |
107 | |
19
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
108 public int sync(long timeout) { |
39 | 109 fds.checkTuple(timeout); // fdl sync is also handled here |
36 | 110 /* |
111 * r.callback() may call meta.sync() and modifies the | |
112 * replies queue. Do current size of queue only. The | |
113 * rest is checked on the next sync call including | |
114 * the recursive case. | |
115 */ | |
39 | 116 int count = replies.size(); |
117 while(count-->0) { | |
118 MetaReply r = replies.poll(); | |
119 // previous call back may call this sync and make | |
120 // replies shorter. | |
121 if (r==null) break; | |
122 if (r.ready()) { | |
123 } else { | |
124 addReply(r); | |
36 | 125 } |
39 | 126 } |
15 | 127 return 0; |
128 } | |
25 | 129 |
130 public void send(ByteBuffer command, ByteBuffer data) { | |
37 | 131 } |
132 | |
133 public void setTupleSpaceHook(IOHandlerHook hook) { | |
134 ts.hook = hook; | |
25 | 135 } |
15 | 136 } |
137 | |
138 | |
139 /* end */ |