1:
37:
38:
39: package ;
40:
41: import ;
42:
43: import ;
44: import ;
45: import ;
46:
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: import ;
60: import ;
61: import ;
62: import ;
63: import ;
64: import ;
65: import ;
66: import ;
67: import ;
68: import ;
69: import ;
70: import ;
71: import ;
72: import ;
73: import ;
74: import ;
75: import ;
76: import ;
77: import ;
78: import ;
79: import ;
80: import ;
81: import ;
82: import ;
83: import ;
84: import ;
85: import ;
86: import ;
87: import ;
88: import ;
89: import ;
90: import ;
91: import ;
92: import ;
93: import ;
94: import ;
95: import ;
96: import ;
97:
98: import ;
99: import ;
100: import ;
101:
102:
107: public class gnuPOA
108: extends LocalObject
109: implements POA, ObjectReferenceFactory
110: {
111:
116: class RefTemplate implements ObjectReferenceTemplate
117: {
118:
121: private static final long serialVersionUID = 1;
122:
123: RefTemplate()
124: {
125:
126: ArrayList names = new ArrayList();
127: names.add(the_name());
128:
129: POA poa = the_parent();
130: while (poa != null)
131: {
132: names.add(poa.the_name());
133: poa = poa.the_parent();
134: }
135:
136:
137:
138: m_adapter_name = new String[names.size()];
139:
140: for (int i = 0; i < m_adapter_name.length; i++)
141: m_adapter_name[i] = (String) names.get(m_adapter_name.length - i - 1);
142: }
143:
144:
147: final String[] m_adapter_name;
148:
149:
152: public String[] adapter_name()
153: {
154: return (String[]) m_adapter_name.clone();
155: }
156:
157:
160: public String orb_id()
161: {
162: return m_orb.orb_id;
163: }
164:
165:
168: public String server_id()
169: {
170: return OrbFunctional.server_id;
171: }
172:
173:
176: public Object make_object(String repositoryId, byte[] objectId)
177: {
178: return create_reference_with_id(objectId, repositoryId);
179: }
180:
181:
184: public String[] _truncatable_ids()
185: {
186: return ref_template_ids;
187: }
188: }
189:
190:
193: private static final long serialVersionUID = 1;
194:
195:
198: ObjectReferenceTemplate refTemplate;
199:
200:
204: final static String[] ref_template_ids =
205: new String[] { ObjectReferenceTemplateHelper.id() };
206:
207:
210: public final AOM aom = new AOM();
211:
212:
215: final ArrayList children = new ArrayList();
216:
217:
220: final String name;
221:
222:
225: final POA parent;
226:
227:
231: static final int SIGNATURE = 0x66726565;
232:
233:
236: AdapterActivator m_activator;
237:
238:
241: POAManager m_manager;
242:
243:
246: ServantActivator servant_activator;
247:
248:
251: ServantLocator servant_locator;
252:
253:
256: Servant default_servant;
257:
258:
261: private byte[] m_poa_id;
262:
263:
267: private final HashSet m_policies;
268:
269:
272: Policy[] s_policies;
273:
274:
277: final ORB_1_4 m_orb;
278:
279:
282: boolean m_inDestruction;
283:
284:
289: public final boolean retain_servant;
290:
291:
295: ObjectReferenceFactory m_object_factory = this;
296:
297:
307: public gnuPOA(gnuPOA a_parent, String a_name, POAManager a_manager,
308: Policy[] a_policies, ORB_1_4 an_orb
309: )
310: throws InvalidPolicy
311: {
312:
313: Policy[] all_policies = StandardPolicies.withDefault(a_policies);
314:
315: name = a_name;
316: parent = a_parent;
317: m_orb = an_orb;
318:
319: if (a_manager != null)
320: m_manager = a_manager;
321: else
322: m_manager = new gnuPOAManager();
323:
324: if (m_manager instanceof gnuPOAManager)
325: {
326: gnuPOAManager g = (gnuPOAManager) m_manager;
327: g.addPoa(this);
328: }
329:
330: m_policies = new HashSet(all_policies.length);
331:
332: s_policies = new Policy[ all_policies.length ];
333: for (int i = 0; i < s_policies.length; i++)
334: {
335: s_policies [ i ] = all_policies [ i ].copy();
336: m_policies.add(((AccessiblePolicy) s_policies [ i ]).getValue());
337: }
338:
339: retain_servant = applies(ServantRetentionPolicyValue.RETAIN);
340:
341: validatePolicies(a_policies);
342:
343: refTemplate = new RefTemplate();
344: }
345:
346:
350: public void waitWhileRunning()
351: {
352:
353: long time = 1;
354:
355:
356: long max = 500;
357:
358: boolean runs;
359:
360: do
361: {
362: runs = m_orb.currents.has(this);
363:
364: if (runs)
365: {
366:
367:
368: try
369: {
370: Thread.sleep(time);
371: time = time * 2;
372: if (time > max)
373: time = max;
374: }
375: catch (InterruptedException ex)
376: {
377: }
378: }
379: }
380: while (runs);
381: }
382:
383:
388: protected void etherealizeAll()
389: {
390: if (servant_activator == null)
391: return;
392:
393: ArrayList keys = new ArrayList();
394: keys.addAll(aom.keySet());
395:
396: byte[] key;
397: AOM.Obj obj;
398: boolean last;
399: for (int i = 0; i < keys.size(); i++)
400: {
401: key = (byte[]) keys.get(i);
402: obj = aom.get(key);
403:
404: if (obj.poa == this)
405: {
406: aom.remove(key);
407:
408: if (!obj.isDeactiveted())
409: {
410:
411: last = aom.findServant(obj.servant) == null;
412: servant_activator.etherealize(obj.key, this, obj.servant, true,
413: last
414: );
415: }
416: }
417: }
418: }
419:
420:
434: protected POA createPoaInstance(String child_name, POAManager a_manager,
435: Policy[] policies, ORB_1_4 an_orb
436: )
437: throws InvalidPolicy
438: {
439: POAManager some_manager =
440: a_manager == null ? new gnuPOAManager() : a_manager;
441:
442: if (some_manager instanceof gnuPOAManager)
443: {
444: ((gnuPOAManager) some_manager).addPoa(this);
445: }
446:
447: return new gnuPOA(this, child_name, some_manager, policies, an_orb);
448: }
449:
450:
459: public final boolean applies(java.lang.Object policy_value)
460: {
461: return m_policies.contains(policy_value);
462: }
463:
464:
471: public final void required(java.lang.Object policy_value)
472: throws WrongPolicy
473: {
474: if (!applies(policy_value))
475: throw new WrongPolicy(policy_value + " policy required.");
476: }
477:
478:
485: public final void excluding(java.lang.Object policy_value)
486: throws WrongPolicy
487: {
488: if (applies(policy_value))
489: throw new WrongPolicy(policy_value + " policy applies.");
490: }
491:
492:
507: public POA find_POA(String poa_name, boolean activate_it)
508: throws AdapterNonExistent
509: {
510: POA child;
511: for (int i = 0; i < children.size(); i++)
512: {
513: child = (POA) children.get(i);
514: if (child.the_name().equals(poa_name))
515: return child;
516: }
517:
518: if (activate_it && m_activator != null)
519: {
520: boolean activated = m_activator.unknown_adapter(this, poa_name);
521: if (!activated)
522: throw new AdapterNonExistent(poa_name + " activation failed.");
523:
524:
525: for (int i = 0; i < children.size(); i++)
526: {
527: child = (POA) children.get(i);
528: if (child.the_name().equals(poa_name))
529: return child;
530: }
531: throw new AdapterNonExistent(poa_name + " not created. ");
532: }
533: else
534: throw new AdapterNonExistent(poa_name);
535: }
536:
537:
554: public byte[] activate_object(Servant a_servant)
555: throws ServantAlreadyActive, WrongPolicy
556: {
557: checkDiscarding();
558: required(ServantRetentionPolicyValue.RETAIN);
559: required(IdAssignmentPolicyValue.SYSTEM_ID);
560:
561: AOM.Obj exists = aom.findServant(a_servant);
562:
563: if (exists != null)
564: {
565: if (exists.isDeactiveted())
566: {
567:
568:
569: exists.setDeactivated(false);
570: incarnate(exists, exists.key, a_servant, false);
571: return exists.key;
572: }
573: else if (applies(IdUniquenessPolicyValue.UNIQUE_ID))
574: throw new ServantAlreadyActive();
575:
576:
577:
578: }
579:
580: byte[] object_key = AOM.getFreeId();
581: ServantDelegateImpl delegate = new ServantDelegateImpl(a_servant, this,
582: object_key);
583: create_and_connect(object_key,
584: a_servant._all_interfaces(this, object_key)[0], delegate);
585: return object_key;
586: }
587:
588:
606: public void activate_object_with_id(byte[] an_Object_Id, Servant a_servant)
607: throws ServantAlreadyActive, ObjectAlreadyActive,
608: WrongPolicy
609: {
610: activate_object_with_id(an_Object_Id, a_servant, false);
611: }
612:
613:
619: public void activate_object_with_id(byte[] an_Object_Id, Servant a_servant,
620: boolean use_forwarding)
621: throws ServantAlreadyActive, ObjectAlreadyActive, WrongPolicy
622: {
623: checkDiscarding();
624: required(ServantRetentionPolicyValue.RETAIN);
625:
626:
627:
628: if (applies(IdUniquenessPolicyValue.UNIQUE_ID))
629: {
630: AOM.Obj sx = aom.findServant(a_servant, false);
631: if (sx != null)
632: throw new ServantAlreadyActive();
633: }
634:
635: AOM.Obj exists = aom.get(an_Object_Id);
636: if (exists != null)
637: {
638: if (exists.servant == null)
639: {
640: locateServant(an_Object_Id, a_servant, exists, use_forwarding);
641: exists.setDeactivated(false);
642: }
643: else if (exists.isDeactiveted())
644: {
645: exists.setDeactivated(false);
646: incarnate(exists, an_Object_Id, a_servant, use_forwarding);
647: }
648: else
649: throw new ObjectAlreadyActive();
650: }
651: else
652: {
653: ServantDelegateImpl delegate = new ServantDelegateImpl(a_servant, this,
654: an_Object_Id);
655: create_and_connect(an_Object_Id, a_servant._all_interfaces(this,
656: an_Object_Id)[0], delegate);
657: }
658: }
659:
660:
672: private void locateServant(byte[] an_Object_Id, Servant a_servant,
673: AOM.Obj exists, boolean use_forwarding
674: )
675: throws InternalError
676: {
677:
678: gnuServantObject object = (gnuServantObject) exists.object;
679: if (servant_activator != null)
680: {
681: exists.setServant(incarnate(exists, an_Object_Id, a_servant,
682: use_forwarding
683: )
684: );
685: }
686: else if (default_servant != null)
687: {
688: exists.setServant(default_servant);
689: }
690: if (exists.servant == null)
691: {
692: exists.setServant(a_servant);
693: }
694: if (exists.servant == null)
695: {
696: throw new OBJ_ADAPTER("no servant", 4, CompletionStatus.COMPLETED_NO);
697: }
698:
699: ServantDelegateImpl delegate =
700: new ServantDelegateImpl(exists.servant, this, an_Object_Id);
701: exists.servant._set_delegate(delegate);
702: object.setServant(exists.servant);
703: connect_to_orb(an_Object_Id, delegate.object);
704: }
705:
706:
717: public void deactivate_object(byte[] the_Object_Id)
718: throws ObjectNotActive, WrongPolicy
719: {
720: required(ServantRetentionPolicyValue.RETAIN);
721:
722: AOM.Obj exists = aom.get(the_Object_Id);
723:
724: if (exists == null || exists.isDeactiveted())
725: throw new ObjectNotActive();
726:
727: exists.setDeactivated(true);
728:
729:
730: aom.remove(the_Object_Id);
731:
732: AOM.Obj other = aom.findServant(exists.servant, false);
733:
734: boolean remaining = other != null;
735:
736: aom.put(exists);
737:
738: if (servant_activator != null)
739: servant_activator.etherealize(the_Object_Id, this, exists.servant, false,
740: remaining
741: );
742: }
743:
744:
756: public org.omg.CORBA.Object create_reference(String a_repository_id)
757: throws WrongPolicy
758: {
759: required(IdAssignmentPolicyValue.SYSTEM_ID);
760: return create_reference_with_id(AOM.getFreeId(), a_repository_id);
761: }
762:
763:
778: public org.omg.CORBA.Object create_reference_with_id(byte[] an_object_id,
779: String a_repository_id
780: )
781: {
782: String[] ids;
783: if (a_repository_id == null)
784: ids = null;
785: else
786: ids = new String[] { a_repository_id };
787:
788:
789: AOM.Obj e = aom.get(an_object_id);
790:
791: Servant servant;
792: if (e == null)
793: {
794: servant = null;
795: }
796: else
797: {
798: servant = e.servant;
799: e.setDeactivated(false);
800: }
801:
802: gnuServantObject object =
803: new gnuServantObject(ids, an_object_id, this, m_orb);
804: object._set_delegate(new LocalDelegate(object, this, an_object_id));
805: aom.add(object.Id, object, servant, this);
806: connect_to_orb(an_object_id, object);
807:
808: return object;
809: }
810:
811:
831: public POA create_POA(String child_name, POAManager manager, Policy[] policies)
832: throws AdapterAlreadyExists, InvalidPolicy
833: {
834: POA child;
835: for (int i = 0; i < children.size(); i++)
836: {
837: child = (POA) children.get(i);
838: if (child.the_name().equals(child_name))
839: throw new AdapterAlreadyExists(name + "/" + child_name);
840: }
841:
842: POA poa = createPoaInstance(child_name, manager, policies, m_orb);
843: children.add(poa);
844: return poa;
845: }
846:
847:
856: public Servant get_servant()
857: throws NoServant, WrongPolicy
858: {
859: required(RequestProcessingPolicyValue.USE_DEFAULT_SERVANT);
860: if (default_servant == null)
861: throw new NoServant();
862: return default_servant;
863: }
864:
865:
873: public void set_servant(Servant a_servant)
874: throws WrongPolicy
875: {
876: required(RequestProcessingPolicyValue.USE_DEFAULT_SERVANT);
877: default_servant = a_servant;
878: }
879:
880:
899: public void set_servant_manager(ServantManager a_manager)
900: throws WrongPolicy
901: {
902: required(RequestProcessingPolicyValue.USE_SERVANT_MANAGER);
903: if (servant_activator != null || servant_locator != null)
904: throw new BAD_INV_ORDER("Setting manager twice for " + name, 6,
905: CompletionStatus.COMPLETED_NO
906: );
907:
908: if (applies(ServantRetentionPolicyValue.RETAIN))
909: {
910: if (a_manager instanceof ServantActivator)
911: servant_activator = (ServantActivator) a_manager;
912: else
913: throw new OBJ_ADAPTER("RETAIN requires ServantActivator", 4,
914: CompletionStatus.COMPLETED_NO
915: );
916: }
917: else if (applies(ServantRetentionPolicyValue.NON_RETAIN))
918: {
919: if (a_manager instanceof ServantLocator)
920: servant_locator = (ServantLocator) a_manager;
921: else
922: throw new OBJ_ADAPTER("NON_RETAIN requires ServantLocator", 4,
923: CompletionStatus.COMPLETED_NO
924: );
925: }
926: else
927: throw new WrongPolicy("No servant retention policy is specified.");
928: }
929:
930:
939: public ServantManager get_servant_manager()
940: throws WrongPolicy
941: {
942: required(RequestProcessingPolicyValue.USE_SERVANT_MANAGER);
943:
944: if (servant_activator != null)
945: return servant_activator;
946: else
947: return servant_locator;
948: }
949:
950:
958: public byte[] id()
959: {
960: if (m_poa_id != null)
961: return m_poa_id;
962: else
963: {
964: BufferedCdrOutput buffer = new BufferedCdrOutput();
965: POA p = this;
966: while (p != null)
967: {
968: buffer.write_string(p.the_name());
969: p = p.the_parent();
970: }
971: m_poa_id = buffer.buffer.toByteArray();
972: return m_poa_id;
973: }
974: }
975:
976:
986: public org.omg.CORBA.Object id_to_reference(byte[] the_Object_Id)
987: throws ObjectNotActive, WrongPolicy
988: {
989: required(ServantRetentionPolicyValue.RETAIN);
990:
991: AOM.Obj ref = aom.get(the_Object_Id);
992: if (ref == null)
993: throw new ObjectNotActive();
994: else
995: return ref.object;
996: }
997:
998:
1009: public Servant id_to_servant(byte[] the_Object_Id)
1010: throws ObjectNotActive, WrongPolicy
1011: {
1012: if (applies(ServantRetentionPolicyValue.RETAIN))
1013: {
1014: AOM.Obj ref = aom.get(the_Object_Id);
1015: if (ref == null || ref.isDeactiveted())
1016: {
1017: if (default_servant != null)
1018: return default_servant;
1019: else
1020: throw new ObjectNotActive();
1021: }
1022: else if (ref.servant != null)
1023: return ref.servant;
1024: else if (default_servant != null)
1025: return default_servant;
1026: else
1027: throw new ObjectNotActive();
1028: }
1029: else if (default_servant != null)
1030: {
1031: return default_servant;
1032: }
1033: else
1034: throw new WrongPolicy("Either RETAIN or USE_DEFAULT_SERVANT required.");
1035: }
1036:
1037:
1046: public byte[] reference_to_id(org.omg.CORBA.Object the_Object)
1047: throws WrongAdapter, WrongPolicy
1048: {
1049: AOM.Obj ref = aom.findObject(the_Object);
1050: if (ref == null)
1051: throw new WrongAdapter();
1052: return ref.key;
1053: }
1054:
1055:
1069: public Servant reference_to_servant(org.omg.CORBA.Object the_Object)
1070: throws ObjectNotActive, WrongPolicy, WrongAdapter
1071: {
1072: if (applies(ServantRetentionPolicyValue.RETAIN))
1073: {
1074: AOM.Obj ref = aom.findObject(the_Object);
1075: if (ref == null)
1076: {
1077: String object;
1078: if (the_Object == null)
1079: object = "null passed";
1080: else if (the_Object instanceof gnuServantObject)
1081: {
1082: gnuServantObject gs = (gnuServantObject) the_Object;
1083: object = "Wrong owner POA " + gs.poa.the_name();
1084: }
1085: else
1086: object = "Unknown " + the_Object.getClass().getName();
1087:
1088: throw new WrongAdapter(object + " for '" + the_name() + "'");
1089: }
1090: else if (ref.isDeactiveted() || ref.servant == null)
1091: {
1092: if (default_servant != null)
1093: return default_servant;
1094: else
1095: throw new ObjectNotActive();
1096: }
1097: else
1098: return ref.servant;
1099: }
1100: else if (default_servant != null)
1101: {
1102: return default_servant;
1103: }
1104: else
1105: throw new WrongPolicy("Either RETAIN or USE_DEFAULT_SERVANT required.");
1106: }
1107:
1108:
1133: public byte[] servant_to_id(Servant the_Servant)
1134: throws ServantNotActive, WrongPolicy
1135: {
1136: if (applies(RequestProcessingPolicyValue.USE_DEFAULT_SERVANT) ||
1137: applies(ServantRetentionPolicyValue.RETAIN) &&
1138: (
1139: applies(IdUniquenessPolicyValue.UNIQUE_ID) ||
1140: applies(ImplicitActivationPolicyValue.IMPLICIT_ACTIVATION)
1141: )
1142: )
1143: {
1144: AOM.Obj ref = null;
1145: if (!applies(IdUniquenessPolicyValue.MULTIPLE_ID))
1146: ref = aom.findServant(the_Servant);
1147: if (ref == null &&
1148: applies(ImplicitActivationPolicyValue.IMPLICIT_ACTIVATION)
1149: )
1150: {
1151:
1152: try
1153: {
1154: return activate_object(the_Servant);
1155: }
1156: catch (ServantAlreadyActive ex)
1157: {
1158:
1159: throw new InternalError();
1160: }
1161: }
1162: if (ref == null)
1163: throw new ServantNotActive();
1164: else
1165: return ref.key;
1166: }
1167: else
1168: throw new WrongPolicy("(RETAIN and UNIQUE ID) " +
1169: "or USE_DEFAULT_SERVANT required."
1170: );
1171: }
1172:
1173:
1193: public org.omg.CORBA.Object servant_to_reference(Servant the_Servant)
1194: throws ServantNotActive, WrongPolicy
1195: {
1196: required(ServantRetentionPolicyValue.RETAIN);
1197:
1198: AOM.Obj exists = null;
1199:
1200: if (!applies(IdUniquenessPolicyValue.MULTIPLE_ID))
1201: exists = aom.findServant(the_Servant);
1202:
1203: if (exists != null)
1204: {
1205: if (exists.isDeactiveted())
1206: {
1207: if (applies(ImplicitActivationPolicyValue.IMPLICIT_ACTIVATION))
1208: {
1209: checkDiscarding();
1210: exists.setDeactivated(false);
1211: incarnate(exists, exists.key, the_Servant, false);
1212: }
1213: else
1214: throw new ServantNotActive();
1215: }
1216: else
1217: return exists.object;
1218: }
1219: if (exists == null
1220: && applies(ImplicitActivationPolicyValue.IMPLICIT_ACTIVATION))
1221: {
1222: checkDiscarding();
1223:
1224: byte[] object_key = AOM.getFreeId();
1225:
1226: ServantDelegateImpl delegate = new ServantDelegateImpl(the_Servant,
1227: this, object_key);
1228: create_and_connect(object_key, the_Servant._all_interfaces(this,
1229: object_key)[0], delegate);
1230:
1231: return delegate.object;
1232: }
1233: else
1234: throw new ServantNotActive();
1235: }
1236:
1237:
1253: private Servant incarnate(AOM.Obj x, byte[] object_key,
1254: Servant a_servant, boolean use_forwarding
1255: )
1256: {
1257: if (servant_activator != null)
1258: {
1259: Servant servant;
1260: try
1261: {
1262: servant = servant_activator.incarnate(object_key, this);
1263: }
1264: catch (ForwardRequest ex)
1265: {
1266: if (use_forwarding)
1267: throw new gnuForwardRequest(ex.forward_reference);
1268: else
1269: servant =
1270: ForwardedServant.create((ObjectImpl) ex.forward_reference);
1271: }
1272: if (servant != null && x != null)
1273: x.setServant(servant);
1274: if (servant == null && x != null)
1275: servant = x.servant;
1276: return servant;
1277: }
1278: else if (a_servant != null)
1279: {
1280: x.setServant(a_servant);
1281: return a_servant;
1282: }
1283: else if (x.servant != null)
1284: {
1285: return x.servant;
1286: }
1287: else if (default_servant != null)
1288: {
1289: x.setServant(default_servant);
1290: return x.servant;
1291: }
1292: else
1293: throw new BAD_INV_ORDER("No servant given and the servant activator not set");
1294: }
1295:
1296:
1301: public POAManager the_POAManager()
1302: {
1303: return m_manager;
1304: }
1305:
1306:
1314: public AdapterActivator the_activator()
1315: {
1316: return m_activator;
1317: }
1318:
1319:
1324: public void the_activator(AdapterActivator an_activator)
1325: {
1326: m_activator = an_activator;
1327: }
1328:
1329:
1334: public POA[] the_children()
1335: {
1336: POA[] poas = new POA[ children.size() ];
1337: for (int i = 0; i < poas.length; i++)
1338: {
1339: poas [ i ] = (POA) children.get(i);
1340: }
1341: return poas;
1342: }
1343:
1344:
1349: public String the_name()
1350: {
1351: return name;
1352: }
1353:
1354:
1359: public POA the_parent()
1360: {
1361: return parent;
1362: }
1363:
1364:
1365: public IdAssignmentPolicy create_id_assignment_policy(IdAssignmentPolicyValue a_value)
1366: {
1367: return new gnuIdAssignmentPolicy(a_value);
1368: }
1369:
1370:
1371: public IdUniquenessPolicy create_id_uniqueness_policy(IdUniquenessPolicyValue a_value)
1372: {
1373: return new gnuIdUniquenessPolicy(a_value);
1374: }
1375:
1376:
1377: public ImplicitActivationPolicy create_implicit_activation_policy(ImplicitActivationPolicyValue a_value)
1378: {
1379: return new gnuImplicitActivationPolicy(a_value);
1380: }
1381:
1382:
1383: public LifespanPolicy create_lifespan_policy(LifespanPolicyValue a_value)
1384: {
1385: return new gnuLifespanPolicy(a_value);
1386: }
1387:
1388:
1389: public RequestProcessingPolicy create_request_processing_policy(RequestProcessingPolicyValue a_value)
1390: {
1391: return new gnuRequestProcessingPolicy(a_value);
1392: }
1393:
1394:
1395: public ServantRetentionPolicy create_servant_retention_policy(ServantRetentionPolicyValue a_value)
1396: {
1397: return new gnuServantRetentionPolicy(a_value);
1398: }
1399:
1400:
1401: public ThreadPolicy create_thread_policy(ThreadPolicyValue a_value)
1402: {
1403: return new gnuThreadPolicy(a_value);
1404: }
1405:
1406:
1430: public void destroy(boolean etherealize_objects, boolean wait_for_completion)
1431: {
1432:
1433: if (m_orb.iIor != null)
1434: m_orb.iIor.adapter_state_changed(
1435: new ObjectReferenceTemplate[] { getReferenceTemplate() },
1436: NON_EXISTENT.value);
1437:
1438: if (wait_for_completion)
1439: waitWhileRunning();
1440:
1441:
1442: if (m_manager instanceof gnuPOAManager)
1443: {
1444: ((gnuPOAManager) m_manager).poaDestroyed(this);
1445: }
1446:
1447:
1448:
1449: gnuPOAManager g = new gnuPOAManager();
1450: g.state = State.INACTIVE;
1451: m_manager = g;
1452:
1453:
1454: if (parent instanceof gnuPOA)
1455: {
1456: ((gnuPOA) parent).children.remove(this);
1457: }
1458:
1459: unregisterFromManager();
1460:
1461:
1462: ArrayList keys = new ArrayList();
1463: keys.addAll(aom.keySet());
1464:
1465: byte[] key;
1466: AOM.Obj obj;
1467: for (int i = 0; i < keys.size(); i++)
1468: {
1469: key = (byte[]) keys.get(i);
1470: obj = aom.get(key);
1471: if (obj.poa == this)
1472: m_orb.disconnect(obj.object);
1473: }
1474:
1475: m_orb.identityDestroyed(this);
1476:
1477: if (etherealize_objects && servant_activator != null && !m_inDestruction)
1478: {
1479: etherealizeAll();
1480: }
1481: m_inDestruction = true;
1482:
1483: POA[] ch = the_children();
1484: for (int i = 0; i < ch.length; i++)
1485: {
1486: ch[i].destroy(etherealize_objects, wait_for_completion);
1487: }
1488: }
1489:
1490:
1493: protected void finalize()
1494: throws java.lang.Throwable
1495: {
1496: if (!m_inDestruction)
1497: destroy(false, false);
1498: }
1499:
1500:
1503: private void unregisterFromManager()
1504: {
1505: if (m_manager instanceof gnuPOAManager)
1506: {
1507: gnuPOAManager p = (gnuPOAManager) m_manager;
1508: p.removePOA(this);
1509: }
1510: }
1511:
1512:
1521: public Policy _get_policy(int a_policy_type)
1522: throws org.omg.CORBA.BAD_PARAM
1523: {
1524: for (int i = 0; i < s_policies.length; i++)
1525: {
1526: if (s_policies [ i ].policy_type() == a_policy_type)
1527: return s_policies [ i ].copy();
1528: }
1529: throw new BAD_PARAM("No policy type " + a_policy_type);
1530: }
1531:
1532:
1535: public Policy[] getPolicyArray()
1536: {
1537: Policy[] r = new Policy[ s_policies.length ];
1538: for (int i = 0; i < s_policies.length; i++)
1539: {
1540: r [ i ] = s_policies [ i ].copy();
1541: }
1542: return r;
1543: }
1544:
1545:
1552: public org.omg.CORBA.Object _set_policy_override(Policy[] policies,
1553: SetOverrideType how
1554: )
1555: {
1556: throw new NO_IMPLEMENT("Use createPOA instead.");
1557: }
1558:
1559:
1562: public ORB orb()
1563: {
1564: return m_orb;
1565: }
1566:
1567:
1570: private void create_and_connect(byte[] object_key, String repository_id,
1571: ServantDelegateImpl delegate)
1572: {
1573: aom.add(delegate);
1574: connect_to_orb(object_key, getReferenceFactory().make_object(repository_id,
1575: object_key));
1576: if (servant_activator != null)
1577: incarnate(null, object_key, delegate.servant, false);
1578: }
1579:
1580:
1586: void checkDiscarding()
1587: throws TRANSIENT
1588: {
1589: if (m_manager.get_state() == State.DISCARDING)
1590: throw new TRANSIENT("Discarding mode", 1, CompletionStatus.COMPLETED_MAYBE);
1591: }
1592:
1593:
1596: protected void connect_to_orb(byte[] an_Object_Id, org.omg.CORBA.Object object)
1597: {
1598: if (applies(ThreadPolicyValue.SINGLE_THREAD_MODEL))
1599: m_orb.connect_1_thread(object, toIORKey(an_Object_Id), this);
1600: else
1601: m_orb.connect(object, toIORKey(an_Object_Id));
1602: }
1603:
1604:
1607: public String toString()
1608: {
1609: CPStringBuilder b = new CPStringBuilder(name);
1610:
1611: if (children.size() != 0)
1612: {
1613: b.append(" (");
1614:
1615: for (int i = 0; i < children.size(); i++)
1616: {
1617: b.append(children.get(i));
1618: if (i < children.size() - 2)
1619: b.append(", ");
1620: }
1621: b.append(")");
1622: }
1623: return b.toString();
1624: }
1625:
1626:
1629: protected boolean validatePolicies(Policy[] a)
1630: throws InvalidPolicy
1631: {
1632: if (applies(ServantRetentionPolicyValue.NON_RETAIN))
1633: {
1634: if (!applies(RequestProcessingPolicyValue.USE_DEFAULT_SERVANT) &&
1635: !applies(RequestProcessingPolicyValue.USE_SERVANT_MANAGER)
1636: )
1637: {
1638: short p = 0;
1639: for (short i = 0; i < a.length; i++)
1640: {
1641: if (a [ i ].policy_type() == SERVANT_RETENTION_POLICY_ID.value)
1642: p = i;
1643: }
1644: throw new InvalidPolicy("NON_RETAIN requires either " +
1645: "USE_DEFAULT_SERVANT or USE_SERVANT_MANAGER",
1646: p
1647: );
1648: }
1649: }
1650: return true;
1651: }
1652:
1653:
1656: public AOM.Obj findObject(org.omg.CORBA.Object object)
1657: {
1658: AOM.Obj h = aom.findObject(object);
1659: if (h != null)
1660: return h;
1661: else
1662: {
1663: for (int i = 0; i < children.size(); i++)
1664: {
1665: h = ((gnuPOA) children.get(i)).findObject(object);
1666: if (h != null)
1667: return h;
1668: }
1669: }
1670: return h;
1671: }
1672:
1673:
1679: public AOM.Obj findKey(byte[] object_id, byte[] poa_id)
1680: {
1681: AOM.Obj h = null;
1682: if (Arrays.equals(poa_id, id()))
1683: h = aom.get(object_id);
1684: if (h != null)
1685: return h;
1686: else
1687: {
1688: for (int i = 0; i < children.size(); i++)
1689: {
1690: h = ((gnuPOA) children.get(i)).findKey(object_id, poa_id);
1691: if (h != null)
1692: return h;
1693: }
1694: }
1695: return h;
1696: }
1697:
1698:
1702: public AOM.Obj findIorKey(byte[] ior_key)
1703: {
1704: BufferredCdrInput in = new BufferredCdrInput(ior_key);
1705: int signature = in.read_long();
1706: if (signature != SIGNATURE)
1707: return null;
1708:
1709: byte[] id = in.read_sequence();
1710: byte[] poa = in.read_sequence();
1711: return findKey(id, poa);
1712: }
1713:
1714:
1719: public byte[] toIORKey(byte[] object_id)
1720: {
1721: BufferedCdrOutput buffer = new BufferedCdrOutput();
1722: buffer.write_long(SIGNATURE);
1723: buffer.write_sequence(object_id);
1724: buffer.write_sequence(id());
1725: return buffer.buffer.toByteArray();
1726: }
1727:
1728:
1737: public byte[] idFormIor(byte[] ior_key)
1738: {
1739: BufferredCdrInput in = new BufferredCdrInput(ior_key);
1740: int signature = in.read_long();
1741: if (signature != SIGNATURE)
1742: return null;
1743:
1744: byte[] object_id = in.read_sequence();
1745: byte[] poa_id = in.read_sequence();
1746: if (Arrays.equals(poa_id, id()))
1747: return object_id;
1748: else
1749: return null;
1750: }
1751:
1752:
1755: public AOM.Obj findServant(Servant servant)
1756: {
1757: AOM.Obj h = aom.findServant(servant);
1758: if (h != null)
1759: return h;
1760: else
1761: {
1762: for (int i = 0; i < children.size(); i++)
1763: {
1764: h = ((gnuPOA) children.get(i)).findServant(servant);
1765: if (h != null)
1766: return h;
1767: }
1768: }
1769: return h;
1770: }
1771:
1772:
1776: public ObjectReferenceTemplate getReferenceTemplate()
1777: {
1778: if (refTemplate == null)
1779: refTemplate = new RefTemplate();
1780:
1781: return refTemplate;
1782: }
1783:
1784: public ObjectReferenceFactory getReferenceFactory()
1785: {
1786: return m_object_factory;
1787: }
1788:
1789: public void setReferenceFactory(ObjectReferenceFactory factory)
1790: {
1791: m_object_factory = factory;
1792: }
1793:
1794:
1797: public Object make_object(String a_repository_id, byte[] an_object_id)
1798: {
1799: AOM.Obj existing = aom.get(an_object_id);
1800:
1801: if (existing != null && existing.object != null)
1802: return existing.object;
1803: else
1804: {
1805: return new gnuServantObject(new String[] { a_repository_id },
1806: an_object_id, this, m_orb);
1807: }
1808: }
1809:
1810:
1813: public String[] _truncatable_ids()
1814: {
1815: return ref_template_ids;
1816: }
1817: }