Mercurial > hg > blitz_condensed
comparison src/org/dancres/blitz/remote/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; | |
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 public class LeaseImpl extends AbstractLease implements ReferentUuid { | |
22 Landlord theStub; | |
23 Uuid theUuid; | |
24 | |
25 private SpaceUID theUID; | |
26 | |
27 public 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 void setLandlord(Landlord aLandlord, Uuid aUid) { | |
37 theStub = aLandlord; | |
38 theUuid = aUid; | |
39 } | |
40 | |
41 public Uuid getReferentUuid() { | |
42 return theUuid; | |
43 } | |
44 | |
45 protected long doRenew(long duration) | |
46 throws UnknownLeaseException, LeaseDeniedException, RemoteException { | |
47 | |
48 return theStub.renew(theUID, duration); | |
49 } | |
50 | |
51 public void cancel() | |
52 throws UnknownLeaseException, RemoteException { | |
53 | |
54 theStub.cancel(theUID); | |
55 } | |
56 | |
57 void setExpiration(long anExpiry) { | |
58 expiration = anExpiry; | |
59 } | |
60 | |
61 SpaceUID getUID() { | |
62 return theUID; | |
63 } | |
64 | |
65 /** | |
66 Each entry in a LeaseMap needs a duration to renew for so, when we | |
67 create the leasemap, we insert the current lease as having the specified | |
68 renewal duration. | |
69 */ | |
70 public LeaseMap createLeaseMap(long aDuration) { | |
71 return new LeaseMapImpl(this, aDuration, theStub); | |
72 } | |
73 | |
74 public boolean canBatch(Lease aLease) { | |
75 | |
76 if (aLease instanceof LeaseImpl) { | |
77 LeaseImpl myOther = (LeaseImpl) aLease; | |
78 | |
79 return myOther.theStub.equals(theStub); | |
80 } | |
81 | |
82 return false; | |
83 } | |
84 | |
85 public int hashCode() { | |
86 return theUID.hashCode(); | |
87 } | |
88 | |
89 public boolean equals(Object anObject) { | |
90 if (anObject instanceof LeaseImpl) { | |
91 if (theUuid.equals(((LeaseImpl) anObject).theUuid)) { | |
92 return (theUID.equals(((LeaseImpl) anObject).theUID)); | |
93 } | |
94 } | |
95 | |
96 return false; | |
97 } | |
98 | |
99 public String toString() { | |
100 return "LeaseImpl: " + theUID; | |
101 } | |
102 } |