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 consumer
07: * of events. This consumer unregisters and quits after receiving
08: * 5 events.
09: *
10: */
11:
12: import org.omg.CosEventChannelAdmin.*;
13: import org.omg.CosEventComm.*;
14: import org.omg.CosNaming.*;
15:
16: public class PushConsumerDemo implements PushConsumerOperations {
17: private short count = 0;
18: private ProxyPushSupplier myPps = null;
19: private int limit = 25;
20:
21: static org.omg.CORBA.ORB orb = null;
22:
23: public PushConsumerDemo(ProxyPushSupplier _pps) {
24: myPps = _pps;
25: }
26:
27: public void disconnect_push_consumer() {
28: System.out.println("Consumer disconnected.");
29: }
30:
31: static public void main(String[] args) {
32: EventChannel ecs = null;
33: ConsumerAdmin ca = null;
34: PushConsumer pushConsumer = null;
35: ProxyPushSupplier pps = null;
36:
37: try {
38: orb = org.omg.CORBA.ORB.init(args, null);
39: NamingContextExt nc = NamingContextExtHelper.narrow(orb
40: .resolve_initial_references("NameService"));
41:
42: ecs = EventChannelHelper.narrow(nc.resolve(nc
43: .to_name("eventchannel.example")));
44: } catch (Exception e) {
45: e.printStackTrace();
46: }
47:
48: ca = ecs.for_consumers();
49: pps = ca.obtain_push_supplier();
50:
51: try {
52: org.omg.PortableServer.POA poa = org.omg.PortableServer.POAHelper
53: .narrow(orb.resolve_initial_references("RootPOA"));
54:
55: poa.the_POAManager().activate();
56:
57: PushConsumerPOATie pt = new PushConsumerPOATie(
58: new PushConsumerDemo(pps));
59: pt._this _object(orb);
60: pushConsumer = PushConsumerHelper.narrow(poa
61: .servant_to_reference(pt));
62: pps.connect_push_consumer(pushConsumer);
63: System.out.println("PushConsumerImpl registered.");
64: orb.run();
65: } catch (Exception e) {
66: e.printStackTrace();
67: }
68: System.out.println("Quit.");
69: }
70:
71: public synchronized void push(org.omg.CORBA.Any data)
72: throws org.omg.CosEventComm.Disconnected {
73: count++;
74: System.out.println("event " + count + " : "
75: + data.extract_string());
76: if (count >= limit) {
77: System.out.println("unregister");
78: myPps.disconnect_push_supplier();
79: // System.exit(0);
80: orb.shutdown(false);
81: }
82: }
83: }
|