Mercurial > hg > FederatedLinda
annotate src/fdl/MetaLinda.java @ 31:846c6c14cf04
worked?
author | kono |
---|---|
date | Fri, 22 Aug 2008 14:48:41 +0900 |
parents | fca6eec8016f |
children | 64071f8e2e0d |
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; |
21 | 33 public FederatedLinda fdl=null; |
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 | |
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) { | |
31 | 52 replies.add(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); |
31 | 103 // copy replies to avoid insert during r.ready() |
104 LinkedList<MetaReply> list = replies; | |
105 replies = new LinkedList<MetaReply>(); | |
106 for(MetaReply r:list) { | |
107 if (!r.ready()) { | |
108 addReply(r); | |
19
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
109 } |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
110 } |
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 */ |