KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * @(#)POAPolicyMediatorBase.java 1.42 03/12/19
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 java.util.Collection JavaDoc;
11 import java.util.Enumeration JavaDoc ;
12
13 import org.omg.PortableServer.Servant JavaDoc ;
14 import org.omg.PortableServer.ForwardRequest JavaDoc ;
15 import org.omg.PortableServer.POAPackage.WrongPolicy JavaDoc ;
16
17 import com.sun.corba.se.spi.extension.ServantCachingPolicy ;
18 import com.sun.corba.se.spi.orb.ORB ;
19 import com.sun.corba.se.spi.transport.SocketOrChannelAcceptor;
20
21 import com.sun.corba.se.impl.orbutil.ORBConstants ;
22 import com.sun.corba.se.impl.orbutil.ORBUtility ;
23 import com.sun.corba.se.impl.orbutil.concurrent.SyncUtil ;
24
25
26 /** Implementation of POARequesHandler that provides policy specific
27  * operations on the POA.
28  */

29 public abstract class POAPolicyMediatorBase implements POAPolicyMediator {
30     protected POAImpl poa ;
31     protected ORB orb ;
32
33     private int sysIdCounter ;
34     private Policies policies ;
35     private DelegateImpl delegateImpl ;
36
37     private int serverid ;
38     private int scid ;
39
40     protected boolean isImplicit ;
41     protected boolean isUnique ;
42     protected boolean isSystemId ;
43
44     public final Policies getPolicies()
45     {
46     return policies ;
47     }
48
49     public final int getScid()
50     {
51     return scid ;
52     }
53
54     public final int getServerId()
55     {
56     return serverid ;
57     }
58
59     POAPolicyMediatorBase( Policies policies, POAImpl poa )
60     {
61     if (policies.isSingleThreaded())
62         throw poa.invocationWrapper().singleThreadNotSupported() ;
63
64     POAManagerImpl poam = (POAManagerImpl)(poa.the_POAManager()) ;
65     POAFactory poaf = poam.getFactory() ;
66     delegateImpl = (DelegateImpl)(poaf.getDelegateImpl()) ;
67     this.policies = policies ;
68     this.poa = poa ;
69     orb = (ORB)poa.getORB() ;
70
71     switch (policies.servantCachingLevel()) {
72         case ServantCachingPolicy.NO_SERVANT_CACHING :
73         scid = ORBConstants.TRANSIENT_SCID ;
74         break ;
75         case ServantCachingPolicy.FULL_SEMANTICS :
76         scid = ORBConstants.SC_TRANSIENT_SCID ;
77         break ;
78         case ServantCachingPolicy.INFO_ONLY_SEMANTICS :
79         scid = ORBConstants.IISC_TRANSIENT_SCID ;
80         break ;
81         case ServantCachingPolicy.MINIMAL_SEMANTICS :
82         scid = ORBConstants.MINSC_TRANSIENT_SCID ;
83         break ;
84     }
85
86     if ( policies.isTransient() ) {
87         serverid = orb.getTransientServerId();
88     } else {
89         serverid = orb.getORBData().getPersistentServerId();
90         scid = ORBConstants.makePersistent( scid ) ;
91     }
92
93     isImplicit = policies.isImplicitlyActivated() ;
94     isUnique = policies.isUniqueIds() ;
95     isSystemId = policies.isSystemAssignedIds() ;
96
97     sysIdCounter = 0 ;
98     }
99     
100     public final java.lang.Object JavaDoc getInvocationServant( byte[] id,
101         String JavaDoc operation ) throws ForwardRequest JavaDoc
102     {
103     java.lang.Object JavaDoc result = internalGetServant( id, operation ) ;
104
105     return result ;
106     }
107
108     // Create a delegate and stick it in the servant.
109
// This delegate is needed during dispatch for the ObjectImpl._orb()
110
// method to work.
111
protected final void setDelegate(Servant JavaDoc servant, byte[] id)
112     {
113         //This new servant delegate no longer needs the id for
114
// its initialization.
115
servant._set_delegate(delegateImpl);
116     }
117
118     public synchronized byte[] newSystemId() throws WrongPolicy JavaDoc
119     {
120     if (!isSystemId)
121         throw new WrongPolicy JavaDoc() ;
122
123     byte[] array = new byte[8];
124     ORBUtility.intToBytes(++sysIdCounter, array, 0);
125     ORBUtility.intToBytes( poa.getPOAId(), array, 4);
126     return array;
127     }
128
129     protected abstract java.lang.Object JavaDoc internalGetServant( byte[] id,
130     String JavaDoc operation ) throws ForwardRequest JavaDoc ;
131 }
132
Popular Tags