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