1 package org.jacorb.events; 2 3 22 23 import org.omg.CosEventChannelAdmin.*; 24 import org.omg.CosEventComm.*; 25 import org.omg.CORBA.*; 26 import org.omg.CosNaming.*; 27 import org.omg.PortableServer.*; 28 import java.util.*; 29 import org.jacorb.orb.*; 30 import java.net.*; 31 32 41 42 public class EventChannelImpl extends JacORBEventChannelPOA 43 { 44 private Vector pullSuppliers = new Vector(); 45 private Vector pullConsumers = new Vector(); 46 private Vector pushSuppliers = new Vector(); 47 private Vector pushConsumers = new Vector(); 48 private Vector pendingEvents = new Vector(); 49 private org.omg.CORBA.Any nullAny = null; 50 51 private org.omg.CORBA.ORB myOrb = null; 52 private org.omg.PortableServer.POA myPoa = null; 53 54 55 58 public EventChannelImpl(org.omg.CORBA.ORB orb, org.omg.PortableServer.POA poa) 59 { 60 myOrb = orb; 61 myPoa = poa; 62 63 _this_object(myOrb); 64 nullAny = myOrb.create_any(); 65 nullAny.type(myOrb.get_primitive_tc( TCKind.tk_null)); 66 67 try 68 { 69 this.myPoa = poa; 70 myPoa.the_POAManager().activate(); 71 } 72 catch( Exception e ) 73 { 74 e.printStackTrace(); 75 } 76 } 77 78 81 private void consumerAdminDestroy() 82 { 83 releaseList( pullSuppliers ); 84 releaseList( pushSuppliers ); 85 } 86 87 90 private void supplierAdminDestroy() 91 { 92 releaseList( pullConsumers ); 93 releaseList( pushConsumers ); 94 } 95 96 99 private void releaseList( Vector list ) 100 { 101 for ( Enumeration e = list.elements(); e.hasMoreElements(); ) 102 { 103 org.omg.PortableServer.Servant servant = 104 (org.omg.PortableServer.Servant )e.nextElement(); 105 releaseServant( servant ); 106 } 107 } 108 109 112 private void releaseServant( org.omg.PortableServer.Servant servant ) 113 { 114 try 115 { 116 servant._poa().deactivate_object( servant._object_id() ); 117 } 118 catch (org.omg.PortableServer.POAPackage.WrongPolicy wpEx) 119 { 120 wpEx.printStackTrace(); 121 } 122 catch (org.omg.PortableServer.POAPackage.ObjectNotActive onaEx) 123 { 124 onaEx.printStackTrace(); 125 } 126 } 127 128 131 public void destroy() 132 { 133 consumerAdminDestroy(); 134 supplierAdminDestroy(); 135 releaseServant(this); 136 } 137 138 139 142 public ConsumerAdmin for_consumers() 143 { 144 try 145 { 146 return ConsumerAdminHelper.narrow(myPoa.servant_to_reference(this)); 147 } 148 catch( Exception e ) 149 { 150 e.printStackTrace(); 151 return null; 152 } 153 } 154 155 158 public SupplierAdmin for_suppliers() 159 { 160 try 161 { 162 return SupplierAdminHelper.narrow(myPoa.servant_to_reference(this)); 163 } 164 catch( Exception e ) 165 { 166 e.printStackTrace(); 167 return null; 168 } 169 } 170 171 175 public ProxyPullConsumer obtain_pull_consumer() 176 { 177 synchronized( pullConsumers ) 178 { 179 ProxyPullConsumerImpl p = new ProxyPullConsumerImpl( this, _orb(), myPoa ); 180 pullConsumers.addElement( p ); 181 return p._this( myOrb ); 182 } 183 } 184 185 189 public ProxyPullSupplier obtain_pull_supplier() 190 { 191 synchronized( pullSuppliers ) 192 { 193 ProxyPullSupplierImpl p = new ProxyPullSupplierImpl ( this, _orb(), myPoa ); 194 pullSuppliers.addElement( p ); 195 return p._this( myOrb ); 196 } 197 } 198 199 203 public ProxyPushConsumer obtain_push_consumer() 204 { 205 synchronized( pushConsumers ) 206 { 207 ProxyPushConsumerImpl p = new ProxyPushConsumerImpl( this, _orb(), myPoa ); 208 pushConsumers.addElement( p ); 209 return p._this( myOrb ); 210 } 211 } 212 213 217 public ProxyPushSupplier obtain_push_supplier() 218 { 219 synchronized( pushSuppliers ) 220 { 221 ProxyPushSupplierImpl p = new ProxyPushSupplierImpl( this, _orb(), myPoa ); 222 pushSuppliers.addElement( p ); 223 return p._this( myOrb ); 224 } 225 } 226 227 228 231 protected void push_event( org.omg.CORBA.Any event ) 232 { 233 ProxyPushSupplierImpl push = null; 234 ProxyPullSupplierImpl pull = null; 235 synchronized( pushSuppliers ) 236 { 237 for(int i = (pushSuppliers.size() - 1); i >= 0; --i ) 238 { 239 push = (ProxyPushSupplierImpl) pushSuppliers.elementAt( i ); 240 try 241 { 242 push.push_to_consumer( event ); 243 } 244 catch( org.omg.CORBA.COMM_FAILURE comm ) 245 { 246 pushSuppliers.removeElementAt( i ); 247 } 248 } 249 } 250 251 synchronized( pullSuppliers ) 252 { 253 for (int i = (pullSuppliers.size() - 1); i >= 0; --i ) 254 { 255 pull = (ProxyPullSupplierImpl)pullSuppliers.elementAt( i ); 256 257 try 258 { 259 pull.push_to_supplier( event ); 260 } 261 catch( org.omg.CORBA.COMM_FAILURE comm ) 262 { 263 pullSuppliers.removeElementAt( i ); 264 } 265 } 266 } 267 } 268 269 static public void main( String [] args ) 270 { 271 org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args, null); 272 try 273 { 274 org.omg.PortableServer.POA poa = 275 org.omg.PortableServer.POAHelper.narrow( 276 orb.resolve_initial_references("RootPOA")); 277 278 EventChannelImpl channel = new EventChannelImpl(orb,poa); 279 280 poa.the_POAManager().activate(); 281 282 org.omg.CORBA.Object o = poa.servant_to_reference(channel); 283 284 NamingContextExt nc = 285 NamingContextExtHelper.narrow( 286 orb.resolve_initial_references("NameService")); 287 288 String channelName = ( args.length > 0 ? args[0] : "Generic.channel" ); 289 290 nc.bind(nc.to_name( channelName ), o); 291 orb.run(); 292 } 293 catch( Exception e ) 294 { 295 e.printStackTrace(); 296 } 297 } 298 299 305 public org.omg.PortableServer.POA _default_POA() 306 { 307 return myPoa; 308 } 309 } 310 | Popular Tags |