comparison src/org/dancres/blitz/remote/AdminProxy.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.Serializable;
4 import java.io.IOException;
5
6 import java.rmi.RemoteException;
7
8 import net.jini.core.entry.Entry;
9
10 import net.jini.core.discovery.LookupLocator;
11
12 import net.jini.core.transaction.TransactionException;
13 import net.jini.core.transaction.Transaction;
14
15 import net.jini.core.lease.Lease;
16
17 import net.jini.space.JavaSpace;
18
19 import net.jini.admin.JoinAdmin;
20
21 import net.jini.id.Uuid;
22 import net.jini.id.ReferentUuid;
23 import net.jini.id.ReferentUuids;
24
25 import com.sun.jini.admin.DestroyAdmin;
26
27 import com.sun.jini.outrigger.JavaSpaceAdmin;
28 import com.sun.jini.outrigger.AdminIterator;
29
30 import org.dancres.blitz.stats.Switch;
31 import org.dancres.blitz.stats.Stat;
32
33 import org.dancres.blitz.mangler.MangledEntry;
34 import org.dancres.blitz.mangler.EntryMangler;
35
36 import org.dancres.blitz.remote.view.EntryViewUID;
37
38 /**
39 Handles all admin-related functions for Blitz.
40 */
41 public class AdminProxy implements DestroyAdmin, JoinAdmin, Serializable,
42 ReferentUuid, StatsAdmin,
43 BlitzAdmin, JavaSpaceAdmin {
44 AdminServer theStub;
45 Uuid theUuid;
46
47 AdminProxy(AdminServer anAdminStub, Uuid aUuid) {
48 theStub = anAdminStub;
49 theUuid = aUuid;
50 }
51
52 private synchronized EntryMangler getMangler() {
53 return EntryMangler.getMangler();
54 }
55
56 public Uuid getReferentUuid() {
57 return theUuid;
58 }
59
60 /**
61 * Get the current attribute sets for the service.
62 *
63 * @return the current attribute sets for the service
64 * @throws java.rmi.RemoteException
65 */
66 public Entry[] getLookupAttributes() throws RemoteException {
67 return theStub.getLookupAttributes();
68 }
69
70 /**
71 * Add attribute sets for the service. The resulting set will be used
72 * for all future joins. The attribute sets are also added to all
73 * currently-joined lookup services.
74 *
75 * @param attrSets the attribute sets to add
76 * @throws java.rmi.RemoteException
77 */
78 public void addLookupAttributes(Entry[] attrSets) throws RemoteException {
79 theStub.addLookupAttributes(attrSets);
80 }
81
82 /**
83 * Modify the current attribute sets, using the same semantics as
84 * ServiceRegistration.modifyAttributes. The resulting set will be used
85 * for all future joins. The same modifications are also made to all
86 * currently-joined lookup services.
87 *
88 * @param attrSetTemplates the templates for matching attribute sets
89 * @param attrSets the modifications to make to matching sets
90 * @throws java.rmi.RemoteException
91 *
92 * @see net.jini.core.lookup.ServiceRegistration#modifyAttributes
93 */
94 public void modifyLookupAttributes(Entry[] attrSetTemplates,
95 Entry[] attrSets)
96 throws RemoteException {
97 theStub.modifyLookupAttributes(attrSetTemplates, attrSets);
98 }
99
100 /**
101 * Get the list of groups to join. An empty array means the service
102 * joins no groups (as opposed to "all" groups).
103 *
104 * @return an array of groups to join. An empty array means the service
105 * joins no groups (as opposed to "all" groups).
106 * @throws java.rmi.RemoteException
107 * @see #setLookupGroups
108 */
109 public String[] getLookupGroups() throws RemoteException {
110 return theStub.getLookupGroups();
111 }
112
113 /**
114 * Add new groups to the set to join. Lookup services in the new
115 * groups will be discovered and joined.
116 *
117 * @param groups groups to join
118 * @throws java.rmi.RemoteException
119 * @see #removeLookupGroups
120 */
121 public void addLookupGroups(String[] groups) throws RemoteException {
122 theStub.addLookupGroups(groups);
123 }
124
125 /**
126 * Remove groups from the set to join. Leases are cancelled at lookup
127 * services that are not members of any of the remaining groups.
128 *
129 * @param groups groups to leave
130 * @throws java.rmi.RemoteException
131 * @see #addLookupGroups
132 */
133 public void removeLookupGroups(String[] groups) throws RemoteException {
134 theStub.removeLookupGroups(groups);
135 }
136
137 /**
138 * Replace the list of groups to join with a new list. Leases are
139 * cancelled at lookup services that are not members of any of the
140 * new groups. Lookup services in the new groups will be discovered
141 * and joined.
142 *
143 * @param groups groups to join
144 * @throws java.rmi.RemoteException
145 * @see #getLookupGroups
146 */
147 public void setLookupGroups(String[] groups) throws RemoteException {
148 theStub.setLookupGroups(groups);
149 }
150
151 /**
152 *Get the list of locators of specific lookup services to join.
153 *
154 * @return the list of locators of specific lookup services to join
155 * @throws java.rmi.RemoteException
156 * @see #setLookupLocators
157 */
158 public LookupLocator[] getLookupLocators() throws RemoteException {
159 return theStub.getLookupLocators();
160 }
161
162 /**
163 * Add locators for specific new lookup services to join. The new
164 * lookup services will be discovered and joined.
165 *
166 * @param locators locators of specific lookup services to join
167 * @throws java.rmi.RemoteException
168 * @see #removeLookupLocators
169 */
170 public void addLookupLocators(LookupLocator[] locators)
171 throws RemoteException {
172 theStub.addLookupLocators(locators);
173 }
174
175 /**
176 * Remove locators for specific lookup services from the set to join.
177 * Any leases held at the lookup services are cancelled.
178 *
179 * @param locators locators of specific lookup services to leave
180 * @throws java.rmi.RemoteException
181 * @see #addLookupLocators
182 */
183 public void removeLookupLocators(LookupLocator[] locators)
184 throws RemoteException {
185 theStub.removeLookupLocators(locators);
186 }
187
188 /**
189 * Replace the list of locators of specific lookup services to join
190 * with a new list. Leases are cancelled at lookup services that were
191 * in the old list but are not in the new list. Any new lookup services
192 * will be discovered and joined.
193 *
194 * @param locators locators of specific lookup services to join
195 * @throws java.rmi.RemoteException
196 * @see #getLookupLocators
197 */
198 public void setLookupLocators(LookupLocator[] locators)
199 throws RemoteException {
200 theStub.setLookupLocators(locators);
201 }
202
203 public void destroy() throws RemoteException {
204 theStub.destroy();
205 }
206
207 public boolean equals(Object anObject) {
208 return ReferentUuids.compare(this, anObject);
209 }
210
211 public Stat[] getStats() throws RemoteException {
212 return theStub.getStats();
213 }
214
215 public void setSwitches(Switch[] aListOfSwitches) throws RemoteException {
216 theStub.setSwitches(aListOfSwitches);
217 }
218
219 public void requestSnapshot() throws RemoteException,
220 TransactionException, IOException {
221 theStub.requestSnapshot();
222 }
223
224 public void shutdown() throws RemoteException, IOException {
225 theStub.shutdown();
226 }
227
228 public void backup(String aDir) throws RemoteException, IOException {
229 theStub.backup(aDir);
230 }
231
232 public void clean() throws RemoteException, IOException {
233 theStub.clean();
234 }
235
236 public void reap() throws RemoteException {
237 theStub.reap();
238 }
239
240 /************************************************************************
241 * JavaSpaceAdmin
242 ***********************************************************************/
243
244 public JavaSpace space() throws RemoteException {
245 return theStub.getJavaSpaceProxy();
246 }
247
248 public AdminIterator contents(Entry aTmpl, Transaction aTxn)
249 throws TransactionException, RemoteException {
250
251 ViewResult myResult =
252 theStub.newView(new MangledEntry[] {packEntry(aTmpl)},
253 aTxn, Lease.FOREVER, false, Long.MAX_VALUE,
254 AdminIteratorImpl.CHUNK_SIZE);
255
256 // We only want the UID from this lease
257 EntryViewUID myViewId = (EntryViewUID) myResult.getLease().getUID();
258
259 return new AdminIteratorImpl(getMangler(), myViewId, theStub,
260 myResult.getInitialBatch());
261 }
262
263 public AdminIterator contents(Entry aTmpl, Transaction aTxn, int aFetchSize)
264 throws TransactionException, RemoteException {
265
266 ViewResult myResult =
267 theStub.newView(new MangledEntry[] {packEntry(aTmpl)},
268 aTxn, Lease.FOREVER, false, Long.MAX_VALUE,
269 AdminIteratorImpl.CHUNK_SIZE);
270
271 // We only want the UID from this lease
272 EntryViewUID myViewId = (EntryViewUID) myResult.getLease().getUID();
273
274 return new AdminIteratorImpl(getMangler(), myViewId,
275 aFetchSize, theStub, myResult.getInitialBatch());
276 }
277
278 private MangledEntry packEntry(Entry anEntry) {
279 if (anEntry == null)
280 return MangledEntry.NULL_TEMPLATE;
281 // Is it a snapshot?
282 else if (anEntry instanceof MangledEntry)
283 return (MangledEntry) anEntry;
284 else
285 return getMangler().mangle(anEntry);
286 }
287 }