src/share/classes/com/sun/corba/se/impl/oa/poa/POAPolicyMediatorBase_R.java

Wed, 28 Mar 2012 02:50:50 -0700

author
mbankal
date
Wed, 28 Mar 2012 02:50:50 -0700
changeset 371
e324dfb90c9e
parent 230
34af2070439b
child 748
6845b95cba6b
permissions
-rw-r--r--

7079902: Refine CORBA data models
Reviewed-by: coffeys

duke@1 1 /*
mbankal@371 2 * Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
duke@1 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1 4 *
duke@1 5 * This code is free software; you can redistribute it and/or modify it
duke@1 6 * under the terms of the GNU General Public License version 2 only, as
ohair@158 7 * published by the Free Software Foundation. Oracle designates this
duke@1 8 * particular file as subject to the "Classpath" exception as provided
ohair@158 9 * by Oracle in the LICENSE file that accompanied this code.
duke@1 10 *
duke@1 11 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1 14 * version 2 for more details (a copy is included in the LICENSE file that
duke@1 15 * accompanied this code).
duke@1 16 *
duke@1 17 * You should have received a copy of the GNU General Public License version
duke@1 18 * 2 along with this work; if not, write to the Free Software Foundation,
duke@1 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1 20 *
ohair@158 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@158 22 * or visit www.oracle.com if you need additional information or have any
ohair@158 23 * questions.
duke@1 24 */
duke@1 25
duke@1 26 package com.sun.corba.se.impl.oa.poa ;
duke@1 27
duke@1 28 import org.omg.PortableServer.Servant ;
duke@1 29
duke@1 30 import org.omg.PortableServer.POAPackage.WrongPolicy ;
duke@1 31 import org.omg.PortableServer.POAPackage.ServantNotActive ;
duke@1 32 import org.omg.PortableServer.POAPackage.ServantAlreadyActive ;
duke@1 33 import org.omg.PortableServer.POAPackage.ObjectNotActive ;
duke@1 34 import org.omg.PortableServer.POAPackage.ObjectAlreadyActive ;
duke@1 35
duke@1 36 import com.sun.corba.se.impl.orbutil.concurrent.SyncUtil ;
duke@1 37
duke@1 38 import com.sun.corba.se.impl.orbutil.ORBUtility ;
duke@1 39 import com.sun.corba.se.impl.orbutil.ORBConstants ;
duke@1 40
duke@1 41 import com.sun.corba.se.impl.javax.rmi.CORBA.Util ;
duke@1 42
duke@1 43 import com.sun.corba.se.impl.oa.NullServantImpl ;
duke@1 44
duke@1 45 public abstract class POAPolicyMediatorBase_R extends POAPolicyMediatorBase {
duke@1 46 protected ActiveObjectMap activeObjectMap ;
duke@1 47
duke@1 48 POAPolicyMediatorBase_R( Policies policies, POAImpl poa )
duke@1 49 {
duke@1 50 super( policies, poa ) ;
duke@1 51
duke@1 52 // assert policies.retainServants() && policies.useActiveObjectMapOnly()
duke@1 53 if (!policies.retainServants())
duke@1 54 throw poa.invocationWrapper().policyMediatorBadPolicyInFactory() ;
duke@1 55
duke@1 56 activeObjectMap = ActiveObjectMap.create(poa, !isUnique);
duke@1 57 }
duke@1 58
duke@1 59 public void returnServant()
duke@1 60 {
duke@1 61 // NO-OP
duke@1 62 }
duke@1 63
duke@1 64 public void clearAOM()
duke@1 65 {
duke@1 66 activeObjectMap.clear() ;
duke@1 67 activeObjectMap = null ;
duke@1 68 }
duke@1 69
duke@1 70 protected Servant internalKeyToServant( ActiveObjectMap.Key key )
duke@1 71 {
duke@1 72 AOMEntry entry = activeObjectMap.get(key);
duke@1 73 if (entry == null)
duke@1 74 return null ;
duke@1 75
duke@1 76 return activeObjectMap.getServant( entry ) ;
duke@1 77 }
duke@1 78
duke@1 79 protected Servant internalIdToServant( byte[] id )
duke@1 80 {
duke@1 81 ActiveObjectMap.Key key = new ActiveObjectMap.Key( id ) ;
duke@1 82 return internalKeyToServant( key ) ;
duke@1 83 }
duke@1 84
duke@1 85 protected void activateServant( ActiveObjectMap.Key key, AOMEntry entry, Servant servant )
duke@1 86 {
duke@1 87 setDelegate(servant, key.id );
duke@1 88
duke@1 89 if (orb.shutdownDebugFlag) {
duke@1 90 System.out.println("Activating object " + servant +
duke@1 91 " with POA " + poa);
duke@1 92 }
duke@1 93
duke@1 94 activeObjectMap.putServant( servant, entry ) ;
duke@1 95
mbankal@371 96 if (Util.isInstanceDefined()) {
duke@1 97 POAManagerImpl pm = (POAManagerImpl)poa.the_POAManager() ;
duke@1 98 POAFactory factory = pm.getFactory() ;
duke@1 99 factory.registerPOAForServant(poa, servant);
duke@1 100 }
duke@1 101 }
duke@1 102
duke@1 103 public final void activateObject(byte[] id, Servant servant)
duke@1 104 throws WrongPolicy, ServantAlreadyActive, ObjectAlreadyActive
duke@1 105 {
duke@1 106 if (isUnique && activeObjectMap.contains(servant))
duke@1 107 throw new ServantAlreadyActive();
duke@1 108 ActiveObjectMap.Key key = new ActiveObjectMap.Key( id ) ;
duke@1 109
skoppar@230 110 AOMEntry entry = activeObjectMap.get( key ) ;
duke@1 111
skoppar@230 112 // Check for an ObjectAlreadyActive error
duke@1 113 entry.activateObject() ;
duke@1 114 activateServant( key, entry, servant ) ;
duke@1 115 }
duke@1 116
duke@1 117 public Servant deactivateObject( byte[] id )
duke@1 118 throws ObjectNotActive, WrongPolicy
duke@1 119 {
duke@1 120 ActiveObjectMap.Key key = new ActiveObjectMap.Key( id ) ;
duke@1 121 return deactivateObject( key ) ;
duke@1 122 }
duke@1 123
duke@1 124 protected void deactivateHelper( ActiveObjectMap.Key key, AOMEntry entry,
duke@1 125 Servant s ) throws ObjectNotActive, WrongPolicy
duke@1 126 {
duke@1 127 // Default does nothing, but the USE_SERVANT_MANAGER case
duke@1 128 // must handle etherealization
duke@1 129
duke@1 130 activeObjectMap.remove(key);
duke@1 131
mbankal@371 132 if (Util.isInstanceDefined()) {
duke@1 133 POAManagerImpl pm = (POAManagerImpl)poa.the_POAManager() ;
duke@1 134 POAFactory factory = pm.getFactory() ;
duke@1 135 factory.unregisterPOAForServant(poa, s);
duke@1 136 }
duke@1 137 }
duke@1 138
duke@1 139 public Servant deactivateObject( ActiveObjectMap.Key key )
duke@1 140 throws ObjectNotActive, WrongPolicy
duke@1 141 {
duke@1 142 if (orb.poaDebugFlag) {
duke@1 143 ORBUtility.dprint( this,
duke@1 144 "Calling deactivateObject for key " + key ) ;
duke@1 145 }
duke@1 146
duke@1 147 try {
duke@1 148 AOMEntry entry = activeObjectMap.get(key);
duke@1 149 if (entry == null)
duke@1 150 throw new ObjectNotActive();
duke@1 151
duke@1 152 Servant s = activeObjectMap.getServant( entry ) ;
duke@1 153 if (s == null)
duke@1 154 throw new ObjectNotActive();
duke@1 155
duke@1 156 if (orb.poaDebugFlag) {
duke@1 157 System.out.println("Deactivating object " + s + " with POA " + poa);
duke@1 158 }
duke@1 159
duke@1 160 deactivateHelper( key, entry, s ) ;
duke@1 161
duke@1 162 return s ;
duke@1 163 } finally {
duke@1 164 if (orb.poaDebugFlag) {
duke@1 165 ORBUtility.dprint( this,
duke@1 166 "Exiting deactivateObject" ) ;
duke@1 167 }
duke@1 168 }
duke@1 169 }
duke@1 170
duke@1 171 public byte[] servantToId( Servant servant ) throws ServantNotActive, WrongPolicy
duke@1 172 {
duke@1 173 // XXX needs to handle call from an invocation on this POA
duke@1 174
duke@1 175 if (!isUnique && !isImplicit)
duke@1 176 throw new WrongPolicy();
duke@1 177
duke@1 178 if (isUnique) {
duke@1 179 ActiveObjectMap.Key key = activeObjectMap.getKey(servant);
duke@1 180 if (key != null)
duke@1 181 return key.id ;
duke@1 182 }
duke@1 183
duke@1 184 // assert !isUnique || (servant not in activateObjectMap)
duke@1 185
duke@1 186 if (isImplicit)
duke@1 187 try {
duke@1 188 byte[] id = newSystemId() ;
duke@1 189 activateObject( id, servant ) ;
duke@1 190 return id ;
duke@1 191 } catch (ObjectAlreadyActive oaa) {
duke@1 192 // This can't occur here, since id is always brand new.
duke@1 193 throw poa.invocationWrapper().servantToIdOaa( oaa ) ;
duke@1 194 } catch (ServantAlreadyActive s) {
duke@1 195 throw poa.invocationWrapper().servantToIdSaa( s ) ;
duke@1 196 } catch (WrongPolicy w) {
duke@1 197 throw poa.invocationWrapper().servantToIdWp( w ) ;
duke@1 198 }
duke@1 199
duke@1 200 throw new ServantNotActive();
duke@1 201 }
duke@1 202 }

mercurial