POAPolicyMediatorBase.java revision 608:7e06bf1dcb09
1/*
2 * Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package com.sun.corba.se.impl.oa.poa ;
27
28import java.util.Collection;
29import java.util.Enumeration ;
30
31import org.omg.PortableServer.Servant ;
32import org.omg.PortableServer.ForwardRequest ;
33import org.omg.PortableServer.POAPackage.WrongPolicy ;
34
35import com.sun.corba.se.spi.extension.ServantCachingPolicy ;
36import com.sun.corba.se.spi.orb.ORB ;
37import com.sun.corba.se.spi.transport.SocketOrChannelAcceptor;
38
39import com.sun.corba.se.impl.orbutil.ORBConstants ;
40import com.sun.corba.se.impl.orbutil.ORBUtility ;
41import com.sun.corba.se.impl.orbutil.concurrent.SyncUtil ;
42
43
44/** Implementation of POARequesHandler that provides policy specific
45 * operations on the POA.
46 */
47public abstract class POAPolicyMediatorBase implements POAPolicyMediator {
48    protected POAImpl poa ;
49    protected ORB orb ;
50
51    private int sysIdCounter ;
52    private Policies policies ;
53    private DelegateImpl delegateImpl ;
54
55    private int serverid ;
56    private int scid ;
57
58    protected boolean isImplicit ;
59    protected boolean isUnique ;
60    protected boolean isSystemId ;
61
62    public final Policies getPolicies()
63    {
64        return policies ;
65    }
66
67    public final int getScid()
68    {
69        return scid ;
70    }
71
72    public final int getServerId()
73    {
74        return serverid ;
75    }
76
77    POAPolicyMediatorBase( Policies policies, POAImpl poa )
78    {
79        if (policies.isSingleThreaded())
80            throw poa.invocationWrapper().singleThreadNotSupported() ;
81
82        POAManagerImpl poam = (POAManagerImpl)(poa.the_POAManager()) ;
83        POAFactory poaf = poam.getFactory() ;
84        delegateImpl = (DelegateImpl)(poaf.getDelegateImpl()) ;
85        this.policies = policies ;
86        this.poa = poa ;
87        orb = (ORB)poa.getORB() ;
88
89        switch (policies.servantCachingLevel()) {
90            case ServantCachingPolicy.NO_SERVANT_CACHING :
91                scid = ORBConstants.TRANSIENT_SCID ;
92                break ;
93            case ServantCachingPolicy.FULL_SEMANTICS :
94                scid = ORBConstants.SC_TRANSIENT_SCID ;
95                break ;
96            case ServantCachingPolicy.INFO_ONLY_SEMANTICS :
97                scid = ORBConstants.IISC_TRANSIENT_SCID ;
98                break ;
99            case ServantCachingPolicy.MINIMAL_SEMANTICS :
100                scid = ORBConstants.MINSC_TRANSIENT_SCID ;
101                break ;
102        }
103
104        if ( policies.isTransient() ) {
105            serverid = orb.getTransientServerId();
106        } else {
107            serverid = orb.getORBData().getPersistentServerId();
108            scid = ORBConstants.makePersistent( scid ) ;
109        }
110
111        isImplicit = policies.isImplicitlyActivated() ;
112        isUnique = policies.isUniqueIds() ;
113        isSystemId = policies.isSystemAssignedIds() ;
114
115        sysIdCounter = 0 ;
116    }
117
118    public final java.lang.Object getInvocationServant( byte[] id,
119        String operation ) throws ForwardRequest
120    {
121        java.lang.Object result = internalGetServant( id, operation ) ;
122
123        return result ;
124    }
125
126    // Create a delegate and stick it in the servant.
127    // This delegate is needed during dispatch for the ObjectImpl._orb()
128    // method to work.
129    protected final void setDelegate(Servant servant, byte[] id)
130    {
131        //This new servant delegate no longer needs the id for
132        // its initialization.
133        servant._set_delegate(delegateImpl);
134    }
135
136    public synchronized byte[] newSystemId() throws WrongPolicy
137    {
138        if (!isSystemId)
139            throw new WrongPolicy() ;
140
141        byte[] array = new byte[8];
142        ORBUtility.intToBytes(++sysIdCounter, array, 0);
143        ORBUtility.intToBytes( poa.getPOAId(), array, 4);
144        return array;
145    }
146
147    protected abstract  java.lang.Object internalGetServant( byte[] id,
148        String operation ) throws ForwardRequest ;
149}
150