Mercurial > hg > blitz_stable
comparison src/org/dancres/blitz/lease/LeaseHandlers.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.lease; | |
2 | |
3 import java.io.IOException; | |
4 import java.io.InputStream; | |
5 import java.io.InputStreamReader; | |
6 | |
7 import java.util.logging.*; | |
8 | |
9 import net.jini.core.lease.UnknownLeaseException; | |
10 import net.jini.core.lease.LeaseDeniedException; | |
11 import net.jini.core.lease.Lease; | |
12 | |
13 import net.jini.config.ConfigurationException; | |
14 import net.jini.config.ConfigurationFile; | |
15 import net.jini.config.Configuration; | |
16 | |
17 import org.dancres.blitz.Logging; | |
18 | |
19 import org.dancres.blitz.config.ConfigurationFactory; | |
20 | |
21 import org.dancres.blitz.util.Time; | |
22 | |
23 /** | |
24 The access point for managing leases associated with SpaceUIDs. Lease | |
25 management is achieved through a collection of LeaseHandlers loaded from | |
26 <code>handlers.properties</code>. Each LeaseHandler "knows" about one | |
27 (or possibly more) types of SpaceUID and handles renewal or cancelling of | |
28 the lease associated with the SpaceUID. | |
29 | |
30 @see org.dancres.blitz.lease.LeaseHandler | |
31 */ | |
32 public class LeaseHandlers { | |
33 private static final String MODULE_NAME = | |
34 ConfigurationFactory.BLITZ_MODULE; | |
35 | |
36 private static final String HANDLER_PROPERTY = "handlers"; | |
37 | |
38 private static LeaseHandler[] theHandlers; | |
39 | |
40 private static Logger theLogger = | |
41 Logging.newLogger("org.dancres.blitz.lease.LeaseHandlers"); | |
42 | |
43 static { | |
44 try { | |
45 InputStream myStream = | |
46 LeaseHandlers.class.getResourceAsStream("handlers.properties"); | |
47 | |
48 if (myStream == null) | |
49 throw new IOException(); | |
50 else { | |
51 Configuration myConfig = | |
52 new ConfigurationFile(new InputStreamReader(myStream), | |
53 null); | |
54 | |
55 LeaseHandler[] myFilters = | |
56 (LeaseHandler[]) myConfig.getEntry(MODULE_NAME, | |
57 HANDLER_PROPERTY, | |
58 LeaseHandler[].class); | |
59 | |
60 theHandlers = myFilters; | |
61 } | |
62 | |
63 } catch (Exception anE) { | |
64 theLogger.log(Level.SEVERE, "Failed to load lease handlers", anE); | |
65 } | |
66 } | |
67 | |
68 public static long renew(SpaceUID aUID, long aLeaseDuration) | |
69 throws UnknownLeaseException, LeaseDeniedException, IOException { | |
70 | |
71 for (int i = 0; i < theHandlers.length; i++) { | |
72 if (theHandlers[i].recognizes(aUID)) { | |
73 return theHandlers[i].renew(aUID, aLeaseDuration); | |
74 } | |
75 } | |
76 | |
77 throw new UnknownLeaseException(); | |
78 } | |
79 | |
80 public static void cancel(SpaceUID aUID) | |
81 throws UnknownLeaseException, IOException { | |
82 | |
83 for (int i = 0; i < theHandlers.length; i++) { | |
84 if (theHandlers[i].recognizes(aUID)) { | |
85 theHandlers[i].cancel(aUID); | |
86 return; | |
87 } | |
88 } | |
89 | |
90 throw new UnknownLeaseException(); | |
91 } | |
92 } |