Mercurial > hg > FederatedLinda
annotate src/fdl/MetaLinda.java @ 30:fca6eec8016f
*** empty log message ***
author | kono |
---|---|
date | Thu, 21 Aug 2008 18:46:40 +0900 |
parents | 132c9bc28d6b |
children | 846c6c14cf04 |
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; |
17 | |
18 /** | |
19
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
19 MetaLinda |
15 | 20 * |
21 * @author Shinji Kono | |
22 * | |
23 | |
24 meta tuple interface in Linda Server | |
25 | |
26 */ | |
27 | |
25 | 28 public class MetaLinda implements PSXLinda { |
15 | 29 |
19
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
30 public TupleSpace ts; |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
31 public FDLindaServ fds; |
21 | 32 public FederatedLinda fdl=null; |
25 | 33 public PSXLinda next=null; |
26 | 34 private MetaReply replies=new MetaReply(0, 0, ts); |
35 private MetaReply last=replies; | |
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 | |
42 public PSXReply in(int id) { | |
43 return null; | |
44 } | |
45 | |
46 public void in(int id, PSXCallback callback) { | |
26 | 47 MetaReply r = new MetaReply(PSX.PSX_IN,id,ts, callback); |
48 addReply(r); | |
49 } | |
50 | |
51 private void addReply(MetaReply r) { | |
52 last.next = r; last = r; | |
15 | 53 } |
54 | |
55 public PSXReply ck(int id) { | |
19
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
56 MetaReply r = new MetaReply(PSX.PSX_CHECK,id,ts); |
15 | 57 return r; |
58 } | |
59 | |
60 public void ck(int id, PSXCallback callback) { | |
26 | 61 MetaReply r = new MetaReply(PSX.PSX_CHECK,id,ts,callback); |
62 addReply(r); | |
15 | 63 } |
64 | |
23 | 65 public PSXReply out(int id, ByteBuffer data) { |
19
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
66 MetaReply r = new MetaReply(PSX.PSX_OUT,id,ts,data,null); |
26 | 67 addReply(r); |
19
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
68 return r; |
15 | 69 } |
70 | |
23 | 71 public PSXReply update(int id, ByteBuffer data) { |
19
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
72 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
|
73 return r; |
15 | 74 } |
75 | |
23 | 76 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
|
77 MetaReply r = new MetaReply(PSX.PSX_UPDATE,id,ts,data,callback); |
26 | 78 addReply(r); |
15 | 79 } |
80 | |
81 public PSXReply rd(int id) { | |
19
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
82 MetaReply r = new MetaReply(PSX.PSX_RD,id,ts); |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
83 return r; |
15 | 84 } |
85 | |
86 public void rd(int id, PSXCallback callback) { | |
26 | 87 MetaReply r = new MetaReply(PSX.PSX_RD,id,ts,callback); |
88 addReply(r); | |
15 | 89 } |
90 | |
25 | 91 public PSXLinda add(PSXLinda linda) { |
15 | 92 next = linda; |
19
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
93 return this; |
15 | 94 } |
95 | |
96 | |
97 public int sync() { | |
19
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
98 return sync(0); |
15 | 99 } |
100 | |
19
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
101 public int sync(long timeout) { |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
102 fds.checkTuple(timeout); |
27 | 103 PSXReply r; |
104 for(r=replies;r!=null&&r.next!=null;r = r.next) { | |
26 | 105 if (r.next.ready()) { |
27 | 106 // ready() may modify replies list |
26 | 107 r.next = r.next.next; |
19
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 } |
27 | 110 last = (MetaReply)r; |
19
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
111 if (fdl!=null) { |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
112 try { |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
113 fdl.sync(timeout); |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
114 } catch (IOException e) { |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
115 e.printStackTrace(); |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
116 } |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
117 } |
15 | 118 return 0; |
119 } | |
25 | 120 |
121 public void send(ByteBuffer command, ByteBuffer data) { | |
122 | |
123 } | |
15 | 124 } |
125 | |
126 | |
127 /* end */ |