1 7 8 package com.sun.corba.se.impl.oa.poa ; 9 10 import org.omg.PortableServer.Servant ; 11 12 import org.omg.PortableServer.POAPackage.WrongPolicy ; 13 import org.omg.PortableServer.POAPackage.ServantNotActive ; 14 import org.omg.PortableServer.POAPackage.ServantAlreadyActive ; 15 import org.omg.PortableServer.POAPackage.ObjectNotActive ; 16 import org.omg.PortableServer.POAPackage.ObjectAlreadyActive ; 17 18 import com.sun.corba.se.impl.orbutil.concurrent.SyncUtil ; 19 20 import com.sun.corba.se.impl.orbutil.ORBUtility ; 21 import com.sun.corba.se.impl.orbutil.ORBConstants ; 22 23 import com.sun.corba.se.impl.javax.rmi.CORBA.Util ; 24 25 import com.sun.corba.se.impl.oa.NullServantImpl ; 26 27 public abstract class POAPolicyMediatorBase_R extends POAPolicyMediatorBase { 28 protected ActiveObjectMap activeObjectMap ; 29 30 POAPolicyMediatorBase_R( Policies policies, POAImpl poa ) 31 { 32 super( policies, poa ) ; 33 34 if (!policies.retainServants()) 36 throw poa.invocationWrapper().policyMediatorBadPolicyInFactory() ; 37 38 activeObjectMap = ActiveObjectMap.create(poa, !isUnique); 39 } 40 41 public void returnServant() 42 { 43 } 45 46 public void clearAOM() 47 { 48 activeObjectMap.clear() ; 49 activeObjectMap = null ; 50 } 51 52 protected Servant internalKeyToServant( ActiveObjectMap.Key key ) 53 { 54 AOMEntry entry = activeObjectMap.get(key); 55 if (entry == null) 56 return null ; 57 58 return activeObjectMap.getServant( entry ) ; 59 } 60 61 protected Servant internalIdToServant( byte[] id ) 62 { 63 ActiveObjectMap.Key key = new ActiveObjectMap.Key( id ) ; 64 return internalKeyToServant( key ) ; 65 } 66 67 protected void activateServant( ActiveObjectMap.Key key, AOMEntry entry, Servant servant ) 68 { 69 setDelegate(servant, key.id ); 70 71 if (orb.shutdownDebugFlag) { 72 System.out.println("Activating object " + servant + 73 " with POA " + poa); 74 } 75 76 activeObjectMap.putServant( servant, entry ) ; 77 78 if (Util.instance != null) { 79 POAManagerImpl pm = (POAManagerImpl)poa.the_POAManager() ; 80 POAFactory factory = pm.getFactory() ; 81 factory.registerPOAForServant(poa, servant); 82 } 83 } 84 85 public final void activateObject(byte[] id, Servant servant) 86 throws WrongPolicy , ServantAlreadyActive , ObjectAlreadyActive 87 { 88 if (isUnique && activeObjectMap.contains(servant)) 89 throw new ServantAlreadyActive (); 90 ActiveObjectMap.Key key = new ActiveObjectMap.Key( id ) ; 91 92 if (activeObjectMap.containsKey(key)) 96 throw new ObjectAlreadyActive () ; 97 98 AOMEntry entry = activeObjectMap.get( key ) ; 99 entry.activateObject() ; 100 activateServant( key, entry, servant ) ; 101 } 102 103 public Servant deactivateObject( byte[] id ) 104 throws ObjectNotActive , WrongPolicy 105 { 106 ActiveObjectMap.Key key = new ActiveObjectMap.Key( id ) ; 107 return deactivateObject( key ) ; 108 } 109 110 protected void deactivateHelper( ActiveObjectMap.Key key, AOMEntry entry, 111 Servant s ) throws ObjectNotActive , WrongPolicy 112 { 113 116 activeObjectMap.remove(key); 117 118 if (Util.instance != null) { 119 POAManagerImpl pm = (POAManagerImpl)poa.the_POAManager() ; 120 POAFactory factory = pm.getFactory() ; 121 factory.unregisterPOAForServant(poa, s); 122 } 123 } 124 125 public Servant deactivateObject( ActiveObjectMap.Key key ) 126 throws ObjectNotActive , WrongPolicy 127 { 128 if (orb.poaDebugFlag) { 129 ORBUtility.dprint( this, 130 "Calling deactivateObject for key " + key ) ; 131 } 132 133 try { 134 AOMEntry entry = activeObjectMap.get(key); 135 if (entry == null) 136 throw new ObjectNotActive (); 137 138 Servant s = activeObjectMap.getServant( entry ) ; 139 if (s == null) 140 throw new ObjectNotActive (); 141 142 if (orb.poaDebugFlag) { 143 System.out.println("Deactivating object " + s + " with POA " + poa); 144 } 145 146 deactivateHelper( key, entry, s ) ; 147 148 return s ; 149 } finally { 150 if (orb.poaDebugFlag) { 151 ORBUtility.dprint( this, 152 "Exiting deactivateObject" ) ; 153 } 154 } 155 } 156 157 public byte[] servantToId( Servant servant ) throws ServantNotActive , WrongPolicy 158 { 159 161 if (!isUnique && !isImplicit) 162 throw new WrongPolicy (); 163 164 if (isUnique) { 165 ActiveObjectMap.Key key = activeObjectMap.getKey(servant); 166 if (key != null) 167 return key.id ; 168 } 169 170 172 if (isImplicit) 173 try { 174 byte[] id = newSystemId() ; 175 activateObject( id, servant ) ; 176 return id ; 177 } catch (ObjectAlreadyActive oaa) { 178 throw poa.invocationWrapper().servantToIdOaa( oaa ) ; 180 } catch (ServantAlreadyActive s) { 181 throw poa.invocationWrapper().servantToIdSaa( s ) ; 182 } catch (WrongPolicy w) { 183 throw poa.invocationWrapper().servantToIdWp( w ) ; 184 } 185 186 throw new ServantNotActive (); 187 } 188 } 189 190 | Popular Tags |