1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.river.outrigger.proxy;
19
20 import org.apache.river.landlord.ConstrainableLandlordLease;
21 import org.apache.river.proxy.ConstrainableProxyUtil;
22 import java.io.IOException;
23 import java.io.ObjectInputStream;
24 import java.lang.reflect.Method;
25 import java.rmi.MarshalledObject;
26 import java.util.Collection;
27 import net.jini.admin.Administrable;
28 import net.jini.core.constraint.MethodConstraints;
29 import net.jini.core.constraint.RemoteMethodControl;
30 import net.jini.core.entry.Entry;
31 import net.jini.core.event.RemoteEventListener;
32 import net.jini.core.lease.Lease;
33 import net.jini.core.transaction.Transaction;
34 import net.jini.id.Uuid;
35 import net.jini.io.MarshalledInstance;
36 import net.jini.security.proxytrust.ProxyTrustIterator;
37 import net.jini.security.proxytrust.SingletonProxyTrustIterator;
38 import net.jini.space.JavaSpace;
39 import net.jini.space.JavaSpace05;
40 import org.apache.river.api.io.AtomicSerial;
41 import org.apache.river.api.io.AtomicSerial.GetArg;
42
43
44
45
46 @AtomicSerial
47 public final class ConstrainableSpaceProxy2 extends SpaceProxy2
48 implements RemoteMethodControl
49 {
50 static final long serialVersionUID = 1L;
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66 private static final Method[] methodMapArray = {
67 ProxyUtil.getMethod(Administrable.class, "getAdmin", new Class[] {}),
68 ProxyUtil.getMethod(Administrable.class, "getAdmin", new Class[] {}),
69
70 ProxyUtil.getMethod(JavaSpace.class, "write",
71 new Class[] {Entry.class,
72 Transaction.class,
73 long.class}),
74 ProxyUtil.getMethod(OutriggerServer.class, "write",
75 new Class[] {EntryRep.class,
76 Transaction.class,
77 long.class}),
78
79
80 ProxyUtil.getMethod(JavaSpace.class, "read",
81 new Class[] {Entry.class,
82 Transaction.class,
83 long.class}),
84 ProxyUtil.getMethod(OutriggerServer.class, "read",
85 new Class[] {EntryRep.class,
86 Transaction.class,
87 long.class,
88 OutriggerServer.QueryCookie.class}),
89
90
91 ProxyUtil.getMethod(JavaSpace.class, "take",
92 new Class[] {Entry.class,
93 Transaction.class,
94 long.class}),
95 ProxyUtil.getMethod(OutriggerServer.class, "take",
96 new Class[] {EntryRep.class,
97 Transaction.class,
98 long.class,
99 OutriggerServer.QueryCookie.class}),
100
101
102 ProxyUtil.getMethod(JavaSpace.class, "readIfExists",
103 new Class[] {Entry.class,
104 Transaction.class,
105 long.class}),
106 ProxyUtil.getMethod(OutriggerServer.class, "readIfExists",
107 new Class[] {EntryRep.class,
108 Transaction.class,
109 long.class,
110 OutriggerServer.QueryCookie.class}),
111
112
113 ProxyUtil.getMethod(JavaSpace.class, "takeIfExists",
114 new Class[] {Entry.class,
115 Transaction.class,
116 long.class}),
117 ProxyUtil.getMethod(OutriggerServer.class, "takeIfExists",
118 new Class[] {EntryRep.class,
119 Transaction.class,
120 long.class,
121 OutriggerServer.QueryCookie.class}),
122
123
124 ProxyUtil.getMethod(JavaSpace.class, "notify",
125 new Class[] {Entry.class,
126 Transaction.class,
127 RemoteEventListener.class,
128 long.class,
129 MarshalledObject.class}),
130 ProxyUtil.getMethod(OutriggerServer.class, "notify",
131 new Class[] {EntryRep.class,
132 Transaction.class,
133 RemoteEventListener.class,
134 long.class,
135 MarshalledInstance.class}),
136
137 ProxyUtil.getMethod(JavaSpace05.class, "contents",
138 new Class[] {Collection.class,
139 Transaction.class,
140 long.class,
141 long.class}),
142 ProxyUtil.getMethod(OutriggerServer.class, "contents",
143 new Class[] {EntryRep[].class,
144 Transaction.class,
145 long.class,
146 long.class}),
147
148
149
150 ProxyUtil.getMethod(JavaSpace05.class, "contents",
151 new Class[] {Collection.class,
152 Transaction.class,
153 long.class,
154 long.class}),
155 ProxyUtil.getMethod(OutriggerServer.class, "nextBatch",
156 new Class[] {Uuid.class,
157 Uuid.class})
158 };
159
160
161
162
163
164 private final MethodConstraints methodConstraints;
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185 public ConstrainableSpaceProxy2(OutriggerServer space, Uuid spaceUuid,
186 long serverMaxServerQueryTimeout,
187 MethodConstraints methodConstraints)
188 {
189 super(constrainServer(space, methodConstraints),
190 spaceUuid, serverMaxServerQueryTimeout);
191 this.methodConstraints = methodConstraints;
192 }
193
194 ConstrainableSpaceProxy2(GetArg arg) throws IOException{
195 this(arg, check(arg));
196 }
197
198 ConstrainableSpaceProxy2(GetArg arg, MethodConstraints constraints) throws IOException{
199 super(arg);
200 methodConstraints = constraints;
201 }
202
203 private static MethodConstraints check(GetArg arg) throws IOException {
204 SpaceProxy2 sp2 = new SpaceProxy2(arg);
205 MethodConstraints methodConstraints = (MethodConstraints)
206 arg.get("methodConstraints", null);
207 MethodConstraints proxyCon = null;
208 if (sp2.space instanceof RemoteMethodControl &&
209 (proxyCon = ((RemoteMethodControl)sp2.space).getConstraints()) != null) {
210
211 return ConstrainableProxyUtil.reverseTranslateConstraints(
212 proxyCon, methodMapArray);
213 }
214
215
216
217
218
219
220 ConstrainableProxyUtil.verifyConsistentConstraints(
221 methodConstraints, sp2.space, methodMapArray);
222 return methodConstraints;
223 }
224
225
226
227
228
229
230
231
232
233
234
235
236 private static OutriggerServer constrainServer(OutriggerServer server,
237 MethodConstraints constraints)
238 {
239 final MethodConstraints serverRefConstraints
240 = ConstrainableProxyUtil.translateConstraints(constraints,
241 methodMapArray);
242 final RemoteMethodControl constrainedServer =
243 ((RemoteMethodControl)server).
244 setConstraints(serverRefConstraints);
245
246 return (OutriggerServer)constrainedServer;
247 }
248
249 public RemoteMethodControl setConstraints(MethodConstraints constraints)
250 {
251 return new ConstrainableSpaceProxy2(space, spaceUuid,
252 serverMaxServerQueryTimeout,
253 constraints);
254 }
255
256 public MethodConstraints getConstraints() {
257 return methodConstraints;
258 }
259
260
261
262
263
264
265 private ProxyTrustIterator getProxyTrustIterator() {
266 return new SingletonProxyTrustIterator(space);
267 }
268
269 private void readObject(ObjectInputStream s)
270 throws IOException, ClassNotFoundException
271 {
272 s.defaultReadObject();
273
274
275
276
277
278
279
280 ConstrainableProxyUtil.verifyConsistentConstraints(
281 methodConstraints, space, methodMapArray);
282 }
283
284 protected Lease constructLease(Uuid uuid, long expiration) {
285 return new ConstrainableLandlordLease(uuid, space, spaceUuid,
286 expiration, null);
287 }
288 }
289