1:
37:
38:
39: package ;
40:
41: import ;
42: import ;
43: import ;
44:
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: 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:
96: import ;
97: import ;
98: import ;
99:
100:
105: public class gnuPOA
106: extends LocalObject
107: implements POA, ObjectReferenceFactory
108: {
109:
114: class RefTemplate implements ObjectReferenceTemplate
115: {
116:
119: private static final long serialVersionUID = 1;
120:
121: RefTemplate()
122: {
123:
124: ArrayList names = new ArrayList();
125: names.add(the_name());
126:
127: POA poa = the_parent();
128: while (poa != null)
129: {
130: names.add(poa.the_name());
131: poa = poa.the_parent();
132: }
133:
134:
135:
136: m_adapter_name = new String[names.size()];
137:
138: for (int i = 0; i < m_adapter_name.length; i++)
139: m_adapter_name[i] = (String) names.get(m_adapter_name.length - i - 1);
140: }
141:
142:
145: final String[] m_adapter_name;
146:
147:
150: public String[] adapter_name()
151: {
152: return (String[]) m_adapter_name.clone();
153: }
154:
155:
158: public String orb_id()
159: {
160: return m_orb.orb_id;
161: }
162:
163:
166: public String server_id()
167: {
168: return OrbFunctional.server_id;
169: }
170:
171:
174: public Object make_object(String repositoryId, byte[] objectId)
175: {
176: return create_reference_with_id(objectId, repositoryId);
177: }
178:
179:
182: public String[] _truncatable_ids()
183: {
184: return ref_template_ids;
185: }
186: }
187:
188:
191: private static final long serialVersionUID = 1;
192:
193:
196: ObjectReferenceTemplate refTemplate;
197:
198:
202: final static String[] ref_template_ids =
203: new String[] { ObjectReferenceTemplateHelper.id() };
204:
205:
208: public final AOM aom = new AOM();
209:
210:
213: final ArrayList children = new ArrayList();
214:
215:
218: final String name;
219:
220:
223: final POA parent;
224:
225:
229: static final int SIGNATURE = 0x66726565;
230:
231:
234: AdapterActivator m_activator;
235:
236:
239: POAManager m_manager;
240:
241:
244: ServantActivator servant_activator;
245:
246:
249: ServantLocator servant_locator;
250:
251:
254: Servant default_servant;
255:
256:
259: private byte[] m_poa_id;
260:
261:
265: private final HashSet m_policies;
266:
267:
270: Policy[] s_policies;
271:
272:
275: final ORB_1_4 m_orb;
276:
277:
280: boolean m_inDestruction;
281:
282:
287: public final boolean retain_servant;
288:
289:
293: ObjectReferenceFactory m_object_factory = this;
294:
295:
305: public gnuPOA(gnuPOA a_parent, String a_name, POAManager a_manager,
306: Policy[] a_policies, ORB_1_4 an_orb
307: )
308: throws InvalidPolicy
309: {
310:
311: Policy[] all_policies = StandardPolicies.withDefault(a_policies);
312:
313: name = a_name;
314: parent = a_parent;
315: m_orb = an_orb;
316:
317: if (a_manager != null)
318: m_manager = a_manager;
319: else
320: m_manager = new gnuPOAManager();
321:
322: if (m_manager instanceof gnuPOAManager)
323: {
324: gnuPOAManager g = (gnuPOAManager) m_manager;
325: g.addPoa(this);
326: }
327:
328: m_policies = new HashSet(all_policies.length);
329:
330: s_policies = new Policy[ all_policies.length ];
331: for (int i = 0; i < s_policies.length; i++)
332: {
333: s_policies [ i ] = all_policies [ i ].copy();
334: m_policies.add(((AccessiblePolicy) s_policies [ i ]).getValue());
335: }
336:
337: retain_servant = applies(ServantRetentionPolicyValue.RETAIN);
338:
339: validatePolicies(a_policies);
340:
341: refTemplate = new RefTemplate();
342: }
343:
344:
348: public void waitWhileRunning()
349: {
350:
351: long time = 1;
352:
353:
354: long max = 500;
355:
356: boolean runs;
357:
358: do
359: {
360: runs = m_orb.currents.has(this);
361:
362: if (runs)
363: {
364:
365:
366: try
367: {
368: Thread.sleep(time);
369: time = time * 2;
370: if (time > max)
371: time = max;
372: }
373: catch (InterruptedException ex)
374: {
375: }
376: }
377: }
378: while (runs);
379: }
380:
381:
386: protected void etherealizeAll()
387: {
388: if (servant_activator == null)
389: return;
390:
391: ArrayList keys = new ArrayList();
392: keys.addAll(aom.keySet());
393:
394: byte[] key;
395: AOM.Obj obj;
396: boolean last;
397: for (int i = 0; i < keys.size(); i++)
398: {
399: key = (byte[]) keys.get(i);
400: obj = aom.get(key);
401:
402: if (obj.poa == this)
403: {
404: aom.remove(key);
405:
406: if (!obj.isDeactiveted())
407: {
408:
409: last = aom.findServant(obj.servant) == null;
410: servant_activator.etherealize(obj.key, this, obj.servant, true,
411: last
412: );
413: }
414: }
415: }
416: }
417:
418:
432: protected POA createPoaInstance(String child_name, POAManager a_manager,
433: Policy[] policies, ORB_1_4 an_orb
434: )
435: throws InvalidPolicy
436: {
437: POAManager some_manager =
438: a_manager == null ? new gnuPOAManager() : a_manager;
439:
440: if (some_manager instanceof gnuPOAManager)
441: {
442: ((gnuPOAManager) some_manager).addPoa(this);
443: }
444:
445: return new gnuPOA(this, child_name, some_manager, policies, an_orb);
446: }
447:
448:
457: public final boolean applies(java.lang.Object policy_value)
458: {
459: return m_policies.contains(policy_value);
460: }
461:
462:
469: public final void required(java.lang.Object policy_value)
470: throws WrongPolicy
471: {
472: if (!applies(policy_value))
473: throw new WrongPolicy(policy_value + " policy required.");
474: }
475:
476:
483: public final void excluding(java.lang.Object policy_value)
484: throws WrongPolicy
485: {
486: if (applies(policy_value))
487: throw new WrongPolicy(policy_value + " policy applies.");
488: }
489:
490:
505: public POA find_POA(String poa_name, boolean activate_it)
506: throws AdapterNonExistent
507: {
508: POA child;
509: for (int i = 0; i < children.size(); i++)
510: {
511: child = (POA) children.get(i);
512: if (child.the_name().equals(poa_name))
513: return child;
514: }
515:
516: if (activate_it && m_activator != null)
517: {
518: boolean activated = m_activator.unknown_adapter(this, poa_name);
519: if (!activated)
520: throw new AdapterNonExistent(poa_name + " activation failed.");
521:
522:
523: for (int i = 0; i < children.size(); i++)
524: {
525: child = (POA) children.get(i);
526: if (child.the_name().equals(poa_name))
527: return child;
528: }
529: throw new AdapterNonExistent(poa_name + " not created. ");
530: }
531: else
532: throw new AdapterNonExistent(poa_name);
533: }
534:
535:
552: public byte[] activate_object(Servant a_servant)
553: throws ServantAlreadyActive, WrongPolicy
554: {
555: checkDiscarding();
556: required(ServantRetentionPolicyValue.RETAIN);
557: required(IdAssignmentPolicyValue.SYSTEM_ID);
558:
559: AOM.Obj exists = aom.findServant(a_servant);
560:
561: if (exists != null)
562: {
563: if (exists.isDeactiveted())
564: {
565:
566:
567: exists.setDeactivated(false);
568: incarnate(exists, exists.key, a_servant, false);
569: return exists.key;
570: }
571: else if (applies(IdUniquenessPolicyValue.UNIQUE_ID))
572: throw new ServantAlreadyActive();
573:
574:
575:
576: }
577:
578: byte[] object_key = AOM.getFreeId();
579: ServantDelegateImpl delegate = new ServantDelegateImpl(a_servant, this,
580: object_key);
581: create_and_connect(object_key,
582: a_servant._all_interfaces(this, object_key)[0], delegate);
583: return object_key;
584: }
585:
586:
604: public void activate_object_with_id(byte[] an_Object_Id, Servant a_servant)
605: throws ServantAlreadyActive, ObjectAlreadyActive,
606: WrongPolicy
607: {
608: activate_object_with_id(an_Object_Id, a_servant, false);
609: }
610:
611:
617: public void activate_object_with_id(byte[] an_Object_Id, Servant a_servant,
618: boolean use_forwarding)
619: throws ServantAlreadyActive, ObjectAlreadyActive, WrongPolicy
620: {
621: checkDiscarding();
622: required(ServantRetentionPolicyValue.RETAIN);
623:
624:
625:
626: if (applies(IdUniquenessPolicyValue.UNIQUE_ID))
627: {
628: AOM.Obj sx = aom.findServant(a_servant, false);
629: if (sx != null)
630: throw new ServantAlreadyActive();
631: }
632:
633: AOM.Obj exists = aom.get(an_Object_Id);
634: if (exists != null)
635: {
636: if (exists.servant == null)
637: {
638: locateServant(an_Object_Id, a_servant, exists, use_forwarding);
639: exists.setDeactivated(false);
640: }
641: else if (exists.isDeactiveted())
642: {
643: exists.setDeactivated(false);
644: incarnate(exists, an_Object_Id, a_servant, use_forwarding);
645: }
646: else
647: throw new ObjectAlreadyActive();
648: }
649: else
650: {
651: ServantDelegateImpl delegate = new ServantDelegateImpl(a_servant, this,
652: an_Object_Id);
653: create_and_connect(an_Object_Id, a_servant._all_interfaces(this,
654: an_Object_Id)[0], delegate);
655: }
656: }
657:
658:
670: private void locateServant(byte[] an_Object_Id, Servant a_servant,
671: AOM.Obj exists, boolean use_forwarding
672: )
673: throws InternalError
674: {
675:
676: gnuServantObject object = (gnuServantObject) exists.object;
677: if (servant_activator != null)
678: {
679: exists.setServant(incarnate(exists, an_Object_Id, a_servant,
680: use_forwarding
681: )
682: );
683: }
684: else if (default_servant != null)
685: {
686: exists.setServant(default_servant);
687: }
688: if (exists.servant == null)
689: {
690: exists.setServant(a_servant);
691: }
692: if (exists.servant == null)
693: {
694: throw new OBJ_ADAPTER("no servant", 4, CompletionStatus.COMPLETED_NO);
695: }
696:
697: ServantDelegateImpl delegate =
698: new ServantDelegateImpl(exists.servant, this, an_Object_Id);
699: exists.servant._set_delegate(delegate);
700: object.setServant(exists.servant);
701: connect_to_orb(an_Object_Id, delegate.object);
702: }
703:
704:
715: public void deactivate_object(byte[] the_Object_Id)
716: throws ObjectNotActive, WrongPolicy
717: {
718: required(ServantRetentionPolicyValue.RETAIN);
719:
720: AOM.Obj exists = aom.get(the_Object_Id);
721:
722: if (exists == null || exists.isDeactiveted())
723: throw new ObjectNotActive();
724:
725: exists.setDeactivated(true);
726:
727:
728: aom.remove(the_Object_Id);
729:
730: AOM.Obj other = aom.findServant(exists.servant, false);
731:
732: boolean remaining = other != null;
733:
734: aom.put(exists);
735:
736: if (servant_activator != null)
737: servant_activator.etherealize(the_Object_Id, this, exists.servant, false,
738: remaining
739: );
740: }
741:
742:
754: public org.omg.CORBA.Object create_reference(String a_repository_id)
755: throws WrongPolicy
756: {
757: required(IdAssignmentPolicyValue.SYSTEM_ID);
758: return create_reference_with_id(AOM.getFreeId(), a_repository_id);
759: }
760:
761:
776: public org.omg.CORBA.Object create_reference_with_id(byte[] an_object_id,
777: String a_repository_id
778: )
779: {
780: String[] ids;
781: if (a_repository_id == null)
782: ids = null;
783: else
784: ids = new String[] { a_repository_id };
785:
786:
787: AOM.Obj e = aom.get(an_object_id);
788:
789: Servant servant;
790: if (e == null)
791: {
792: servant = null;
793: }
794: else
795: {
796: servant = e.servant;
797: e.setDeactivated(false);
798: }
799:
800: gnuServantObject object =
801: new gnuServantObject(ids, an_object_id, this, m_orb);
802: object._set_delegate(new LocalDelegate(object, this, an_object_id));
803: aom.add(object.Id, object, servant, this);
804: connect_to_orb(an_object_id, object);
805:
806: return object;
807: }
808:
809:
829: public POA create_POA(String child_name, POAManager manager, Policy[] policies)
830: throws AdapterAlreadyExists, InvalidPolicy
831: {
832: POA child;
833: for (int i = 0; i < children.size(); i++)
834: {
835: child = (POA) children.get(i);
836: if (child.the_name().equals(child_name))
837: throw new AdapterAlreadyExists(name + "/" + child_name);
838: }
839:
840: POA poa = createPoaInstance(child_name, manager, policies, m_orb);
841: children.add(poa);
842: return poa;
843: }
844:
845:
854: public Servant get_servant()
855: throws NoServant, WrongPolicy
856: {
857: required(RequestProcessingPolicyValue.USE_DEFAULT_SERVANT);
858: if (default_servant == null)
859: throw new NoServant();
860: return default_servant;
861: }
862:
863:
871: public void set_servant(Servant a_servant)
872: throws WrongPolicy
873: {
874: required(RequestProcessingPolicyValue.USE_DEFAULT_SERVANT);
875: default_servant = a_servant;
876: }
877:
878:
897: public void set_servant_manager(ServantManager a_manager)
898: throws WrongPolicy
899: {
900: required(RequestProcessingPolicyValue.USE_SERVANT_MANAGER);
901: if (servant_activator != null || servant_locator != null)
902: throw new BAD_INV_ORDER("Setting manager twice for " + name, 6,
903: CompletionStatus.COMPLETED_NO
904: );
905:
906: if (applies(ServantRetentionPolicyValue.RETAIN))
907: {
908: if (a_manager instanceof ServantActivator)
909: servant_activator = (ServantActivator) a_manager;
910: else
911: throw new OBJ_ADAPTER("RETAIN requires ServantActivator", 4,
912: CompletionStatus.COMPLETED_NO
913: );
914: }
915: else if (applies(ServantRetentionPolicyValue.NON_RETAIN))
916: {
917: if (a_manager instanceof ServantLocator)
918: servant_locator = (ServantLocator) a_manager;
919: else
920: throw new OBJ_ADAPTER("NON_RETAIN requires ServantLocator", 4,
921: CompletionStatus.COMPLETED_NO
922: );
923: }
924: else
925: throw new WrongPolicy("No servant retention policy is specified.");
926: }
927:
928:
937: public ServantManager get_servant_manager()
938: throws WrongPolicy
939: {
940: required(RequestProcessingPolicyValue.USE_SERVANT_MANAGER);
941:
942: if (servant_activator != null)
943: return servant_activator;
944: else
945: return servant_locator;
946: }
947:
948:
956: public byte[] id()
957: {
958: if (m_poa_id != null)
959: return m_poa_id;
960: else
961: {
962: BufferedCdrOutput buffer = new BufferedCdrOutput();
963: POA p = this;
964: while (p != null)
965: {
966: buffer.write_string(p.the_name());
967: p = p.the_parent();
968: }
969: m_poa_id = buffer.buffer.toByteArray();
970: return m_poa_id;
971: }
972: }
973:
974:
984: public org.omg.CORBA.Object id_to_reference(byte[] the_Object_Id)
985: throws ObjectNotActive, WrongPolicy
986: {
987: required(ServantRetentionPolicyValue.RETAIN);
988:
989: AOM.Obj ref = aom.get(the_Object_Id);
990: if (ref == null)
991: throw new ObjectNotActive();
992: else
993: return ref.object;
994: }
995:
996:
1007: public Servant id_to_servant(byte[] the_Object_Id)
1008: throws ObjectNotActive, WrongPolicy
1009: {
1010: if (applies(ServantRetentionPolicyValue.RETAIN))
1011: {
1012: AOM.Obj ref = aom.get(the_Object_Id);
1013: if (ref == null || ref.isDeactiveted())
1014: {
1015: if (default_servant != null)
1016: return default_servant;
1017: else
1018: throw new ObjectNotActive();
1019: }
1020: else if (ref.servant != null)
1021: return ref.servant;
1022: else if (default_servant != null)
1023: return default_servant;
1024: else
1025: throw new ObjectNotActive();
1026: }
1027: else if (default_servant != null)
1028: {
1029: return default_servant;
1030: }
1031: else
1032: throw new WrongPolicy("Either RETAIN or USE_DEFAULT_SERVANT required.");
1033: }
1034:
1035:
1044: public byte[] reference_to_id(org.omg.CORBA.Object the_Object)
1045: throws WrongAdapter, WrongPolicy
1046: {
1047: AOM.Obj ref = aom.findObject(the_Object);
1048: if (ref == null)
1049: throw new WrongAdapter();
1050: return ref.key;
1051: }
1052:
1053:
1067: public Servant reference_to_servant(org.omg.CORBA.Object the_Object)
1068: throws ObjectNotActive, WrongPolicy, WrongAdapter
1069: {
1070: if (applies(ServantRetentionPolicyValue.RETAIN))
1071: {
1072: AOM.Obj ref = aom.findObject(the_Object);
1073: if (ref == null)
1074: {
1075: String object;
1076: if (the_Object == null)
1077: object = "null passed";
1078: else if (the_Object instanceof gnuServantObject)
1079: {
1080: gnuServantObject gs = (gnuServantObject) the_Object;
1081: object = "Wrong owner POA " + gs.poa.the_name();
1082: }
1083: else
1084: object = "Unknown " + the_Object.getClass().getName();
1085:
1086: throw new WrongAdapter(object + " for '" + the_name() + "'");
1087: }
1088: else if (ref.isDeactiveted() || ref.servant == null)
1089: {
1090: if (default_servant != null)
1091: return default_servant;
1092: else
1093: throw new ObjectNotActive();
1094: }
1095: else
1096: return ref.servant;
1097: }
1098: else if (default_servant != null)
1099: {
1100: return default_servant;
1101: }
1102: else
1103: throw new WrongPolicy("Either RETAIN or USE_DEFAULT_SERVANT required.");
1104: }
1105:
1106:
1131: public byte[] servant_to_id(Servant the_Servant)
1132: throws ServantNotActive, WrongPolicy
1133: {
1134: if (applies(RequestProcessingPolicyValue.USE_DEFAULT_SERVANT) ||
1135: applies(ServantRetentionPolicyValue.RETAIN) &&
1136: (
1137: applies(IdUniquenessPolicyValue.UNIQUE_ID) ||
1138: applies(ImplicitActivationPolicyValue.IMPLICIT_ACTIVATION)
1139: )
1140: )
1141: {
1142: AOM.Obj ref = null;
1143: if (!applies(IdUniquenessPolicyValue.MULTIPLE_ID))
1144: ref = aom.findServant(the_Servant);
1145: if (ref == null &&
1146: applies(ImplicitActivationPolicyValue.IMPLICIT_ACTIVATION)
1147: )
1148: {
1149:
1150: try
1151: {
1152: return activate_object(the_Servant);
1153: }
1154: catch (ServantAlreadyActive ex)
1155: {
1156:
1157: throw new InternalError();
1158: }
1159: }
1160: if (ref == null)
1161: throw new ServantNotActive();
1162: else
1163: return ref.key;
1164: }
1165: else
1166: throw new WrongPolicy("(RETAIN and UNIQUE ID) " +
1167: "or USE_DEFAULT_SERVANT required."
1168: );
1169: }
1170:
1171:
1191: public org.omg.CORBA.Object servant_to_reference(Servant the_Servant)
1192: throws ServantNotActive, WrongPolicy
1193: {
1194: required(ServantRetentionPolicyValue.RETAIN);
1195:
1196: AOM.Obj exists = null;
1197:
1198: if (!applies(IdUniquenessPolicyValue.MULTIPLE_ID))
1199: exists = aom.findServant(the_Servant);
1200:
1201: if (exists != null)
1202: {
1203: if (exists.isDeactiveted())
1204: {
1205: if (applies(ImplicitActivationPolicyValue.IMPLICIT_ACTIVATION))
1206: {
1207: checkDiscarding();
1208: exists.setDeactivated(false);
1209: incarnate(exists, exists.key, the_Servant, false);
1210: }
1211: else
1212: throw new ServantNotActive();
1213: }
1214: else
1215: return exists.object;
1216: }
1217: if (exists == null
1218: && applies(ImplicitActivationPolicyValue.IMPLICIT_ACTIVATION))
1219: {
1220: checkDiscarding();
1221:
1222: byte[] object_key = AOM.getFreeId();
1223:
1224: ServantDelegateImpl delegate = new ServantDelegateImpl(the_Servant,
1225: this, object_key);
1226: create_and_connect(object_key, the_Servant._all_interfaces(this,
1227: object_key)[0], delegate);
1228:
1229: return delegate.object;
1230: }
1231: else
1232: throw new ServantNotActive();
1233: }
1234:
1235:
1251: private Servant incarnate(AOM.Obj x, byte[] object_key,
1252: Servant a_servant, boolean use_forwarding
1253: )
1254: {
1255: if (servant_activator != null)
1256: {
1257: Servant servant;
1258: try
1259: {
1260: servant = servant_activator.incarnate(object_key, this);
1261: }
1262: catch (ForwardRequest ex)
1263: {
1264: if (use_forwarding)
1265: throw new gnuForwardRequest(ex.forward_reference);
1266: else
1267: servant =
1268: ForwardedServant.create((ObjectImpl) ex.forward_reference);
1269: }
1270: if (servant != null && x != null)
1271: x.setServant(servant);
1272: if (servant == null && x != null)
1273: servant = x.servant;
1274: return servant;
1275: }
1276: else if (a_servant != null)
1277: {
1278: x.setServant(a_servant);
1279: return a_servant;
1280: }
1281: else if (x.servant != null)
1282: {
1283: return x.servant;
1284: }
1285: else if (default_servant != null)
1286: {
1287: x.setServant(default_servant);
1288: return x.servant;
1289: }
1290: else
1291: throw new BAD_INV_ORDER("No servant given and the servant activator not set");
1292: }
1293:
1294:
1299: public POAManager the_POAManager()
1300: {
1301: return m_manager;
1302: }
1303:
1304:
1312: public AdapterActivator the_activator()
1313: {
1314: return m_activator;
1315: }
1316:
1317:
1322: public void the_activator(AdapterActivator an_activator)
1323: {
1324: m_activator = an_activator;
1325: }
1326:
1327:
1332: public POA[] the_children()
1333: {
1334: POA[] poas = new POA[ children.size() ];
1335: for (int i = 0; i < poas.length; i++)
1336: {
1337: poas [ i ] = (POA) children.get(i);
1338: }
1339: return poas;
1340: }
1341:
1342:
1347: public String the_name()
1348: {
1349: return name;
1350: }
1351:
1352:
1357: public POA the_parent()
1358: {
1359: return parent;
1360: }
1361:
1362:
1363: public IdAssignmentPolicy create_id_assignment_policy(IdAssignmentPolicyValue a_value)
1364: {
1365: return new gnuIdAssignmentPolicy(a_value);
1366: }
1367:
1368:
1369: public IdUniquenessPolicy create_id_uniqueness_policy(IdUniquenessPolicyValue a_value)
1370: {
1371: return new gnuIdUniquenessPolicy(a_value);
1372: }
1373:
1374:
1375: public ImplicitActivationPolicy create_implicit_activation_policy(ImplicitActivationPolicyValue a_value)
1376: {
1377: return new gnuImplicitActivationPolicy(a_value);
1378: }
1379:
1380:
1381: public LifespanPolicy create_lifespan_policy(LifespanPolicyValue a_value)
1382: {
1383: return new gnuLifespanPolicy(a_value);
1384: }
1385:
1386:
1387: public RequestProcessingPolicy create_request_processing_policy(RequestProcessingPolicyValue a_value)
1388: {
1389: return new gnuRequestProcessingPolicy(a_value);
1390: }
1391:
1392:
1393: public ServantRetentionPolicy create_servant_retention_policy(ServantRetentionPolicyValue a_value)
1394: {
1395: return new gnuServantRetentionPolicy(a_value);
1396: }
1397:
1398:
1399: public ThreadPolicy create_thread_policy(ThreadPolicyValue a_value)
1400: {
1401: return new gnuThreadPolicy(a_value);
1402: }
1403:
1404:
1428: public void destroy(boolean etherealize_objects, boolean wait_for_completion)
1429: {
1430:
1431: if (m_orb.iIor != null)
1432: m_orb.iIor.adapter_state_changed(
1433: new ObjectReferenceTemplate[] { getReferenceTemplate() },
1434: NON_EXISTENT.value);
1435:
1436: if (wait_for_completion)
1437: waitWhileRunning();
1438:
1439:
1440: if (m_manager instanceof gnuPOAManager)
1441: {
1442: ((gnuPOAManager) m_manager).poaDestroyed(this);
1443: }
1444:
1445:
1446:
1447: gnuPOAManager g = new gnuPOAManager();
1448: g.state = State.INACTIVE;
1449: m_manager = g;
1450:
1451:
1452: if (parent instanceof gnuPOA)
1453: {
1454: ((gnuPOA) parent).children.remove(this);
1455: }
1456:
1457: unregisterFromManager();
1458:
1459:
1460: ArrayList keys = new ArrayList();
1461: keys.addAll(aom.keySet());
1462:
1463: byte[] key;
1464: AOM.Obj obj;
1465: for (int i = 0; i < keys.size(); i++)
1466: {
1467: key = (byte[]) keys.get(i);
1468: obj = aom.get(key);
1469: if (obj.poa == this)
1470: m_orb.disconnect(obj.object);
1471: }
1472:
1473: m_orb.identityDestroyed(this);
1474:
1475: if (etherealize_objects && servant_activator != null && !m_inDestruction)
1476: {
1477: etherealizeAll();
1478: }
1479: m_inDestruction = true;
1480:
1481: POA[] ch = the_children();
1482: for (int i = 0; i < ch.length; i++)
1483: {
1484: ch[i].destroy(etherealize_objects, wait_for_completion);
1485: }
1486: }
1487:
1488:
1491: protected void finalize()
1492: throws java.lang.Throwable
1493: {
1494: if (!m_inDestruction)
1495: destroy(false, false);
1496: }
1497:
1498:
1501: private void unregisterFromManager()
1502: {
1503: if (m_manager instanceof gnuPOAManager)
1504: {
1505: gnuPOAManager p = (gnuPOAManager) m_manager;
1506: p.removePOA(this);
1507: }
1508: }
1509:
1510:
1519: public Policy _get_policy(int a_policy_type)
1520: throws org.omg.CORBA.BAD_PARAM
1521: {
1522: for (int i = 0; i < s_policies.length; i++)
1523: {
1524: if (s_policies [ i ].policy_type() == a_policy_type)
1525: return s_policies [ i ].copy();
1526: }
1527: throw new BAD_PARAM("No policy type " + a_policy_type);
1528: }
1529:
1530:
1533: public Policy[] getPolicyArray()
1534: {
1535: Policy[] r = new Policy[ s_policies.length ];
1536: for (int i = 0; i < s_policies.length; i++)
1537: {
1538: r [ i ] = s_policies [ i ].copy();
1539: }
1540: return r;
1541: }
1542:
1543:
1550: public org.omg.CORBA.Object _set_policy_override(Policy[] policies,
1551: SetOverrideType how
1552: )
1553: {
1554: throw new NO_IMPLEMENT("Use createPOA instead.");
1555: }
1556:
1557:
1560: public ORB orb()
1561: {
1562: return m_orb;
1563: }
1564:
1565:
1568: private void create_and_connect(byte[] object_key, String repository_id,
1569: ServantDelegateImpl delegate)
1570: {
1571: aom.add(delegate);
1572: connect_to_orb(object_key, getReferenceFactory().make_object(repository_id,
1573: object_key));
1574: if (servant_activator != null)
1575: incarnate(null, object_key, delegate.servant, false);
1576: }
1577:
1578:
1584: void checkDiscarding()
1585: throws TRANSIENT
1586: {
1587: if (m_manager.get_state() == State.DISCARDING)
1588: throw new TRANSIENT("Discarding mode", 1, CompletionStatus.COMPLETED_MAYBE);
1589: }
1590:
1591:
1594: protected void connect_to_orb(byte[] an_Object_Id, org.omg.CORBA.Object object)
1595: {
1596: if (applies(ThreadPolicyValue.SINGLE_THREAD_MODEL))
1597: m_orb.connect_1_thread(object, toIORKey(an_Object_Id), this);
1598: else
1599: m_orb.connect(object, toIORKey(an_Object_Id));
1600: }
1601:
1602:
1605: public String toString()
1606: {
1607: StringBuffer b = new StringBuffer(name);
1608:
1609: if (children.size() != 0)
1610: {
1611: b.append(" (");
1612:
1613: for (int i = 0; i < children.size(); i++)
1614: {
1615: b.append(children.get(i));
1616: if (i < children.size() - 2)
1617: b.append(", ");
1618: }
1619: b.append(")");
1620: }
1621: return b.toString();
1622: }
1623:
1624:
1627: protected boolean validatePolicies(Policy[] a)
1628: throws InvalidPolicy
1629: {
1630: if (applies(ServantRetentionPolicyValue.NON_RETAIN))
1631: {
1632: if (!applies(RequestProcessingPolicyValue.USE_DEFAULT_SERVANT) &&
1633: !applies(RequestProcessingPolicyValue.USE_SERVANT_MANAGER)
1634: )
1635: {
1636: short p = 0;
1637: for (short i = 0; i < a.length; i++)
1638: {
1639: if (a [ i ].policy_type() == SERVANT_RETENTION_POLICY_ID.value)
1640: p = i;
1641: }
1642: throw new InvalidPolicy("NON_RETAIN requires either " +
1643: "USE_DEFAULT_SERVANT or USE_SERVANT_MANAGER",
1644: p
1645: );
1646: }
1647: }
1648: return true;
1649: }
1650:
1651:
1654: public AOM.Obj findObject(org.omg.CORBA.Object object)
1655: {
1656: AOM.Obj h = aom.findObject(object);
1657: if (h != null)
1658: return h;
1659: else
1660: {
1661: for (int i = 0; i < children.size(); i++)
1662: {
1663: h = ((gnuPOA) children.get(i)).findObject(object);
1664: if (h != null)
1665: return h;
1666: }
1667: }
1668: return h;
1669: }
1670:
1671:
1677: public AOM.Obj findKey(byte[] object_id, byte[] poa_id)
1678: {
1679: AOM.Obj h = null;
1680: if (Arrays.equals(poa_id, id()))
1681: h = aom.get(object_id);
1682: if (h != null)
1683: return h;
1684: else
1685: {
1686: for (int i = 0; i < children.size(); i++)
1687: {
1688: h = ((gnuPOA) children.get(i)).findKey(object_id, poa_id);
1689: if (h != null)
1690: return h;
1691: }
1692: }
1693: return h;
1694: }
1695:
1696:
1700: public AOM.Obj findIorKey(byte[] ior_key)
1701: {
1702: BufferredCdrInput in = new BufferredCdrInput(ior_key);
1703: int signature = in.read_long();
1704: if (signature != SIGNATURE)
1705: return null;
1706:
1707: byte[] id = in.read_sequence();
1708: byte[] poa = in.read_sequence();
1709: return findKey(id, poa);
1710: }
1711:
1712:
1717: public byte[] toIORKey(byte[] object_id)
1718: {
1719: BufferedCdrOutput buffer = new BufferedCdrOutput();
1720: buffer.write_long(SIGNATURE);
1721: buffer.write_sequence(object_id);
1722: buffer.write_sequence(id());
1723: return buffer.buffer.toByteArray();
1724: }
1725:
1726:
1735: public byte[] idFormIor(byte[] ior_key)
1736: {
1737: BufferredCdrInput in = new BufferredCdrInput(ior_key);
1738: int signature = in.read_long();
1739: if (signature != SIGNATURE)
1740: return null;
1741:
1742: byte[] object_id = in.read_sequence();
1743: byte[] poa_id = in.read_sequence();
1744: if (Arrays.equals(poa_id, id()))
1745: return object_id;
1746: else
1747: return null;
1748: }
1749:
1750:
1753: public AOM.Obj findServant(Servant servant)
1754: {
1755: AOM.Obj h = aom.findServant(servant);
1756: if (h != null)
1757: return h;
1758: else
1759: {
1760: for (int i = 0; i < children.size(); i++)
1761: {
1762: h = ((gnuPOA) children.get(i)).findServant(servant);
1763: if (h != null)
1764: return h;
1765: }
1766: }
1767: return h;
1768: }
1769:
1770:
1774: public ObjectReferenceTemplate getReferenceTemplate()
1775: {
1776: if (refTemplate == null)
1777: refTemplate = new RefTemplate();
1778:
1779: return refTemplate;
1780: }
1781:
1782: public ObjectReferenceFactory getReferenceFactory()
1783: {
1784: return m_object_factory;
1785: }
1786:
1787: public void setReferenceFactory(ObjectReferenceFactory factory)
1788: {
1789: m_object_factory = factory;
1790: }
1791:
1792:
1795: public Object make_object(String a_repository_id, byte[] an_object_id)
1796: {
1797: AOM.Obj existing = aom.get(an_object_id);
1798:
1799: if (existing != null && existing.object != null)
1800: return existing.object;
1801: else
1802: {
1803: return new gnuServantObject(new String[] { a_repository_id },
1804: an_object_id, this, m_orb);
1805: }
1806: }
1807:
1808:
1811: public String[] _truncatable_ids()
1812: {
1813: return ref_template_ids;
1814: }
1815: }