KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > demo > notification > office > PrintServer


1 package demo.notification.office;
2
3 /**
4  *
5  */

6
7 import org.omg.CosNotification.*;
8 import org.omg.CosNotifyComm.*;
9 import org.omg.CosNotifyChannelAdmin.*;
10
11 import org.omg.CosNaming.*;
12 import org.omg.CosNaming.NamingContextPackage.*;
13 import org.omg.CORBA.ORB JavaDoc;
14 import org.omg.PortableServer.*;
15
16 import demo.notification.office.*;
17
18 class PrintServer
19 {
20     /**
21      * main
22      */

23
24     static public void main (String JavaDoc argv[])
25     {
26     EventChannel channel = null;
27     org.omg.CORBA.ORB JavaDoc orb = org.omg.CORBA.ORB.init(argv, null);
28
29     try
30     {
31         // initialize POA, get naming and event service references
32
POA poa = POAHelper.narrow(orb.resolve_initial_references("RootPOA") );
33         poa.the_POAManager().activate();
34
35         NamingContextExt nc =
36         NamingContextExtHelper.narrow(orb.resolve_initial_references("NameService"));
37
38             EventChannelFactory factory =
39                 EventChannelFactoryHelper.narrow( orb.resolve_initial_references("NotificationService"));
40
41             if( factory == null )
42             {
43                 System.err.println("Could not find or narrow EventChannelFactory");
44                 System.exit(1);
45             }
46
47             org.omg.CORBA.IntHolder JavaDoc idHolder =
48                 new org.omg.CORBA.IntHolder JavaDoc();
49
50             Property[] qos = new Property[0];
51             Property[] adm = new Property[0];
52
53             channel = factory.create_channel(qos, adm, idHolder);
54             nc.rebind( nc.to_name("office_event.channel"), channel );
55
56             System.out.println("Channel " + idHolder.value +
57                                " created and bound to name office_event.channel.");
58
59         // create a Printer object, implicitly activate it and advertise its presence
60
PrinterImpl printer = new PrinterImpl( channel, orb, poa );
61         printer.connect();
62             System.out.println("Printer created and connected");
63
64         org.omg.CORBA.Object JavaDoc printerObj = poa.servant_to_reference( printer );
65         nc.rebind( nc.to_name("Printer"), printerObj);
66             System.out.println("Printer exported");
67
68         // wait for requests
69
orb.run();
70     }
71     catch (Exception JavaDoc ex)
72     {
73         ex.printStackTrace();
74     }
75     }
76 }
77
Popular Tags