1 package org.jacorb.test.notification; 2 3 import org.omg.CORBA.Any ; 4 import org.omg.CORBA.BooleanHolder ; 5 import org.omg.CORBA.ORB ; 6 import org.omg.CosEventChannelAdmin.AlreadyConnected; 7 import org.omg.CosEventChannelAdmin.ConsumerAdmin; 8 import org.omg.CosEventChannelAdmin.EventChannel; 9 import org.omg.CosEventChannelAdmin.EventChannelHelper; 10 import org.omg.CosEventChannelAdmin.ProxyPullSupplier; 11 import org.omg.CosEventComm.Disconnected; 12 import org.omg.CosEventComm.PullConsumerPOA; 13 14 18 19 public class CosEventPullReceiver extends PullConsumerPOA implements Runnable , TestClientOperations 20 { 21 ProxyPullSupplier mySupplier_; 22 23 Any event_ = null; 24 25 long timeout_ = 1000; 26 27 boolean error_ = false; 28 29 boolean connected_; 30 31 ORB orb_; 32 33 public CosEventPullReceiver(ORB orb) 34 { 35 orb_ = orb; 36 } 37 38 public void disconnect_pull_consumer() 39 { 40 connected_ = false; 41 } 42 43 public boolean isError() 44 { 45 return error_; 46 } 47 48 public boolean isConnected() 49 { 50 return connected_; 51 } 52 53 public boolean isEventHandled() 54 { 55 return (event_ != null); 56 } 57 58 public void run() 59 { 60 long _startTime = System.currentTimeMillis(); 61 long _stopTime = _startTime + timeout_; 62 63 BooleanHolder _success = new BooleanHolder (); 64 65 try 66 { 67 while (connected_ && System.currentTimeMillis() < _stopTime) 68 { 69 event_ = mySupplier_.try_pull(_success); 70 if (_success.value) 71 { 72 break; 73 } 74 Thread.yield(); 75 } 76 } catch (Disconnected d) 77 { 78 d.printStackTrace(); 79 error_ = true; 80 } 81 } 82 83 public void connect(org.omg.CosNotifyChannelAdmin.EventChannel channel, boolean useOrSemantic) 84 throws AlreadyConnected 85 { 86 87 EventChannel _channel = EventChannelHelper.narrow(channel); 88 ConsumerAdmin _admin = _channel.for_consumers(); 89 mySupplier_ = _admin.obtain_pull_supplier(); 90 mySupplier_.connect_pull_consumer(_this(orb_)); 91 connected_ = true; 92 } 93 94 public void shutdown() 95 { 96 mySupplier_.disconnect_pull_supplier(); 97 } 98 } 99 | Popular Tags |