KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > demo > poa_monitor > user_poa > Server


1 package demo.poa_monitor.user_poa;
2
3 import org.omg.CORBA.ORB JavaDoc;
4 import org.omg.PortableServer.*;
5 import org.omg.CosNaming.*;
6 import java.io.*;
7
8 public class Server
9 {
10     public final static String JavaDoc [] DESCRIPTIONS =
11     { "Servant Activator",
12       "Servant Activator & location forward",
13       "Servant Locator",
14       "Default Servant & RETAIN",
15       "One servant multiple oid's",
16       "SINGLE_THREAD_MODEL"
17     };
18
19     public static int kind;
20     public static String JavaDoc factoryPOAName = "factoryPOA";
21     public static String JavaDoc fooPOAName;
22     public static String JavaDoc description;
23
24     public static void main(String JavaDoc[] args)
25     {
26         if( args.length != 1 ||
27             (kind = Integer.parseInt(args[0])) < 1 ||
28             kind > DESCRIPTIONS.length)
29         {
30             String JavaDoc str = "";
31             for (int i=1; i <= DESCRIPTIONS.length; i++ )
32                 str = i==DESCRIPTIONS.length ? str+i : str+i+"|";
33
34             System.err.println("\n<usage: jaco [properties] demo.poa_monitor.user_poa.Server "+str+">\n");
35             System.exit(0);
36         }
37
38         fooPOAName = "fooPOA"+kind;
39         description = DESCRIPTIONS[kind-1];
40
41         try
42         {
43             ORB JavaDoc orb = org.omg.CORBA.ORB.init(args, null);
44             POA rootPOA = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
45             POAManager poaMgr = rootPOA.the_POAManager();
46             
47             // create a user defined poa for the foo factory
48

49             org.omg.CORBA.Policy JavaDoc [] policies =
50             {
51                 rootPOA.create_id_assignment_policy(IdAssignmentPolicyValue.USER_ID),
52                 rootPOA.create_lifespan_policy(LifespanPolicyValue.PERSISTENT)
53             };
54
55             POA factoryPOA =
56                 rootPOA.create_POA( factoryPOAName, poaMgr, policies);
57
58             for (int i = 0; i < policies.length; i++)
59                 policies[i].destroy();
60             
61             // implicit activation of an adpater activator on root poa
62
factoryPOA.the_activator( new FooAdapterActivatorImpl( orb ) );
63             
64             // explicit activation of the factory servant on factory poa
65
FooFactoryImpl factoryServant = new FooFactoryImpl();
66             factoryPOA.activate_object_with_id( new String JavaDoc("FooFactory").getBytes(), factoryServant );
67             
68             // register factory on name service
69
NamingContextExt nc =
70                 NamingContextExtHelper.narrow(orb.resolve_initial_references("NameService"));
71
72             nc.bind( nc.to_name("FooFactory.service") , factoryServant._this(orb) );
73
74             // activate the poa manager
75
poaMgr.activate();
76             System.out.println("[ Server ready ]");
77             orb.run();
78             
79         }
80         catch (Exception JavaDoc e)
81         {
82             e.printStackTrace();
83         }
84     }
85 }
86
Popular Tags