01: package demo.events;
02:
03: /**
04: * @authors Joerg v. Frantzius, Rainer Lischetzki, Gerald Brose 1997
05: *
06: * A simple demo for using the event channel as a push supplier of events.
07: *
08: */
09:
10: import org.omg.CosEventChannelAdmin.*;
11: import org.omg.CosEventComm.*;
12: import org.omg.CosNaming.*;
13: import org.omg.CORBA.Any;
14:
15: class PushSupplierDemo extends PushSupplierPOA {
16:
17: public PushSupplierDemo(String[] args) {
18: org.omg.CosEventChannelAdmin.EventChannel e = null;
19: org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args, null);
20:
21: try {
22: org.omg.PortableServer.POA poa = org.omg.PortableServer.POAHelper
23: .narrow(orb.resolve_initial_references("RootPOA"));
24: poa.the_POAManager().activate();
25:
26: NamingContextExt nc = NamingContextExtHelper.narrow(orb
27: .resolve_initial_references("NameService"));
28:
29: e = EventChannelHelper.narrow(nc.resolve(nc
30: .to_name("eventchannel.example")));
31: } catch (Exception ex) {
32: ex.printStackTrace();
33: }
34:
35: SupplierAdmin supplierAdmin = e.for_suppliers();
36: ProxyPushConsumer proxyPushConsumer = supplierAdmin
37: .obtain_push_consumer();
38:
39: try {
40: proxyPushConsumer.connect_push_supplier(_this (orb));
41: } catch (org.omg.CosEventChannelAdmin.AlreadyConnected ex) {
42: ex.printStackTrace();
43: }
44:
45: for (int i = 0; i < 30; i++) {
46: try {
47: Any any = orb.create_any();
48: any.insert_string("Test the channel!" + i);
49: System.out.println("Pushing event # " + (i));
50: proxyPushConsumer.push(any);
51: } catch (Disconnected d) {
52: d.printStackTrace();
53: }
54: }
55: proxyPushConsumer.disconnect_push_consumer();
56: }
57:
58: public void disconnect_push_supplier() {
59: System.out.println("Supplier disconnected");
60: }
61:
62: public static void main(String[] args) {
63: PushSupplierDemo demo = new PushSupplierDemo(args);
64: }
65: }
|