KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > demo > events > PushSupplierDemo


1 package demo.events;
2
3 /**
4  * @authors Joerg v. Frantzius, Rainer Lischetzki, Gerald Brose 1997
5  *
6  * A simple demo for using the event channel as a push supplier of events.
7  *
8  */

9
10 import org.omg.CosEventChannelAdmin.*;
11 import org.omg.CosEventComm.*;
12 import org.omg.CosNaming.*;
13 import org.omg.CORBA.Any JavaDoc;
14
15 class PushSupplierDemo extends PushSupplierPOA
16 {
17
18   public PushSupplierDemo( String JavaDoc[] args )
19   {
20     org.omg.CosEventChannelAdmin.EventChannel e = null;
21     org.omg.CORBA.ORB JavaDoc orb = org.omg.CORBA.ORB.init(args, null);
22
23     try
24     {
25       org.omg.PortableServer.POA JavaDoc poa =
26          org.omg.PortableServer.POAHelper.narrow
27             (orb.resolve_initial_references ("RootPOA"));
28       poa.the_POAManager().activate();
29  
30       NamingContextExt nc =
31           NamingContextExtHelper.narrow(
32               orb.resolve_initial_references("NameService"));
33
34       e = EventChannelHelper.narrow(nc.resolve(
35           nc.to_name("eventchannel.example")));
36     }
37     catch(Exception JavaDoc ex)
38     {
39       ex.printStackTrace();
40     }
41
42     SupplierAdmin supplierAdmin = e.for_suppliers();
43     ProxyPushConsumer proxyPushConsumer = supplierAdmin.obtain_push_consumer();
44
45     try
46     {
47       proxyPushConsumer.connect_push_supplier( _this(orb) );
48     }
49     catch (org.omg.CosEventChannelAdmin.AlreadyConnected ex)
50     {
51       ex.printStackTrace();
52     }
53
54     for(int i=0; i < 30; i++)
55     {
56       try
57       {
58         Any JavaDoc any = orb.create_any();
59         any.insert_string("Test the channel!" + i);
60         System.out.println("Pushing event # " + (i) );
61         proxyPushConsumer.push( any );
62       }
63       catch(Disconnected d)
64       {
65         d.printStackTrace();
66       }
67     }
68     proxyPushConsumer.disconnect_push_consumer();
69   }
70
71   public void disconnect_push_supplier ()
72   {
73     System.out.println ("Supplier disconnected");
74   }
75
76   public static void main(String JavaDoc[] args)
77   {
78     PushSupplierDemo demo = new PushSupplierDemo( args );
79   }
80 }
81
Popular Tags