1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package jgroup.relacs.daemon;
20
21
22 import java.io.IOException;
23 import java.io.ObjectInput;
24 import java.util.Iterator;
25 import java.util.List;
26
27 import jgroup.core.EndPoint;
28 import jgroup.relacs.mss.MssConstants;
29 import jgroup.relacs.types.EndPointImpl;
30 import jgroup.relacs.types.GroupId;
31 import jgroup.relacs.types.GroupIndex;
32 import jgroup.relacs.types.VersionId;
33 import jgroup.util.MsgFactory;
34 import jgroup.util.OutMessage;
35
36
37
38
39
40
41
42
43 final class MsgSymm
44 implements MssConstants, DaemonMsg
45 {
46
47
48
49
50
51 private static final int START = MSS_HEADER_SIZE;
52
53
54
55
56
57
58
59
60
61
62
63 private static MsgSymm msg = new MsgSymm();
64
65
66 private static OutMessage outmsg;
67
68
69
70
71
72
73
74 int vsend;
75
76
77 EndPoint[] hosts;
78
79
80 int[] version;
81
82
83 EndPoint[] rset;
84
85
86
87
88
89
90
91
92
93
94 static MsgSymm unmarshal(ObjectInput msgstream)
95 throws IOException, ClassNotFoundException
96 {
97
98 msg.vsend = VersionId.unmarshal(msgstream);
99
100
101 int len = GroupIndex.unmarshal(msgstream);
102 msg.version = new int[len];
103 msg.hosts = new EndPoint[len];
104 for (int i=0; i < len; i++) {
105 msg.hosts[i] = new EndPointImpl();
106 msg.hosts[i].readExternal(msgstream);
107 msg.version[i] = VersionId.unmarshal(msgstream);
108 }
109
110
111 len = GroupIndex.unmarshal(msgstream);
112 msg.rset = new EndPoint[len];
113 for (int i=0; i < len; i++) {
114 msg.rset[i] = new EndPointImpl();
115 msg.rset[i].readExternal(msgstream);
116 }
117 return msg;
118 }
119
120
121
122
123
124
125
126
127
128 static MsgSymm marshal(int gid, int vsend, List nrset, EndPoint[] rset, int nreceivers)
129 throws IOException
130 {
131
132 int size = START + GroupId.SIZE + VersionId.SIZE + 2 * GroupIndex.SIZE + nrset.size() *
133 (VersionId.SIZE + EndPointImpl.SIZE) + rset.length * EndPointImpl.SIZE;
134 outmsg = MsgFactory.get(size, nreceivers);
135 outmsg.seek(START);
136
137
138 GroupId.marshal(outmsg, gid);
139 VersionId.marshal(outmsg, vsend);
140
141
142
143
144
145 GroupIndex.marshal(outmsg, nrset.size());
146 Iterator iterator = nrset.iterator();
147 while (iterator.hasNext()) {
148 HostData data = (HostData) iterator.next();
149 data.getEndPoint().writeExternal(outmsg);
150 VersionId.marshal(outmsg, data.getVersion());
151 }
152
153
154
155
156 GroupIndex.marshal(outmsg, rset.length);
157 for (int i=0; i < rset.length; i++)
158 rset[i].writeExternal(outmsg);
159
160 return msg;
161 }
162
163
164
165
166
167 static MsgSymm marshal(int gid, int vsend, HostData dest, EndPoint[] rset, int nreceivers)
168 throws IOException
169 {
170
171 int size = START + GroupId.SIZE + VersionId.SIZE + 2 * GroupIndex.SIZE +
172 VersionId.SIZE + EndPointImpl.SIZE + rset.length * EndPointImpl.SIZE;
173 outmsg = MsgFactory.get(size, nreceivers);
174 outmsg.seek(START);
175
176
177 GroupId.marshal(outmsg, gid);
178 VersionId.marshal(outmsg, vsend);
179
180
181 GroupIndex.marshal(outmsg, 1);
182 dest.getEndPoint().writeExternal(outmsg);
183 VersionId.marshal(outmsg, dest.getVersion());
184
185
186
187
188 GroupIndex.marshal(outmsg, rset.length);
189 for (int i=0; i < rset.length; i++)
190 rset[i].writeExternal(outmsg);
191
192 return msg;
193 }
194
195
196
197
198
199
200 public int size()
201 {
202
203
204 return outmsg.size();
205 }
206
207 public OutMessage getOutMessage()
208 {
209 return outmsg;
210 }
211
212
213
214
215
216
217
218
219
220 public String toString()
221 {
222 StringBuilder buffer = new StringBuilder();
223 buffer.append("[MsgSymm: vsend=");
224 buffer.append(vsend);
225 buffer.append(", rset={");
226 for (int i=0; i < rset.length; i++) {
227 buffer.append(rset[i]);
228 if (i < rset.length-1)
229 buffer.append(", ");
230 }
231 buffer.append("}, hosts={");
232 for (int i=0; i < hosts.length; i++) {
233 buffer.append(hosts[i]);
234 if (i < hosts.length-1)
235 buffer.append(", ");
236 }
237 buffer.append("}, versions={");
238 for (int i=0; i < version.length; i++) {
239 buffer.append(version[i]);
240 if (i < version.length-1)
241 buffer.append(", ");
242 }
243 buffer.append("}]");
244 return buffer.toString();
245 }
246
247 }