Mercurial > hg > blitz_condensed
comparison src/org/dancres/blitz/remote/perf/LeaseImpl.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.perf; | |
2 | |
3 import java.rmi.RemoteException; | |
4 | |
5 import com.sun.jini.lease.AbstractLease; | |
6 | |
7 import net.jini.core.lease.UnknownLeaseException; | |
8 import net.jini.core.lease.LeaseDeniedException; | |
9 import net.jini.core.lease.LeaseMap; | |
10 import net.jini.core.lease.Lease; | |
11 | |
12 import net.jini.id.Uuid; | |
13 import net.jini.id.ReferentUuid; | |
14 | |
15 import org.dancres.blitz.lease.SpaceUID; | |
16 | |
17 /** | |
18 Generic lease implementation used to wrap all Blitz's internal lease | |
19 implementations. | |
20 */ | |
21 class LeaseImpl extends AbstractLease implements ReferentUuid { | |
22 Landlord theStub; | |
23 Uuid theUuid; | |
24 | |
25 private SpaceUID theUID; | |
26 | |
27 LeaseImpl(Landlord aLandlord, Uuid aUuid, SpaceUID aUID, | |
28 long anExpiration) { | |
29 | |
30 super(anExpiration); | |
31 theStub = aLandlord; | |
32 theUID = aUID; | |
33 theUuid = aUuid; | |
34 } | |
35 | |
36 public Uuid getReferentUuid() { | |
37 return theUuid; | |
38 } | |
39 | |
40 protected long doRenew(long duration) | |
41 throws UnknownLeaseException, LeaseDeniedException, RemoteException { | |
42 | |
43 return theStub.renew(theUID, duration); | |
44 } | |
45 | |
46 public void cancel() | |
47 throws UnknownLeaseException, RemoteException { | |
48 | |
49 theStub.cancel(theUID); | |
50 } | |
51 | |
52 void setExpiration(long anExpiry) { | |
53 expiration = anExpiry; | |
54 } | |
55 | |
56 SpaceUID getUID() { | |
57 return theUID; | |
58 } | |
59 | |
60 /** | |
61 Each entry in a LeaseMap needs a duration to renew for so, when we | |
62 create the leasemap, we insert the current lease as having the specified | |
63 renewal duration. | |
64 */ | |
65 public LeaseMap createLeaseMap(long aDuration) { | |
66 return new LeaseMapImpl(this, aDuration, theStub); | |
67 } | |
68 | |
69 public boolean canBatch(Lease aLease) { | |
70 | |
71 if (aLease instanceof LeaseImpl) { | |
72 LeaseImpl myOther = (LeaseImpl) aLease; | |
73 | |
74 return myOther.theStub.equals(theStub); | |
75 } | |
76 | |
77 return false; | |
78 } | |
79 | |
80 public int hashCode() { | |
81 return theUID.hashCode(); | |
82 } | |
83 | |
84 public boolean equals(Object anObject) { | |
85 if (anObject instanceof LeaseImpl) { | |
86 if (theUuid.equals(((LeaseImpl) anObject).theUuid)) { | |
87 return (theUID.equals(((LeaseImpl) anObject).theUID)); | |
88 } | |
89 } | |
90 | |
91 return false; | |
92 } | |
93 } |