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