comparison src/org/dancres/blitz/remote/ConstrainableLeaseImpl.java @ 0:3dc0c5604566

Initial checkin of blitz 2.0 fcs - no installer yet.
author Dan Creswell <dan.creswell@gmail.com>
date Sat, 21 Mar 2009 11:00:06 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:3dc0c5604566
1 package org.dancres.blitz.remote;
2
3 import java.io.IOException;
4 import java.io.ObjectInputStream;
5 import java.io.InvalidObjectException;
6
7 import java.lang.reflect.Method;
8
9 import net.jini.id.Uuid;
10
11 import net.jini.core.constraint.RemoteMethodControl;
12 import net.jini.core.constraint.MethodConstraints;
13
14 import net.jini.security.proxytrust.ProxyTrustIterator;
15 import net.jini.security.proxytrust.SingletonProxyTrustIterator;
16
17 import net.jini.core.lease.Lease;
18
19 import net.jini.admin.JoinAdmin;
20
21 import net.jini.id.Uuid;
22
23 import com.sun.jini.proxy.ConstrainableProxyUtil;
24
25 import org.dancres.blitz.lease.SpaceUID;
26
27 import org.dancres.util.ReflectUtil;
28
29 /**
30 When running in "secure mode", Leases should be constrainable as per
31 other proxies.
32 */
33 public final class ConstrainableLeaseImpl extends
34 LeaseImpl implements RemoteMethodControl {
35
36 /**
37 The outer-layer calls all omit SpaceUID whilst the server
38 calls use SpaceUID so we must translate constraints which will be
39 applied against the outer-layer methods to the internal methods.
40 */
41 private static final Method[] theMethodMapping = {
42 ReflectUtil.findMethod(Lease.class, "renew",
43 new Class[] {long.class}),
44 ReflectUtil.findMethod(Landlord.class, "renew",
45 new Class[] {SpaceUID.class, long.class}),
46 ReflectUtil.findMethod(Lease.class, "cancel",
47 new Class[] {}),
48 ReflectUtil.findMethod(Landlord.class, "cancel",
49 new Class[] {SpaceUID.class})
50 };
51
52 private static Landlord constrainStub(Landlord aServer,
53 MethodConstraints aConstraints) {
54 RemoteMethodControl myServer = (RemoteMethodControl) aServer;
55
56 MethodConstraints myStubConstraints =
57 ConstrainableProxyUtil.translateConstraints(aConstraints,
58 theMethodMapping);
59
60 myServer.setConstraints(myStubConstraints);
61 return (Landlord) myServer;
62 }
63
64 private final MethodConstraints theConstraints;
65
66 ConstrainableLeaseImpl(Landlord aLandlord, Uuid aUuid, SpaceUID aUID,
67 long aDuration) {
68 super(aLandlord, aUuid, aUID, aDuration);
69 theConstraints = null;
70 }
71
72 ConstrainableLeaseImpl(Landlord aLandlord, Uuid aUuid, SpaceUID aUID,
73 long aDuration, MethodConstraints aConstraints) {
74 super(constrainStub(aLandlord, aConstraints), aUuid, aUID,
75 aDuration);
76 theConstraints = aConstraints;
77 }
78
79 private ProxyTrustIterator getProxyTrustIterator() {
80 return new SingletonProxyTrustIterator(theStub);
81 }
82
83 public RemoteMethodControl setConstraints(MethodConstraints aConstraints) {
84 return new ConstrainableLeaseImpl(theStub, theUuid, getUID(),
85 expiration, aConstraints);
86 }
87
88 public MethodConstraints getConstraints() {
89 return theConstraints;
90 }
91 }