01: package demo.poa_monitor.user_poa;
02:
03: import org.omg.CORBA.ORB;
04: import org.omg.PortableServer.*;
05: import org.omg.CosNaming.*;
06: import java.io.*;
07:
08: public class Server {
09: public final static String[] DESCRIPTIONS = { "Servant Activator",
10: "Servant Activator & location forward", "Servant Locator",
11: "Default Servant & RETAIN", "One servant multiple oid's",
12: "SINGLE_THREAD_MODEL" };
13:
14: public static int kind;
15: public static String factoryPOAName = "factoryPOA";
16: public static String fooPOAName;
17: public static String description;
18:
19: public static void main(String[] args) {
20: if (args.length != 1 || (kind = Integer.parseInt(args[0])) < 1
21: || kind > DESCRIPTIONS.length) {
22: String str = "";
23: for (int i = 1; i <= DESCRIPTIONS.length; i++)
24: str = i == DESCRIPTIONS.length ? str + i : str + i
25: + "|";
26:
27: System.err
28: .println("\n<usage: jaco [properties] demo.poa_monitor.user_poa.Server "
29: + str + ">\n");
30: System.exit(0);
31: }
32:
33: fooPOAName = "fooPOA" + kind;
34: description = DESCRIPTIONS[kind - 1];
35:
36: try {
37: ORB orb = org.omg.CORBA.ORB.init(args, null);
38: POA rootPOA = POAHelper.narrow(orb
39: .resolve_initial_references("RootPOA"));
40: POAManager poaMgr = rootPOA.the_POAManager();
41:
42: // create a user defined poa for the foo factory
43:
44: org.omg.CORBA.Policy[] policies = {
45: rootPOA
46: .create_id_assignment_policy(IdAssignmentPolicyValue.USER_ID),
47: rootPOA
48: .create_lifespan_policy(LifespanPolicyValue.PERSISTENT) };
49:
50: POA factoryPOA = rootPOA.create_POA(factoryPOAName, poaMgr,
51: policies);
52:
53: for (int i = 0; i < policies.length; i++)
54: policies[i].destroy();
55:
56: // implicit activation of an adpater activator on root poa
57: factoryPOA.the_activator(new FooAdapterActivatorImpl(orb));
58:
59: // explicit activation of the factory servant on factory poa
60: FooFactoryImpl factoryServant = new FooFactoryImpl();
61: factoryPOA.activate_object_with_id(new String("FooFactory")
62: .getBytes(), factoryServant);
63:
64: // register factory on name service
65: NamingContextExt nc = NamingContextExtHelper.narrow(orb
66: .resolve_initial_references("NameService"));
67:
68: nc.bind(nc.to_name("FooFactory.service"), factoryServant
69: ._this (orb));
70:
71: // activate the poa manager
72: poaMgr.activate();
73: System.out.println("[ Server ready ]");
74: orb.run();
75:
76: } catch (Exception e) {
77: e.printStackTrace();
78: }
79: }
80: }
|