01: package demo.poa_monitor.user_poa;
02:
03: import demo.poa_monitor.foox.*;
04: import org.omg.PortableServer.*;
05:
06: public class FooFactoryImpl extends FooFactoryPOA {
07: private static FooImpl single = new FooImpl("0");
08:
09: public POA _default_POA() {
10: POA rootPOA = super ._default_POA();
11: try {
12: return rootPOA.find_POA(Server.factoryPOAName, false);
13: } catch (org.omg.PortableServer.POAPackage.AdapterNonExistent e) {
14: e.printStackTrace();
15: return rootPOA;
16: }
17: }
18:
19: public Foo createFoo(String id) {
20: Foo result = null;
21: try {
22: POA fooPOA = _default_POA().find_POA(Server.fooPOAName,
23: true);
24:
25: if (Server.kind == 1 || Server.kind == 2
26: || Server.kind == 3) {
27: byte[] oid = id.getBytes();
28: result = FooHelper.narrow(fooPOA
29: .create_reference_with_id(oid, FooHelper.id()));
30: } else if (Server.kind == 4) {
31: result = FooHelper.narrow(fooPOA
32: .create_reference(FooHelper.id()));
33:
34: } else if (Server.kind == 5) {
35: result = FooHelper.narrow(fooPOA
36: .servant_to_reference(single));
37: /* for testing the colocation optimization */
38: System.out
39: .println("[ invocation of the coolocated Foo object ... ]");
40: result.compute(0);
41: System.out.println("[ ... done ]");
42: /*******************************************/
43: } else {
44: result = FooHelper.narrow(fooPOA
45: .servant_to_reference(new FooImpl("0")));
46: }
47: } catch (Exception e) {
48: e.printStackTrace();
49: }
50: System.out.println("[ Foo created with id: " + id + " ]");
51: return result;
52: }
53:
54: public String getServerDescription() {
55: String myOid = "unknown";
56: try {
57: org.omg.PortableServer.Current current = org.omg.PortableServer.CurrentHelper
58: .narrow(_orb().resolve_initial_references(
59: "POACurrent"));
60: myOid = new String(current.get_object_id());
61:
62: } catch (org.omg.CORBA.ORBPackage.InvalidName in) {
63: System.out.println("POACurrent not available!");
64:
65: } catch (org.omg.PortableServer.CurrentPackage.NoContext nc) {
66: System.out.println("Cannot determine the context oid!");
67: }
68:
69: System.out.println("[ " + myOid + ": description requested (\""
70: + Server.description + "\") ]");
71: return Server.description;
72: }
73: }
|