1 package org.jacorb.test.notification; 2 3 import junit.framework.Assert; 4 5 import org.omg.CORBA.BooleanHolder ; 6 import org.omg.CORBA.IntHolder ; 7 import org.omg.CORBA.ORB ; 8 import org.omg.CosEventChannelAdmin.AlreadyConnected; 9 import org.omg.CosEventChannelAdmin.TypeError; 10 import org.omg.CosEventComm.Disconnected; 11 import org.omg.CosNotification.EventType; 12 import org.omg.CosNotification.StructuredEvent; 13 import org.omg.CosNotifyChannelAdmin.AdminLimitExceeded; 14 import org.omg.CosNotifyChannelAdmin.AdminNotFound; 15 import org.omg.CosNotifyChannelAdmin.ClientType; 16 import org.omg.CosNotifyChannelAdmin.EventChannel; 17 import org.omg.CosNotifyChannelAdmin.ProxyType; 18 import org.omg.CosNotifyChannelAdmin.StructuredProxyPullConsumer; 19 import org.omg.CosNotifyChannelAdmin.StructuredProxyPullConsumerHelper; 20 import org.omg.CosNotifyChannelAdmin.SupplierAdmin; 21 import org.omg.CosNotifyComm.InvalidEventType; 22 import org.omg.CosNotifyComm.StructuredPullSupplierHelper; 23 import org.omg.CosNotifyComm.StructuredPullSupplierOperations; 24 import org.omg.CosNotifyComm.StructuredPullSupplierPOATie; 25 26 30 31 public class StructuredPullSender extends Thread implements StructuredPullSupplierOperations, 32 TestClientOperations 33 { 34 ORB orb_; 35 36 StructuredEvent event_; 37 38 StructuredProxyPullConsumer pullConsumer_; 39 40 private boolean error_; 41 42 boolean connected_; 43 44 boolean eventHandled_; 45 46 boolean available_; 47 48 public boolean isError() 49 { 50 return error_; 51 } 52 53 public boolean isEventHandled() 54 { 55 return eventHandled_; 56 } 57 58 public StructuredPullSender(ORB orb, StructuredEvent event) 59 { 60 event_ = event; 61 orb_ = orb; 62 } 63 64 public void run() 65 { 66 synchronized (this) 67 { 68 available_ = true; 69 } 70 } 71 72 74 public void subscription_change(EventType[] eventType1, EventType[] eventType2) 75 throws InvalidEventType 76 { 77 } 79 80 82 89 public StructuredEvent pull_structured_event() throws Disconnected 90 { 91 BooleanHolder _success = new BooleanHolder (); 92 StructuredEvent _event; 93 while (true) 94 { 95 _event = try_pull_structured_event(_success); 96 if (_success.value) 97 { 98 return _event; 99 } 100 Thread.yield(); 101 } 102 } 103 104 113 public StructuredEvent try_pull_structured_event(BooleanHolder booleanHolder) 114 throws Disconnected 115 { 116 booleanHolder.value = false; 117 StructuredEvent _result = NotificationTestUtils.getInvalidStructuredEvent(orb_); 118 if (event_ != null) 119 { 120 synchronized (this) 121 { 122 if (event_ != null && available_) 123 { 124 _result = event_; 125 event_ = null; 126 booleanHolder.value = true; 127 eventHandled_ = true; 128 } 129 } 130 } 131 return _result; 132 } 133 134 138 public void disconnect_structured_pull_supplier() 139 { 140 connected_ = false; 141 } 142 143 public void connect(EventChannel channel, boolean useOrSemantic) throws AdminLimitExceeded, 144 AlreadyConnected, TypeError, AdminNotFound 145 { 146 StructuredPullSupplierPOATie _senderTie = new StructuredPullSupplierPOATie(this); 147 SupplierAdmin _supplierAdmin = channel.default_supplier_admin(); 148 IntHolder _proxyId = new IntHolder (); 149 pullConsumer_ = StructuredProxyPullConsumerHelper.narrow(_supplierAdmin 150 .obtain_notification_pull_consumer(ClientType.STRUCTURED_EVENT, _proxyId)); 151 152 Assert.assertEquals(_supplierAdmin, channel.get_supplieradmin(_supplierAdmin.MyID())); 153 154 Assert.assertEquals(pullConsumer_.MyType(), ProxyType.PULL_STRUCTURED); 155 156 pullConsumer_.connect_structured_pull_supplier(StructuredPullSupplierHelper 157 .narrow(_senderTie._this(orb_))); 158 connected_ = true; 159 } 160 161 public void shutdown() 162 { 163 pullConsumer_.disconnect_structured_pull_consumer(); 164 Assert.assertTrue(pullConsumer_._non_existent()); 165 } 166 167 public boolean isConnected() 168 { 169 return connected_; 170 } 171 172 } 173 | Popular Tags |