1 package org.jacorb.test.notification; 2 3 import java.util.ArrayList ; 4 import java.util.List ; 5 6 import junit.framework.Assert; 7 8 import org.omg.CORBA.IntHolder ; 9 import org.omg.CORBA.ORB ; 10 import org.omg.CosEventChannelAdmin.AlreadyConnected; 11 import org.omg.CosEventComm.Disconnected; 12 import org.omg.CosNotification.EventType; 13 import org.omg.CosNotification.StructuredEvent; 14 import org.omg.CosNotifyChannelAdmin.AdminLimitExceeded; 15 import org.omg.CosNotifyChannelAdmin.AdminNotFound; 16 import org.omg.CosNotifyChannelAdmin.ClientType; 17 import org.omg.CosNotifyChannelAdmin.EventChannel; 18 import org.omg.CosNotifyChannelAdmin.ProxyType; 19 import org.omg.CosNotifyChannelAdmin.StructuredProxyPushConsumer; 20 import org.omg.CosNotifyChannelAdmin.StructuredProxyPushConsumerHelper; 21 import org.omg.CosNotifyChannelAdmin.SupplierAdmin; 22 import org.omg.CosNotifyComm.InvalidEventType; 23 import org.omg.CosNotifyComm.StructuredPushSupplier; 24 import org.omg.CosNotifyComm.StructuredPushSupplierOperations; 25 import org.omg.CosNotifyComm.StructuredPushSupplierPOATie; 26 27 public class StructuredPushSender extends Thread implements StructuredPushSupplierOperations, 28 TestClientOperations 29 { 30 public StructuredProxyPushConsumer pushConsumer_; 31 32 StructuredEvent[] events_; 33 34 boolean error_ = false; 35 36 boolean connected_; 37 38 boolean eventSent_; 39 40 long interval_ = 0; 41 42 NotificationTestCase testCase_; 43 44 List addedSubscriptions_ = new ArrayList (); 45 46 List removedSubscriptions_ = new ArrayList (); 47 48 final ORB orb_; 49 50 public StructuredPushSender(ORB orb) 51 { 52 orb_ = orb; 53 } 54 55 public boolean isConnected() 56 { 57 return connected_; 58 } 59 60 public boolean isEventHandled() 61 { 62 return eventSent_; 63 } 64 65 public boolean isError() 66 { 67 return error_; 68 } 69 70 public void run() 71 { 72 runOnEventArray(); 73 74 eventSent_ = true; 75 } 76 77 private void runOnEventArray() 78 { 79 try 80 { 81 pushEvents(events_); 82 } catch (Disconnected e) 83 { 84 Assert.fail(); 85 } 86 } 87 88 public void pushEvents(final StructuredEvent[] events) throws Disconnected 89 { 90 for (int x = 0; x < events.length; ++x) 91 { 92 pushConsumer_.push_structured_event(events[x]); 93 } 94 } 95 96 public void disconnect_structured_push_supplier() 97 { 98 connected_ = false; 99 } 100 101 public void subscription_change(EventType[] added, EventType[] removed) throws InvalidEventType 102 { 103 for (int x = 0; x < added.length; ++x) 104 { 105 addedSubscriptions_.add(added[x]); 106 } 107 108 for (int x = 0; x < removed.length; ++x) 109 { 110 removedSubscriptions_.add(removed[x]); 111 } 112 } 113 114 public void connect(EventChannel channel, boolean useOrSemantic) throws AdminLimitExceeded, 115 AlreadyConnected, AdminNotFound 116 { 117 Assert.assertNotNull(channel); 118 119 StructuredPushSupplierPOATie senderTie = new StructuredPushSupplierPOATie(this); 120 121 StructuredPushSupplier sender = senderTie._this(orb_); 122 123 SupplierAdmin supplierAdmin = channel.default_supplier_admin(); 124 125 Assert.assertNotNull(supplierAdmin); 126 127 Assert.assertEquals(supplierAdmin, channel.get_supplieradmin(supplierAdmin.MyID())); 128 129 IntHolder _proxyIdHolder = new IntHolder (); 130 131 pushConsumer_ = StructuredProxyPushConsumerHelper.narrow(supplierAdmin 132 .obtain_notification_push_consumer(ClientType.STRUCTURED_EVENT, _proxyIdHolder)); 133 134 Assert.assertEquals(pushConsumer_.MyType(), ProxyType.PUSH_STRUCTURED); 135 136 pushConsumer_.connect_structured_push_supplier(sender); 137 138 connected_ = true; 139 } 140 141 public void shutdown() 142 { 143 pushConsumer_.disconnect_structured_push_consumer(); 144 } 145 146 public void setStructuredEvent(StructuredEvent[] events) 147 { 148 events_ = events; 149 } 150 151 public void setStructuredEvent(StructuredEvent events) 152 { 153 setStructuredEvent(new StructuredEvent[] { events }); 154 } 155 156 public void setInterval(long interval) 157 { 158 interval_ = interval; 159 } 160 } 161 | Popular Tags |