KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > oa > poa > POAPolicyMediatorBase_R


1 /*
2  * @(#)POAPolicyMediatorBase_R.java 1.24 04/03/01
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.corba.se.impl.oa.poa ;
9
10 import org.omg.PortableServer.Servant JavaDoc ;
11
12 import org.omg.PortableServer.POAPackage.WrongPolicy JavaDoc ;
13 import org.omg.PortableServer.POAPackage.ServantNotActive JavaDoc ;
14 import org.omg.PortableServer.POAPackage.ServantAlreadyActive JavaDoc ;
15 import org.omg.PortableServer.POAPackage.ObjectNotActive JavaDoc ;
16 import org.omg.PortableServer.POAPackage.ObjectAlreadyActive JavaDoc ;
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     // assert policies.retainServants() && policies.useActiveObjectMapOnly()
35
if (!policies.retainServants())
36         throw poa.invocationWrapper().policyMediatorBadPolicyInFactory() ;
37
38         activeObjectMap = ActiveObjectMap.create(poa, !isUnique);
39     }
40     
41     public void returnServant()
42     {
43     // NO-OP
44
}
45
46     public void clearAOM()
47     {
48     activeObjectMap.clear() ;
49     activeObjectMap = null ;
50     }
51
52     protected Servant JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc servant)
86     throws WrongPolicy JavaDoc, ServantAlreadyActive JavaDoc, ObjectAlreadyActive JavaDoc
87     {
88     if (isUnique && activeObjectMap.contains(servant))
89         throw new ServantAlreadyActive JavaDoc();
90     ActiveObjectMap.Key key = new ActiveObjectMap.Key( id ) ;
91
92     // Note that this can't happen for system assigned IDs since the
93
// POA never hands out the same ID. However, we make this redundant
94
// check here to share the code.
95
if (activeObjectMap.containsKey(key))
96         throw new ObjectAlreadyActive JavaDoc() ;
97
98     AOMEntry entry = activeObjectMap.get( key ) ;
99     entry.activateObject() ;
100     activateServant( key, entry, servant ) ;
101     }
102     
103     public Servant JavaDoc deactivateObject( byte[] id )
104     throws ObjectNotActive JavaDoc, WrongPolicy JavaDoc
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 JavaDoc s ) throws ObjectNotActive JavaDoc, WrongPolicy JavaDoc
112     {
113     // Default does nothing, but the USE_SERVANT_MANAGER case
114
// must handle etherealization
115

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 JavaDoc deactivateObject( ActiveObjectMap.Key key )
126     throws ObjectNotActive JavaDoc, WrongPolicy JavaDoc
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 JavaDoc();
137
138         Servant JavaDoc s = activeObjectMap.getServant( entry ) ;
139         if (s == null)
140         throw new ObjectNotActive JavaDoc();
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 JavaDoc servant ) throws ServantNotActive JavaDoc, WrongPolicy JavaDoc
158     {
159     // XXX needs to handle call from an invocation on this POA
160

161     if (!isUnique && !isImplicit)
162         throw new WrongPolicy JavaDoc();
163
164     if (isUnique) {
165         ActiveObjectMap.Key key = activeObjectMap.getKey(servant);
166         if (key != null)
167         return key.id ;
168     }
169
170     // assert !isUnique || (servant not in activateObjectMap)
171

172     if (isImplicit)
173         try {
174         byte[] id = newSystemId() ;
175         activateObject( id, servant ) ;
176         return id ;
177         } catch (ObjectAlreadyActive JavaDoc oaa) {
178         // This can't occur here, since id is always brand new.
179
throw poa.invocationWrapper().servantToIdOaa( oaa ) ;
180         } catch (ServantAlreadyActive JavaDoc s) {
181         throw poa.invocationWrapper().servantToIdSaa( s ) ;
182         } catch (WrongPolicy JavaDoc w) {
183         throw poa.invocationWrapper().servantToIdWp( w ) ;
184         }
185
186     throw new ServantNotActive JavaDoc();
187     }
188 }
189
190
Popular Tags