1 package org.jacorb.notification.servant; 2 3 23 24 import java.util.List ; 25 26 import org.apache.avalon.framework.configuration.Configuration; 27 import org.apache.avalon.framework.configuration.ConfigurationException; 28 import org.jacorb.notification.OfferManager; 29 import org.jacorb.notification.SubscriptionManager; 30 import org.jacorb.notification.engine.TaskProcessor; 31 import org.jacorb.notification.interfaces.Message; 32 import org.jacorb.notification.interfaces.MessageConsumer; 33 import org.jacorb.notification.util.CollectionsWrapper; 34 import org.omg.CORBA.BooleanHolder ; 35 import org.omg.CORBA.ORB ; 36 import org.omg.CosEventChannelAdmin.AlreadyConnected; 37 import org.omg.CosEventComm.Disconnected; 38 import org.omg.CosNotification.EventHeader; 39 import org.omg.CosNotification.EventType; 40 import org.omg.CosNotification.FixedEventHeader; 41 import org.omg.CosNotification.Property; 42 import org.omg.CosNotification.StructuredEvent; 43 import org.omg.CosNotifyChannelAdmin.ConsumerAdmin; 44 import org.omg.CosNotifyChannelAdmin.ProxySupplierHelper; 45 import org.omg.CosNotifyChannelAdmin.ProxyType; 46 import org.omg.CosNotifyChannelAdmin.StructuredProxyPullSupplierOperations; 47 import org.omg.CosNotifyChannelAdmin.StructuredProxyPullSupplierPOATie; 48 import org.omg.CosNotifyComm.StructuredPullConsumer; 49 import org.omg.PortableServer.POA ; 50 import org.omg.PortableServer.Servant ; 51 52 56 57 public class StructuredProxyPullSupplierImpl extends AbstractProxySupplier implements 58 StructuredProxyPullSupplierOperations 59 { 60 63 protected static final StructuredEvent UNDEFINED_STRUCTURED_EVENT; 64 65 static 67 { 68 ORB _orb = ORB.init(); 69 70 UNDEFINED_STRUCTURED_EVENT = new StructuredEvent(); 71 EventType _type = new EventType(); 72 FixedEventHeader _fixed = new FixedEventHeader(_type, ""); 73 Property[] _variable = new Property[0]; 74 UNDEFINED_STRUCTURED_EVENT.header = new EventHeader(_fixed, _variable); 75 UNDEFINED_STRUCTURED_EVENT.filterable_data = new Property[0]; 76 UNDEFINED_STRUCTURED_EVENT.remainder_of_body = _orb.create_any(); 77 } 78 79 82 private StructuredPullConsumer structuredPullConsumer_; 83 84 86 public StructuredProxyPullSupplierImpl(IAdmin admin, ORB orb, POA poa, Configuration conf, 87 TaskProcessor taskProcessor, OfferManager offerManager, 88 SubscriptionManager subscriptionManager, ConsumerAdmin consumerAdmin) throws ConfigurationException 89 { 90 super(admin, orb, poa, conf, taskProcessor, offerManager, 91 subscriptionManager, consumerAdmin); 92 } 93 94 public ProxyType MyType() 95 { 96 return ProxyType.PULL_STRUCTURED; 97 } 98 99 public void connect_structured_pull_consumer(StructuredPullConsumer consumer) 100 throws AlreadyConnected 101 { 102 checkIsNotConnected(); 103 104 connectClient(consumer); 105 106 structuredPullConsumer_ = consumer; 107 108 logger_.info("connect structured_pull_consumer"); 109 } 110 111 public StructuredEvent pull_structured_event() throws Disconnected 112 { 113 checkStillConnected(); 114 115 try 116 { 117 Message _message = getMessageBlocking(); 118 119 try 120 { 121 return _message.toStructuredEvent(); 122 } finally 123 { 124 _message.dispose(); 125 } 126 } catch (InterruptedException e) 127 { 128 return UNDEFINED_STRUCTURED_EVENT; 129 } 130 } 131 132 public StructuredEvent try_pull_structured_event(BooleanHolder hasEvent) throws Disconnected 133 { 134 checkStillConnected(); 135 136 Message _message = getMessageNoBlock(); 137 138 if (_message != null) 139 { 140 try 141 { 142 hasEvent.value = true; 143 144 return _message.toStructuredEvent(); 145 } finally 146 { 147 _message.dispose(); 148 } 149 } 150 151 hasEvent.value = false; 152 153 return UNDEFINED_STRUCTURED_EVENT; 154 } 155 156 public void disconnect_structured_pull_supplier() 157 { 158 destroy(); 159 } 160 161 protected void disconnectClient() 162 { 163 logger_.info("disconnect structured_pull_consumer"); 164 165 structuredPullConsumer_.disconnect_structured_pull_consumer(); 166 167 structuredPullConsumer_ = null; 168 } 169 170 public List getSubsequentFilterStages() 171 { 172 return CollectionsWrapper.singletonList(this); 173 } 174 175 public MessageConsumer getMessageConsumer() 176 { 177 return this; 178 } 179 180 public void disableDelivery() 181 { 182 } 184 185 public void enableDelivery() 186 { 187 } 189 190 public void deliverPendingData() 191 { 192 } 194 195 public synchronized Servant getServant() 196 { 197 if (thisServant_ == null) 198 { 199 thisServant_ = new StructuredProxyPullSupplierPOATie(this); 200 } 201 202 return thisServant_; 203 } 204 205 public org.omg.CORBA.Object activate() 206 { 207 return ProxySupplierHelper.narrow(getServant()._this_object(getORB())); 208 } 209 210 protected long getCost() 211 { 212 return 0; 213 } 214 } | Popular Tags |