1 7 8 package com.sun.corba.se.impl.oa.poa ; 9 10 import java.util.Set ; 11 12 import org.omg.CORBA.SystemException ; 13 14 import org.omg.PortableServer.ServantActivator ; 15 import org.omg.PortableServer.Servant ; 16 import org.omg.PortableServer.ServantManager ; 17 import org.omg.PortableServer.ForwardRequest ; 18 import org.omg.PortableServer.POAPackage.WrongPolicy ; 19 import org.omg.PortableServer.POAPackage.ObjectNotActive ; 20 import org.omg.PortableServer.POAPackage.ServantNotActive ; 21 import org.omg.PortableServer.POAPackage.ObjectAlreadyActive ; 22 import org.omg.PortableServer.POAPackage.ServantAlreadyActive ; 23 import org.omg.PortableServer.POAPackage.NoServant ; 24 25 import com.sun.corba.se.impl.orbutil.concurrent.SyncUtil ; 26 import com.sun.corba.se.impl.orbutil.ORBUtility ; 27 import com.sun.corba.se.impl.orbutil.ORBConstants ; 28 29 import com.sun.corba.se.impl.oa.NullServantImpl ; 30 31 import com.sun.corba.se.impl.javax.rmi.CORBA.Util ; 32 33 import com.sun.corba.se.spi.oa.OAInvocationInfo ; 34 import com.sun.corba.se.spi.oa.NullServant ; 35 36 39 public class POAPolicyMediatorImpl_R_USM extends POAPolicyMediatorBase_R { 40 protected ServantActivator activator ; 41 42 POAPolicyMediatorImpl_R_USM( Policies policies, POAImpl poa ) 43 { 44 super( policies, poa ) ; 46 activator = null ; 47 48 if (!policies.useServantManager()) 49 throw poa.invocationWrapper().policyMediatorBadPolicyInFactory() ; 50 } 51 52 61 private AOMEntry enterEntry( ActiveObjectMap.Key key ) 62 { 63 AOMEntry result = null ; 64 boolean failed ; 65 do { 66 failed = false ; 67 result = activeObjectMap.get(key) ; 68 69 try { 70 result.enter() ; 71 } catch (Exception exc) { 72 failed = true ; 73 } 74 } while (failed) ; 75 76 return result ; 77 } 78 79 protected java.lang.Object internalGetServant( byte[] id, 80 String operation ) throws ForwardRequest 81 { 82 if (poa.getDebug()) { 83 ORBUtility.dprint( this, 84 "Calling POAPolicyMediatorImpl_R_USM.internalGetServant " + 85 "for poa " + poa + " operation=" + operation ) ; 86 } 87 88 try { 89 ActiveObjectMap.Key key = new ActiveObjectMap.Key( id ) ; 90 AOMEntry entry = enterEntry(key) ; 91 java.lang.Object servant = activeObjectMap.getServant( entry ) ; 92 if (servant != null) { 93 if (poa.getDebug()) { 94 ORBUtility.dprint( this, 95 "internalGetServant: servant already activated" ) ; 96 } 97 98 return servant ; 99 } 100 101 if (activator == null) { 102 if (poa.getDebug()) { 103 ORBUtility.dprint( this, 104 "internalGetServant: no servant activator in POA" ) ; 105 } 106 107 entry.incarnateFailure() ; 108 throw poa.invocationWrapper().poaNoServantManager() ; 109 } 110 111 try { 116 if (poa.getDebug()) { 117 ORBUtility.dprint( this, 118 "internalGetServant: upcall to incarnate" ) ; 119 } 120 121 poa.unlock() ; 122 123 servant = activator.incarnate(id, poa); 124 125 if (servant == null) 126 servant = new NullServantImpl( 127 poa.omgInvocationWrapper().nullServantReturned() ) ; 128 } catch (ForwardRequest freq) { 129 if (poa.getDebug()) { 130 ORBUtility.dprint( this, 131 "internalGetServant: incarnate threw ForwardRequest" ) ; 132 } 133 134 throw freq ; 135 } catch (SystemException exc) { 136 if (poa.getDebug()) { 137 ORBUtility.dprint( this, 138 "internalGetServant: incarnate threw SystemException " + exc ) ; 139 } 140 141 throw exc ; 142 } catch (Throwable exc) { 143 if (poa.getDebug()) { 144 ORBUtility.dprint( this, 145 "internalGetServant: incarnate threw Throwable " + exc ) ; 146 } 147 148 throw poa.invocationWrapper().poaServantActivatorLookupFailed( 149 exc ) ; 150 } finally { 151 poa.lock() ; 152 153 if ((servant == null) || (servant instanceof NullServant)) { 158 if (poa.getDebug()) { 159 ORBUtility.dprint( this, 160 "internalGetServant: incarnate failed" ) ; 161 } 162 163 entry.incarnateFailure() ; 172 } else { 173 if (isUnique) { 178 if (activeObjectMap.contains((Servant )servant)) { 180 if (poa.getDebug()) { 181 ORBUtility.dprint( this, 182 "internalGetServant: servant already assigned to ID" ) ; 183 } 184 185 entry.incarnateFailure() ; 186 throw poa.invocationWrapper().poaServantNotUnique() ; 187 } 188 } 189 190 if (poa.getDebug()) { 191 ORBUtility.dprint( this, 192 "internalGetServant: incarnate complete" ) ; 193 } 194 195 entry.incarnateComplete() ; 196 activateServant(key, entry, (Servant )servant); 197 } 198 } 199 200 return servant ; 201 } finally { 202 if (poa.getDebug()) { 203 ORBUtility.dprint( this, 204 "Exiting POAPolicyMediatorImpl_R_USM.internalGetServant " + 205 "for poa " + poa ) ; 206 } 207 } 208 } 209 210 public void returnServant() 211 { 212 OAInvocationInfo info = orb.peekInvocationInfo(); 213 byte[] id = info.id() ; 214 ActiveObjectMap.Key key = new ActiveObjectMap.Key( id ) ; 215 AOMEntry entry = activeObjectMap.get( key ) ; 216 entry.exit() ; 217 } 218 219 public void etherealizeAll() 220 { 221 if (activator != null) { 222 Set keySet = activeObjectMap.keySet() ; 223 224 ActiveObjectMap.Key[] keys = 227 (ActiveObjectMap.Key[])keySet.toArray( 228 new ActiveObjectMap.Key[ keySet.size() ] ) ; 229 230 for (int ctr=0; ctr<keySet.size(); ctr++) { 231 ActiveObjectMap.Key key = keys[ctr] ; 232 AOMEntry entry = activeObjectMap.get( key ) ; 233 Servant servant = activeObjectMap.getServant( entry ) ; 234 if (servant != null) { 235 boolean remainingActivations = 236 activeObjectMap.hasMultipleIDs(entry) ; 237 238 entry.startEtherealize( null ) ; 244 try { 245 poa.unlock() ; 246 try { 247 activator.etherealize(key.id, poa, servant, true, 248 remainingActivations); 249 } catch (Exception exc) { 250 } 252 } finally { 253 poa.lock() ; 254 entry.etherealizeComplete() ; 255 } 256 } 257 } 258 } 259 } 260 261 public ServantManager getServantManager() throws WrongPolicy 262 { 263 return activator; 264 } 265 266 public void setServantManager( 267 ServantManager servantManager ) throws WrongPolicy 268 { 269 if (activator != null) 270 throw poa.invocationWrapper().servantManagerAlreadySet() ; 271 272 if (servantManager instanceof ServantActivator ) 273 activator = (ServantActivator )servantManager; 274 else 275 throw poa.invocationWrapper().servantManagerBadType() ; 276 } 277 278 public Servant getDefaultServant() throws NoServant , WrongPolicy 279 { 280 throw new WrongPolicy (); 281 } 282 283 public void setDefaultServant( Servant servant ) throws WrongPolicy 284 { 285 throw new WrongPolicy (); 286 } 287 288 class Etherealizer extends Thread { 289 private POAPolicyMediatorImpl_R_USM mediator ; 290 private ActiveObjectMap.Key key ; 291 private AOMEntry entry ; 292 private Servant servant ; 293 private boolean debug ; 294 295 public Etherealizer( POAPolicyMediatorImpl_R_USM mediator, 296 ActiveObjectMap.Key key, AOMEntry entry, Servant servant, 297 boolean debug ) 298 { 299 this.mediator = mediator ; 300 this.key = key ; 301 this.entry = entry; 302 this.servant = servant; 303 this.debug = debug ; 304 } 305 306 public void run() { 307 if (debug) { 308 ORBUtility.dprint( this, "Calling Etherealizer.run on key " + 309 key ) ; 310 } 311 312 try { 313 try { 314 mediator.activator.etherealize( key.id, mediator.poa, servant, 315 false, mediator.activeObjectMap.hasMultipleIDs( entry ) ); 316 } catch (Exception exc) { 317 } 319 320 try { 321 mediator.poa.lock() ; 322 323 entry.etherealizeComplete() ; 324 mediator.activeObjectMap.remove( key ) ; 325 326 POAManagerImpl pm = (POAManagerImpl)mediator.poa.the_POAManager() ; 327 POAFactory factory = pm.getFactory() ; 328 factory.unregisterPOAForServant( mediator.poa, servant); 329 } finally { 330 mediator.poa.unlock() ; 331 } 332 } finally { 333 if (debug) { 334 ORBUtility.dprint( this, "Exiting Etherealizer.run" ) ; 335 } 336 } 337 } 338 } 339 340 public void deactivateHelper( ActiveObjectMap.Key key, AOMEntry entry, 341 Servant servant ) throws ObjectNotActive , WrongPolicy 342 { 343 if (activator == null) 344 throw poa.invocationWrapper().poaNoServantManager() ; 345 346 Etherealizer eth = new Etherealizer( this, key, entry, servant, poa.getDebug() ) ; 347 entry.startEtherealize( eth ) ; 348 } 349 350 public Servant idToServant( byte[] id ) 351 throws WrongPolicy , ObjectNotActive 352 { 353 ActiveObjectMap.Key key = new ActiveObjectMap.Key( id ) ; 354 AOMEntry entry = activeObjectMap.get(key); 355 356 Servant servant = activeObjectMap.getServant( entry ) ; 357 if (servant != null) 358 return servant ; 359 else 360 throw new ObjectNotActive () ; 361 } 362 } 363 | Popular Tags |