1:
37:
38:
39: package ;
40:
41: import ;
42: import ;
43: import ;
44: import ;
45: import ;
46: import ;
47: import ;
48: import ;
49: import ;
50: import ;
51: import ;
52: import ;
53: import ;
54: import ;
55: import ;
56: import ;
57: import ;
58: import ;
59:
60:
65: public class ActivationSystemTransient
66: extends DefaultActivationSystem
67: implements ActivationSystem, ActivationMonitor, Activator
68: {
69:
72: protected final BidiTable groupDescs;
73:
74:
77: protected final BidiTable descriptions;
78:
79:
82: protected transient final Map groupInstantiators = new Hashtable();
83:
84:
88: protected transient final Map activatedObjects = new HashMap();
89:
90:
93: static long groupIncarnations = 0;
94:
95:
98: static ActivationSystem singleton;
99:
100:
103: public static boolean debug = false;
104:
105:
106:
109: protected ActivationSystemTransient(BidiTable objectDescriptions,
110: BidiTable groupDescriptiopns)
111: {
112: descriptions = objectDescriptions;
113: groupDescs = groupDescriptiopns;
114: }
115:
116:
119: protected ActivationSystemTransient()
120: {
121: this (new BidiTable(), new BidiTable());
122: }
123:
124: public static ActivationSystem getInstance()
125: {
126: if (singleton == null)
127: singleton = new ActivationSystemTransient();
128: return singleton;
129: }
130:
131:
134: public MarshalledObject activate(ActivationID id, boolean force)
135: throws ActivationException, UnknownObjectException, RemoteException
136: {
137: if (! force)
138: {
139: synchronized (activatedObjects)
140: {
141: MarshalledObject object = (MarshalledObject) activatedObjects.get(id);
142: if (object != null)
143: return object;
144: }
145: }
146:
147: ActivationDesc desc = (ActivationDesc) descriptions.get(id);
148: if (desc == null)
149: throw new UnknownObjectException("Activating unknown object "+
150: id == null ? "null" : id.toString());
151:
152: ActivationInstantiator group =
153: (ActivationInstantiator) groupInstantiators.get(desc.getGroupID());
154:
155: if (group == null)
156: {
157:
158: ActivationGroupID gid = desc.getGroupID();
159: ActivationGroupDesc adesc = (ActivationGroupDesc) groupDescs.get(gid);
160:
161: if (adesc == null)
162: throw new UnknownGroupException("Activating unknown group "
163: + gid + " for "+ id+" this "+this);
164:
165: synchronized (ActivationSystemTransient.class)
166: {
167: groupIncarnations++;
168: }
169:
170: group = ActivationGroup.createGroup(gid, adesc, groupIncarnations);
171: activeGroup(gid, group, groupIncarnations);
172: }
173:
174: MarshalledObject object = group.newInstance(id, desc);
175:
176: synchronized (activatedObjects)
177: {
178: activatedObjects.put(id, object);
179: }
180: return object;
181: }
182:
183:
187: public ActivationMonitor activeGroup(ActivationGroupID id,
188: ActivationInstantiator group,
189: long incarnation)
190: throws UnknownGroupException, ActivationException, RemoteException
191: {
192: groupInstantiators.put(id, group);
193: return this;
194: }
195:
196:
202: public ActivationDesc getActivationDesc(ActivationID id)
203: throws ActivationException, UnknownObjectException, RemoteException
204: {
205: ActivationDesc desc = (ActivationDesc) descriptions.get(id);
206: if (desc == null)
207: throw new UnknownObjectException("No desc for "+
208: id == null ? "null" : id.toString());
209: return desc;
210: }
211:
212:
218: public ActivationGroupDesc getActivationGroupDesc(ActivationGroupID groupId)
219: throws ActivationException, UnknownGroupException, RemoteException
220: {
221: ActivationGroupDesc desc = (ActivationGroupDesc) groupDescs.get(groupId);
222: if (desc == null)
223: throw new UnknownGroupException(groupId == null ? "null"
224: : groupId.toString());
225: return desc;
226: }
227:
228:
234: public ActivationGroupID registerGroup(ActivationGroupDesc groupDesc)
235: throws ActivationException, RemoteException
236: {
237: ActivationGroupID id = (ActivationGroupID) groupDescs.getKey(groupDesc);
238: if (id == null)
239: {
240: id = new ActivationGroupID(this);
241: groupDescs.put(id, groupDesc);
242: }
243: if (debug)
244: System.out.println("Register group " + id +":"+groupDesc+" this "+this);
245:
246: return id;
247: }
248:
249:
255: public ActivationID registerObject(ActivationDesc desc)
256: throws ActivationException, UnknownGroupException, RemoteException
257: {
258: ActivationID id = (ActivationID) descriptions.getKey(desc);
259: if (id == null)
260: {
261: id = new ActivationID(this);
262: descriptions.put(id, desc);
263: }
264:
265: if (debug)
266: System.out.println("Register object " + id +":"+desc+" this "+this);
267:
268: return id;
269: }
270:
271:
274: public ActivationDesc setActivationDesc(ActivationID id, ActivationDesc desc)
275: throws ActivationException, UnknownObjectException,
276: UnknownGroupException, RemoteException
277: {
278: ActivationDesc prev = getActivationDesc(id);
279: descriptions.put(id, desc);
280: return prev;
281: }
282:
283:
286: public ActivationGroupDesc setActivationGroupDesc(
287: ActivationGroupID groupId,
288: ActivationGroupDesc groupDesc)
289: throws ActivationException, UnknownGroupException, RemoteException
290: {
291: ActivationGroupDesc prev = getActivationGroupDesc(groupId);
292: groupDescs.put(groupId, groupDesc);
293: return prev;
294: }
295:
296:
300: public void shutdown() throws RemoteException
301: {
302: descriptions.shutdown();
303: groupDescs.shutdown();
304: }
305:
306:
309: public void unregisterGroup(ActivationGroupID groupId) throws ActivationException,
310: UnknownGroupException, RemoteException
311: {
312: if (! groupDescs.containsKey(groupId))
313: throw new UnknownGroupException("Unknown group "+groupId);
314:
315: groupDescs.removeKey(groupId);
316: groupInstantiators.remove(groupId);
317: }
318:
319:
322: public void unregisterObject(ActivationID id) throws ActivationException,
323: UnknownObjectException, RemoteException
324: {
325: if (! descriptions.containsKey(id))
326: throw new UnknownObjectException("Unregistering unknown object");
327: descriptions.removeKey(id);
328:
329: synchronized (activatedObjects)
330: {
331: activatedObjects.remove(id);
332: }
333: }
334:
335:
338: public void activeObject(ActivationID id, MarshalledObject obj)
339: throws UnknownObjectException, RemoteException
340: {
341: if (! descriptions.containsKey(id))
342: throw new UnknownObjectException("Activating unknown object "+
343: id+" this "+this);
344: try
345: {
346: synchronized (activatedObjects)
347: {
348: activatedObjects.put(id, obj.get());
349: }
350: }
351: catch (RemoteException e)
352: {
353: throw e;
354: }
355: catch (Exception e)
356: {
357: UnknownObjectException un = new UnknownObjectException(
358: "Cannot get Remote for MarshalledObject of "+id);
359: un.detail = e;
360: throw un;
361: }
362: }
363:
364:
368: public void inactiveGroup(ActivationGroupID groupId, long incarnation)
369: throws UnknownGroupException, RemoteException
370: {
371: if (! groupInstantiators.containsKey(groupId))
372: throw new UnknownGroupException("Inactivating unkwnon group");
373:
374: groupInstantiators.remove(groupId);
375:
376:
377: synchronized (activatedObjects)
378: {
379: Iterator iter = activatedObjects.keySet().iterator();
380: ActivationID id;
381: ActivationDesc desc;
382: while (iter.hasNext())
383: {
384: id = (ActivationID) iter.next();
385: desc = (ActivationDesc) descriptions.get(id);
386: if (desc.getGroupID().equals(groupId))
387: activatedObjects.remove(id);
388: }
389: }
390: }
391:
392:
395: public void inactiveObject(ActivationID id) throws UnknownObjectException,
396: RemoteException
397: {
398: if (! descriptions.containsKey(id))
399: throw new UnknownObjectException("Inactivating unknown object");
400:
401: synchronized (activatedObjects)
402: {
403: activatedObjects.remove(id);
404: }
405: }
406: }