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.jacorb.notification.MessageFactory; 28 import org.jacorb.notification.OfferManager; 29 import org.jacorb.notification.SubscriptionManager; 30 import org.jacorb.notification.container.CORBAObjectComponentAdapter; 31 import org.jacorb.notification.interfaces.Disposable; 32 import org.jacorb.notification.interfaces.FilterStageSource; 33 import org.jacorb.notification.interfaces.MessageConsumer; 34 import org.jacorb.notification.util.CollectionsWrapper; 35 import org.omg.CORBA.BAD_PARAM ; 36 import org.omg.CORBA.IntHolder ; 37 import org.omg.CORBA.ORB ; 38 import org.omg.CORBA.UNKNOWN ; 39 import org.omg.CosEventChannelAdmin.ProxyPullConsumer; 40 import org.omg.CosEventChannelAdmin.ProxyPushConsumer; 41 import org.omg.CosNotification.EventType; 42 import org.omg.CosNotifyChannelAdmin.AdminLimitExceeded; 43 import org.omg.CosNotifyChannelAdmin.ClientType; 44 import org.omg.CosNotifyChannelAdmin.ProxyConsumer; 45 import org.omg.CosNotifyChannelAdmin.ProxyConsumerHelper; 46 import org.omg.CosNotifyChannelAdmin.ProxyNotFound; 47 import org.omg.CosNotifyChannelAdmin.SupplierAdmin; 48 import org.omg.CosNotifyChannelAdmin.SupplierAdminHelper; 49 import org.omg.CosNotifyChannelAdmin.SupplierAdminOperations; 50 import org.omg.CosNotifyChannelAdmin.SupplierAdminPOATie; 51 import org.omg.CosNotifyComm.InvalidEventType; 52 import org.omg.PortableServer.POA ; 53 import org.omg.PortableServer.Servant ; 54 import org.picocontainer.MutablePicoContainer; 55 import org.picocontainer.defaults.CachingComponentAdapter; 56 57 61 62 public class SupplierAdminImpl extends AbstractSupplierAdmin implements SupplierAdminOperations, 63 Disposable 64 { 65 private FilterStageSource subsequentFilterStagesSource_; 66 67 private final Servant thisServant_; 68 69 private final SupplierAdmin thisCorbaRef_; 70 71 73 public SupplierAdminImpl(IEventChannel channelServant, ORB orb, POA poa, Configuration config, 74 MessageFactory messageFactory, OfferManager offerManager, 75 SubscriptionManager subscriptionManager) 76 { 77 super(channelServant, orb, poa, config, messageFactory, offerManager, subscriptionManager); 78 79 thisServant_ = createServant(); 80 81 thisCorbaRef_ = SupplierAdminHelper.narrow(getServant()._this_object(getORB())); 82 83 container_.registerComponent(new CachingComponentAdapter(new CORBAObjectComponentAdapter( 84 SupplierAdmin.class, thisCorbaRef_))); 85 86 addDisposeHook(new Disposable() 87 { 88 public void dispose() 89 { 90 container_.unregisterComponent(SupplierAdmin.class); 91 } 92 }); 93 } 94 95 protected Servant createServant() 96 { 97 return new SupplierAdminPOATie(this); 98 } 99 100 public Servant getServant() 101 { 102 return thisServant_; 103 } 104 105 public org.omg.CORBA.Object activate() 106 { 107 return thisCorbaRef_; 108 } 109 110 public void offer_change(EventType[] added, EventType[] removed) throws InvalidEventType 111 { 112 offerManager_.offer_change(added, removed); 113 } 114 115 118 public int[] pull_consumers() 119 { 120 return get_all_notify_proxies(pullServants_, modifyProxiesLock_); 121 } 122 123 126 public int[] push_consumers() 127 { 128 return get_all_notify_proxies(pushServants_, modifyProxiesLock_); 129 } 130 131 public ProxyConsumer obtain_notification_pull_consumer(ClientType clientType, 132 IntHolder intHolder) throws AdminLimitExceeded 133 { 134 fireCreateProxyRequestEvent(); 135 136 try 137 { 138 AbstractProxy _servant = obtain_notification_pull_consumer_servant(clientType); 139 140 intHolder.value = _servant.getID().intValue(); 141 142 return ProxyConsumerHelper.narrow(_servant.activate()); 143 } catch (Exception e) 144 { 145 logger_.fatalError("obtain_notification_pull_consumer: unexpected error", e); 146 147 throw new UNKNOWN (); 148 } 149 } 150 151 private AbstractProxy obtain_notification_pull_consumer_servant(ClientType clientType) 152 throws Exception 153 { 154 AbstractProxy _servant = newProxyPullConsumer(clientType); 155 156 configureInterFilterGroupOperator(_servant); 157 158 configureQoS(_servant); 159 160 addProxyToMap(_servant, pullServants_, modifyProxiesLock_); 161 162 return _servant; 163 } 164 165 public ProxyConsumer get_proxy_consumer(int id) throws ProxyNotFound 166 { 167 return ProxyConsumerHelper.narrow(getProxy(id).activate()); 168 } 169 170 public ProxyConsumer obtain_notification_push_consumer(ClientType clienttype, 171 IntHolder intHolder) throws AdminLimitExceeded 172 { 173 fireCreateProxyRequestEvent(); 175 176 try 177 { 178 AbstractProxy _servant = obtain_notification_push_consumer_servant(clienttype); 179 180 intHolder.value = _servant.getID().intValue(); 181 182 return ProxyConsumerHelper.narrow(_servant.activate()); 183 } catch (Exception e) 184 { 185 logger_.fatalError("obtain_notification_push_consumer: unexpected error", e); 186 187 throw new UNKNOWN (); 188 } 189 } 190 191 private AbstractProxy obtain_notification_push_consumer_servant(ClientType clientType) 192 throws Exception 193 { 194 AbstractProxy _servant = newProxyPushConsumer(clientType); 195 196 configureInterFilterGroupOperator(_servant); 197 198 configureQoS(_servant); 199 200 addProxyToMap(_servant, pushServants_, modifyProxiesLock_); 201 202 return _servant; 203 } 204 205 208 public ProxyPushConsumer obtain_push_consumer() 209 { 210 try 211 { 212 MutablePicoContainer _container = newContainerForEventStyleProxy(); 213 214 _container.registerComponent(newComponentAdapter(ECProxyPushConsumerImpl.class, 215 ECProxyPushConsumerImpl.class)); 216 217 AbstractProxyConsumer _servant = (AbstractProxyConsumer) _container 218 .getComponentInstance(ECProxyPushConsumerImpl.class); 219 220 _servant.setSubsequentDestinations(CollectionsWrapper.singletonList(this)); 221 222 addProxyToMap(_servant, pushServants_, modifyProxiesLock_); 223 224 return org.omg.CosEventChannelAdmin.ProxyPushConsumerHelper.narrow(_servant.activate()); 225 } catch (Exception e) 226 { 227 logger_.fatalError("obtain_push_consumer: unexpected error", e); 228 229 throw new UNKNOWN (); 230 } 231 } 232 233 236 public ProxyPullConsumer obtain_pull_consumer() 237 { 238 try 239 { 240 MutablePicoContainer _container = newContainerForEventStyleProxy(); 241 242 _container.registerComponent(newComponentAdapter(ECProxyPullConsumerImpl.class, 243 ECProxyPullConsumerImpl.class)); 244 245 AbstractProxyConsumer _servant = (AbstractProxyConsumer) _container 246 .getComponentInstance(ECProxyPullConsumerImpl.class); 247 248 _servant.setSubsequentDestinations(CollectionsWrapper.singletonList(this)); 249 250 addProxyToMap(_servant, pushServants_, modifyProxiesLock_); 251 252 _servant.set_qos(get_qos()); 253 254 return org.omg.CosEventChannelAdmin.ProxyPullConsumerHelper.narrow(_servant.activate()); 255 } catch (Exception e) 256 { 257 logger_.fatalError("obtain_pull_consumer: unexpected error", e); 258 259 throw new UNKNOWN (); 260 } 261 } 262 263 265 public List getSubsequentFilterStages() 266 { 267 return subsequentFilterStagesSource_.getSubsequentFilterStages(); 268 } 269 270 public void setSubsequentFilterStageSource(FilterStageSource source) 271 { 272 subsequentFilterStagesSource_ = source; 273 } 274 275 278 public MessageConsumer getMessageConsumer() 279 { 280 throw new UnsupportedOperationException (); 281 } 282 283 286 public boolean hasMessageConsumer() 287 { 288 return false; 289 } 290 291 public boolean hasInterFilterGroupOperatorOR() 292 { 293 return false; 294 } 295 296 299 AbstractProxy newProxyPullConsumer(ClientType clientType) 300 { 301 final AbstractProxyConsumer _servant; 302 303 final Class _clazz; 304 305 switch (clientType.value()) { 306 case ClientType._ANY_EVENT: 307 _clazz = ProxyPullConsumerImpl.class; 308 break; 309 case ClientType._STRUCTURED_EVENT: 310 _clazz = StructuredProxyPullConsumerImpl.class; 311 break; 312 case ClientType._SEQUENCE_EVENT: 313 _clazz = SequenceProxyPullConsumerImpl.class; 314 break; 315 default: 316 throw new BAD_PARAM ("Invalid ClientType: ClientType." + clientType.value()); 317 } 318 319 final MutablePicoContainer _containerForProxy = newContainerForNotifyStyleProxy(); 320 321 _containerForProxy.registerComponent(newComponentAdapter(AbstractProxyConsumer.class, 322 _clazz)); 323 324 _servant = (AbstractProxyConsumer) _containerForProxy 325 .getComponentInstance(AbstractProxyConsumer.class); 326 327 _servant.setSubsequentDestinations(CollectionsWrapper.singletonList(this)); 328 329 return _servant; 330 } 331 332 335 AbstractProxy newProxyPushConsumer(ClientType clientType) 336 { 337 final AbstractProxyConsumer _servant; 338 339 final Class _proxyClazz; 340 341 switch (clientType.value()) { 342 case ClientType._ANY_EVENT: 343 _proxyClazz = ProxyPushConsumerImpl.class; 344 break; 345 case ClientType._STRUCTURED_EVENT: 346 _proxyClazz = StructuredProxyPushConsumerImpl.class; 347 break; 348 case ClientType._SEQUENCE_EVENT: 349 _proxyClazz = SequenceProxyPushConsumerImpl.class; 350 break; 351 default: 352 throw new BAD_PARAM ("Invalid ClientType: ClientType." + clientType.value()); 353 } 354 355 final MutablePicoContainer _containerForProxy = newContainerForNotifyStyleProxy(); 356 357 _containerForProxy.registerComponent(newComponentAdapter(AbstractProxyConsumer.class, 358 _proxyClazz)); 359 360 _servant = (AbstractProxyConsumer) _containerForProxy 361 .getComponentInstance(AbstractProxyConsumer.class); 362 363 _servant.setSubsequentDestinations(CollectionsWrapper.singletonList(this)); 364 365 return _servant; 366 } 367 } | Popular Tags |