1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.river.outrigger.proxy;
19
20 import java.io.IOException;
21 import java.io.InvalidObjectException;
22 import java.io.ObjectInputStream;
23 import java.io.Serializable;
24 import java.rmi.RemoteException;
25 import net.jini.core.discovery.LookupLocator;
26 import net.jini.core.entry.Entry;
27 import net.jini.core.transaction.Transaction;
28 import net.jini.core.transaction.TransactionException;
29 import net.jini.id.ReferentUuid;
30 import net.jini.id.ReferentUuids;
31 import net.jini.id.Uuid;
32 import net.jini.space.JavaSpace;
33 import org.apache.river.api.io.AtomicSerial;
34 import org.apache.river.api.io.AtomicSerial.GetArg;
35 import org.apache.river.admin.JavaSpaceAdmin;
36 import org.apache.river.admin.AdminIterator;
37
38
39
40
41
42
43
44
45 @AtomicSerial
46 public class AdminProxy implements JavaSpaceAdmin, ReferentUuid, Serializable {
47 private static final long serialVersionUID = 1L;
48
49
50 final OutriggerAdmin admin;
51
52
53 final Uuid spaceUuid;
54
55 private static final boolean DEBUG = false;
56
57
58
59
60
61
62
63
64
65 public AdminProxy(OutriggerAdmin admin, Uuid spaceUuid) {
66 this(check(admin,spaceUuid), admin, spaceUuid);
67 }
68
69 AdminProxy(GetArg arg) throws IOException {
70 this(serialCheck((OutriggerAdmin) arg.get("admin", null),
71 (Uuid) arg.get("spaceUuid", null)),
72 (OutriggerAdmin) arg.get("admin", null),
73 (Uuid) arg.get("spaceUuid", null)
74 );
75 }
76
77 private AdminProxy(boolean check, OutriggerAdmin admin, Uuid spaceUuid){
78 this.admin = admin;
79 this.spaceUuid = spaceUuid;
80 }
81
82 private static boolean serialCheck(OutriggerAdmin admin, Uuid spaceUuid) throws InvalidObjectException{
83 try {
84 return check(admin, spaceUuid);
85 } catch (NullPointerException ex){
86 InvalidObjectException e = new InvalidObjectException("Invariants not satisfied");
87 e.initCause(ex);
88 throw e;
89 }
90 }
91
92 private static boolean check(OutriggerAdmin admin, Uuid spaceUuid){
93 if (admin == null)
94 throw new NullPointerException("admin must be non-null");
95 if (spaceUuid == null)
96 throw new NullPointerException("spaceUuid must be non-null");
97 return true;
98 }
99
100
101
102
103
104
105
106 private void readObject(ObjectInputStream in)
107 throws IOException, ClassNotFoundException
108 {
109 in.defaultReadObject();
110
111 if (admin == null)
112 throw new InvalidObjectException("null server reference");
113
114 if (spaceUuid == null)
115 throw new InvalidObjectException("null Uuid");
116 }
117
118
119
120
121
122
123 private void readObjectNoData() throws InvalidObjectException {
124 throw new
125 InvalidObjectException("SpaceProxy should always have data");
126 }
127
128
129 public JavaSpace space() throws RemoteException {
130 return admin.space();
131 }
132
133
134 public AdminIterator contents(Entry tmpl, Transaction tr)
135 throws TransactionException, RemoteException
136 {
137 return contents(tmpl, tr, USE_DEFAULT);
138 }
139
140
141 public AdminIterator contents(Entry tmpl, Transaction tr, int fetchSize)
142 throws TransactionException, RemoteException
143 {
144 return new IteratorProxy(
145 admin.contents(SpaceProxy2.repFor(tmpl), tr), admin, fetchSize);
146 }
147
148
149 public void destroy() throws RemoteException {
150 admin.destroy();
151 }
152
153
154
155
156 public Entry[] getLookupAttributes() throws RemoteException {
157 return admin.getLookupAttributes();
158 }
159
160
161 public void addLookupAttributes(Entry[] attrSets)
162 throws RemoteException
163 {
164 admin.addLookupAttributes(attrSets);
165 }
166
167
168 public void modifyLookupAttributes(Entry[] attrSetTemplates,
169 Entry[] attrSets)
170 throws RemoteException
171 {
172 admin.modifyLookupAttributes(attrSetTemplates, attrSets);
173 }
174
175
176 public String[] getLookupGroups() throws RemoteException {
177 return admin.getLookupGroups();
178 }
179
180
181 public void addLookupGroups(String[] groups) throws RemoteException {
182 admin.addLookupGroups(groups);
183 }
184
185
186 public void removeLookupGroups(String[] groups)
187 throws RemoteException
188 {
189 admin.removeLookupGroups(groups);
190 }
191
192
193 public void setLookupGroups(String[] groups) throws RemoteException {
194 admin.setLookupGroups(groups);
195 }
196
197
198 public LookupLocator[] getLookupLocators() throws RemoteException {
199 return admin.getLookupLocators();
200 }
201
202
203 public void addLookupLocators(LookupLocator[] locators)
204 throws RemoteException
205 {
206 admin.addLookupLocators(locators);
207 }
208
209
210 public void removeLookupLocators(LookupLocator[] locators)
211 throws RemoteException
212 {
213 admin.removeLookupLocators(locators);
214 }
215
216
217 public void setLookupLocators(LookupLocator[] locators)
218 throws RemoteException
219 {
220 admin.setLookupLocators(locators);
221 }
222
223 public String toString() {
224 return getClass().getName() + " for " + spaceUuid +
225 " (through " + admin + ")";
226 }
227
228 public boolean equals(Object other) {
229 return ReferentUuids.compare(this, other);
230 }
231
232 public int hashCode() {
233 return spaceUuid.hashCode();
234 }
235
236 public Uuid getReferentUuid() {
237 return spaceUuid;
238 }
239 }