corba/src/java.corba/share/classes/com/sun/corba/se/impl/oa/poa/POAPolicyMediatorImpl_R_USM.java
author chegar
Tue, 19 Apr 2016 14:34:43 +0100
changeset 37620 230612715768
parent 33680 56aa0b79bf5a
permissions -rw-r--r--
8148863: Remove sun.misc.ManagedLocalsThread from corba Reviewed-by: alanb, coffeys, msheppar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     1
/*
29937
c774371adf92 8048997: Enhance thread contexts in CORBA
msheppar
parents: 25862
diff changeset
     2
 * Copyright (c) 2002, 2015, Oracle and/or its affiliates. All rights reserved.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
02bb8761fcce Initial load
duke
parents:
diff changeset
     4
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
02bb8761fcce Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    10
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
02bb8761fcce Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
02bb8761fcce Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
02bb8761fcce Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
02bb8761fcce Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
02bb8761fcce Initial load
duke
parents:
diff changeset
    16
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
02bb8761fcce Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
02bb8761fcce Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
02bb8761fcce Initial load
duke
parents:
diff changeset
    20
 *
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    23
 * questions.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    24
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    25
02bb8761fcce Initial load
duke
parents:
diff changeset
    26
package com.sun.corba.se.impl.oa.poa ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    27
02bb8761fcce Initial load
duke
parents:
diff changeset
    28
import java.util.Set ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    29
import org.omg.CORBA.SystemException ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    30
02bb8761fcce Initial load
duke
parents:
diff changeset
    31
import org.omg.PortableServer.ServantActivator ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    32
import org.omg.PortableServer.Servant ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    33
import org.omg.PortableServer.ServantManager ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    34
import org.omg.PortableServer.ForwardRequest ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    35
import org.omg.PortableServer.POAPackage.WrongPolicy ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    36
import org.omg.PortableServer.POAPackage.ObjectNotActive ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    37
import org.omg.PortableServer.POAPackage.ServantNotActive ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    38
import org.omg.PortableServer.POAPackage.ObjectAlreadyActive ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    39
import org.omg.PortableServer.POAPackage.ServantAlreadyActive ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    40
import org.omg.PortableServer.POAPackage.NoServant ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    41
02bb8761fcce Initial load
duke
parents:
diff changeset
    42
import com.sun.corba.se.impl.orbutil.concurrent.SyncUtil ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    43
import com.sun.corba.se.impl.orbutil.ORBUtility ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    44
import com.sun.corba.se.impl.orbutil.ORBConstants ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    45
02bb8761fcce Initial load
duke
parents:
diff changeset
    46
import com.sun.corba.se.impl.oa.NullServantImpl ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    47
02bb8761fcce Initial load
duke
parents:
diff changeset
    48
import com.sun.corba.se.impl.javax.rmi.CORBA.Util ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    49
02bb8761fcce Initial load
duke
parents:
diff changeset
    50
import com.sun.corba.se.spi.oa.OAInvocationInfo ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    51
import com.sun.corba.se.spi.oa.NullServant ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    52
02bb8761fcce Initial load
duke
parents:
diff changeset
    53
/** Implementation of POARequesHandler that provides policy specific
02bb8761fcce Initial load
duke
parents:
diff changeset
    54
 * operations on the POA.
02bb8761fcce Initial load
duke
parents:
diff changeset
    55
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    56
public class POAPolicyMediatorImpl_R_USM extends POAPolicyMediatorBase_R {
02bb8761fcce Initial load
duke
parents:
diff changeset
    57
    protected ServantActivator activator ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    58
02bb8761fcce Initial load
duke
parents:
diff changeset
    59
    POAPolicyMediatorImpl_R_USM( Policies policies, POAImpl poa )
02bb8761fcce Initial load
duke
parents:
diff changeset
    60
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
    61
        // assert policies.retainServants()
02bb8761fcce Initial load
duke
parents:
diff changeset
    62
        super( policies, poa ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    63
        activator = null ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    64
02bb8761fcce Initial load
duke
parents:
diff changeset
    65
        if (!policies.useServantManager())
02bb8761fcce Initial load
duke
parents:
diff changeset
    66
            throw poa.invocationWrapper().policyMediatorBadPolicyInFactory() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    67
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
    68
02bb8761fcce Initial load
duke
parents:
diff changeset
    69
    /* This handles a rather subtle bug (4939892).  The problem is that
02bb8761fcce Initial load
duke
parents:
diff changeset
    70
     * enter will wait on the entry if it is being etherealized.  When the
02bb8761fcce Initial load
duke
parents:
diff changeset
    71
     * deferred state transition completes, the entry is no longer in the
02bb8761fcce Initial load
duke
parents:
diff changeset
    72
     * AOM, and so we need to get a new entry, otherwise activator.incarnate
02bb8761fcce Initial load
duke
parents:
diff changeset
    73
     * will be called twice, once for the old entry, and again when a new
02bb8761fcce Initial load
duke
parents:
diff changeset
    74
     * entry is created.  This fix also required extending the FSM StateEngine
02bb8761fcce Initial load
duke
parents:
diff changeset
    75
     * to allow actions to throw exceptions, and adding a new state in the
02bb8761fcce Initial load
duke
parents:
diff changeset
    76
     * AOMEntry FSM to detect this condition.
02bb8761fcce Initial load
duke
parents:
diff changeset
    77
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
    78
    private AOMEntry enterEntry( ActiveObjectMap.Key key )
02bb8761fcce Initial load
duke
parents:
diff changeset
    79
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
    80
        AOMEntry result = null ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    81
        boolean failed ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    82
        do {
02bb8761fcce Initial load
duke
parents:
diff changeset
    83
            failed = false ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    84
            result = activeObjectMap.get(key) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    85
02bb8761fcce Initial load
duke
parents:
diff changeset
    86
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
    87
                result.enter() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    88
            } catch (Exception exc) {
02bb8761fcce Initial load
duke
parents:
diff changeset
    89
                failed = true ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    90
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
    91
        } while (failed) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    92
02bb8761fcce Initial load
duke
parents:
diff changeset
    93
        return result ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    94
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
    95
02bb8761fcce Initial load
duke
parents:
diff changeset
    96
    protected java.lang.Object internalGetServant( byte[] id,
02bb8761fcce Initial load
duke
parents:
diff changeset
    97
        String operation ) throws ForwardRequest
02bb8761fcce Initial load
duke
parents:
diff changeset
    98
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
    99
        if (poa.getDebug()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   100
            ORBUtility.dprint( this,
02bb8761fcce Initial load
duke
parents:
diff changeset
   101
                "Calling POAPolicyMediatorImpl_R_USM.internalGetServant " +
02bb8761fcce Initial load
duke
parents:
diff changeset
   102
                "for poa " + poa + " operation=" + operation ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   103
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   104
02bb8761fcce Initial load
duke
parents:
diff changeset
   105
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   106
            ActiveObjectMap.Key key = new ActiveObjectMap.Key( id ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   107
            AOMEntry entry = enterEntry(key) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   108
            java.lang.Object servant = activeObjectMap.getServant( entry ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   109
            if (servant != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   110
                if (poa.getDebug()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   111
                    ORBUtility.dprint( this,
02bb8761fcce Initial load
duke
parents:
diff changeset
   112
                        "internalGetServant: servant already activated" ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   113
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   114
02bb8761fcce Initial load
duke
parents:
diff changeset
   115
                return servant ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   116
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   117
02bb8761fcce Initial load
duke
parents:
diff changeset
   118
            if (activator == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   119
                if (poa.getDebug()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   120
                    ORBUtility.dprint( this,
02bb8761fcce Initial load
duke
parents:
diff changeset
   121
                        "internalGetServant: no servant activator in POA" ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   122
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   123
02bb8761fcce Initial load
duke
parents:
diff changeset
   124
                entry.incarnateFailure() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   125
                throw poa.invocationWrapper().poaNoServantManager() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   126
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   127
02bb8761fcce Initial load
duke
parents:
diff changeset
   128
            // Drop the POA lock during the incarnate call and
02bb8761fcce Initial load
duke
parents:
diff changeset
   129
            // re-acquire it afterwards.  The entry state machine
02bb8761fcce Initial load
duke
parents:
diff changeset
   130
            // prevents more than one thread from executing the
02bb8761fcce Initial load
duke
parents:
diff changeset
   131
            // incarnate method at a time within the same POA.
02bb8761fcce Initial load
duke
parents:
diff changeset
   132
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   133
                if (poa.getDebug()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   134
                    ORBUtility.dprint( this,
02bb8761fcce Initial load
duke
parents:
diff changeset
   135
                        "internalGetServant: upcall to incarnate" ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   136
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   137
02bb8761fcce Initial load
duke
parents:
diff changeset
   138
                poa.unlock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   139
02bb8761fcce Initial load
duke
parents:
diff changeset
   140
                servant = activator.incarnate(id, poa);
02bb8761fcce Initial load
duke
parents:
diff changeset
   141
02bb8761fcce Initial load
duke
parents:
diff changeset
   142
                if (servant == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   143
                    servant = new NullServantImpl(
02bb8761fcce Initial load
duke
parents:
diff changeset
   144
                        poa.omgInvocationWrapper().nullServantReturned() ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   145
            } catch (ForwardRequest freq) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   146
                if (poa.getDebug()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   147
                    ORBUtility.dprint( this,
02bb8761fcce Initial load
duke
parents:
diff changeset
   148
                        "internalGetServant: incarnate threw ForwardRequest" ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   149
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   150
02bb8761fcce Initial load
duke
parents:
diff changeset
   151
                throw freq ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   152
            } catch (SystemException exc) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   153
                if (poa.getDebug()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   154
                    ORBUtility.dprint( this,
02bb8761fcce Initial load
duke
parents:
diff changeset
   155
                        "internalGetServant: incarnate threw SystemException " + exc ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   156
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   157
02bb8761fcce Initial load
duke
parents:
diff changeset
   158
                throw exc ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   159
            } catch (Throwable exc) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   160
                if (poa.getDebug()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   161
                    ORBUtility.dprint( this,
02bb8761fcce Initial load
duke
parents:
diff changeset
   162
                        "internalGetServant: incarnate threw Throwable " + exc ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   163
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   164
02bb8761fcce Initial load
duke
parents:
diff changeset
   165
                throw poa.invocationWrapper().poaServantActivatorLookupFailed(
02bb8761fcce Initial load
duke
parents:
diff changeset
   166
                    exc ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   167
            } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
   168
                poa.lock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   169
02bb8761fcce Initial load
duke
parents:
diff changeset
   170
                // servant == null means incarnate threw an exception,
02bb8761fcce Initial load
duke
parents:
diff changeset
   171
                // while servant instanceof NullServant means incarnate returned a
02bb8761fcce Initial load
duke
parents:
diff changeset
   172
                // null servant.  Either case is an incarnate failure to the
02bb8761fcce Initial load
duke
parents:
diff changeset
   173
                // entry state machine.
02bb8761fcce Initial load
duke
parents:
diff changeset
   174
                if ((servant == null) || (servant instanceof NullServant)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   175
                    if (poa.getDebug()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   176
                        ORBUtility.dprint( this,
02bb8761fcce Initial load
duke
parents:
diff changeset
   177
                            "internalGetServant: incarnate failed" ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   178
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   179
02bb8761fcce Initial load
duke
parents:
diff changeset
   180
                    // XXX Does the AOM leak in this case? Yes,
02bb8761fcce Initial load
duke
parents:
diff changeset
   181
                    // but the problem is hard to fix.  There may be
02bb8761fcce Initial load
duke
parents:
diff changeset
   182
                    // a number of threads waiting for the state to change
02bb8761fcce Initial load
duke
parents:
diff changeset
   183
                    // from INCARN to something else, which is VALID or
02bb8761fcce Initial load
duke
parents:
diff changeset
   184
                    // INVALID, depending on the incarnate result.
02bb8761fcce Initial load
duke
parents:
diff changeset
   185
                    // The activeObjectMap.get() call above creates an
02bb8761fcce Initial load
duke
parents:
diff changeset
   186
                    // ActiveObjectMap.Entry if one does not already exist,
02bb8761fcce Initial load
duke
parents:
diff changeset
   187
                    // and stores it in the keyToEntry map in the AOM.
02bb8761fcce Initial load
duke
parents:
diff changeset
   188
                    entry.incarnateFailure() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   189
                } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   190
                    // here check for unique_id policy, and if the servant
02bb8761fcce Initial load
duke
parents:
diff changeset
   191
                    // is already registered for a different ID, then throw
02bb8761fcce Initial load
duke
parents:
diff changeset
   192
                    // OBJ_ADAPTER exception, else activate it. Section 11.3.5.1
02bb8761fcce Initial load
duke
parents:
diff changeset
   193
                    // 99-10-07.pdf
02bb8761fcce Initial load
duke
parents:
diff changeset
   194
                    if (isUnique) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   195
                        // check if the servant already is associated with some id
02bb8761fcce Initial load
duke
parents:
diff changeset
   196
                        if (activeObjectMap.contains((Servant)servant)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   197
                            if (poa.getDebug()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   198
                                ORBUtility.dprint( this,
02bb8761fcce Initial load
duke
parents:
diff changeset
   199
                                    "internalGetServant: servant already assigned to ID" ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   200
                            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   201
02bb8761fcce Initial load
duke
parents:
diff changeset
   202
                            entry.incarnateFailure() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   203
                            throw poa.invocationWrapper().poaServantNotUnique() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   204
                        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   205
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   206
02bb8761fcce Initial load
duke
parents:
diff changeset
   207
                    if (poa.getDebug()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   208
                        ORBUtility.dprint( this,
02bb8761fcce Initial load
duke
parents:
diff changeset
   209
                            "internalGetServant: incarnate complete" ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   210
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   211
02bb8761fcce Initial load
duke
parents:
diff changeset
   212
                    entry.incarnateComplete() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   213
                    activateServant(key, entry, (Servant)servant);
02bb8761fcce Initial load
duke
parents:
diff changeset
   214
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   215
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   216
02bb8761fcce Initial load
duke
parents:
diff changeset
   217
            return servant ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   218
        } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
   219
            if (poa.getDebug()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   220
                ORBUtility.dprint( this,
02bb8761fcce Initial load
duke
parents:
diff changeset
   221
                    "Exiting POAPolicyMediatorImpl_R_USM.internalGetServant " +
02bb8761fcce Initial load
duke
parents:
diff changeset
   222
                    "for poa " + poa ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   223
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   224
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   225
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   226
02bb8761fcce Initial load
duke
parents:
diff changeset
   227
    public void returnServant()
02bb8761fcce Initial load
duke
parents:
diff changeset
   228
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   229
        OAInvocationInfo info = orb.peekInvocationInfo();
02bb8761fcce Initial load
duke
parents:
diff changeset
   230
        byte[] id = info.id() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   231
        ActiveObjectMap.Key key = new ActiveObjectMap.Key( id ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   232
        AOMEntry entry = activeObjectMap.get( key ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   233
        entry.exit() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   234
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   235
02bb8761fcce Initial load
duke
parents:
diff changeset
   236
    public void etherealizeAll()
02bb8761fcce Initial load
duke
parents:
diff changeset
   237
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   238
        if (activator != null)  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   239
            Set keySet = activeObjectMap.keySet() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   240
02bb8761fcce Initial load
duke
parents:
diff changeset
   241
            // Copy the elements in the set to an array to avoid
02bb8761fcce Initial load
duke
parents:
diff changeset
   242
            // changes in the set due to concurrent modification
02bb8761fcce Initial load
duke
parents:
diff changeset
   243
            ActiveObjectMap.Key[] keys =
02bb8761fcce Initial load
duke
parents:
diff changeset
   244
                (ActiveObjectMap.Key[])keySet.toArray(
02bb8761fcce Initial load
duke
parents:
diff changeset
   245
                    new ActiveObjectMap.Key[ keySet.size() ] ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   246
02bb8761fcce Initial load
duke
parents:
diff changeset
   247
            for (int ctr=0; ctr<keySet.size(); ctr++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   248
                ActiveObjectMap.Key key = keys[ctr] ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   249
                AOMEntry entry = activeObjectMap.get( key ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   250
                Servant servant = activeObjectMap.getServant( entry ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   251
                if (servant != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   252
                    boolean remainingActivations =
02bb8761fcce Initial load
duke
parents:
diff changeset
   253
                        activeObjectMap.hasMultipleIDs(entry) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   254
02bb8761fcce Initial load
duke
parents:
diff changeset
   255
                    // Here we etherealize in the thread that called this
02bb8761fcce Initial load
duke
parents:
diff changeset
   256
                    // method, rather than etherealizing in a new thread
02bb8761fcce Initial load
duke
parents:
diff changeset
   257
                    // as in the deactivate case.  We still inform the
02bb8761fcce Initial load
duke
parents:
diff changeset
   258
                    // entry state machine so that only one thread at a
02bb8761fcce Initial load
duke
parents:
diff changeset
   259
                    // time can call the etherealize method.
02bb8761fcce Initial load
duke
parents:
diff changeset
   260
                    entry.startEtherealize( null ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   261
                    try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   262
                        poa.unlock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   263
                        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   264
                            activator.etherealize(key.id, poa, servant, true,
02bb8761fcce Initial load
duke
parents:
diff changeset
   265
                                remainingActivations);
02bb8761fcce Initial load
duke
parents:
diff changeset
   266
                        } catch (Exception exc) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   267
                            // ignore all exceptions
02bb8761fcce Initial load
duke
parents:
diff changeset
   268
                        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   269
                    } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
   270
                        poa.lock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   271
                        entry.etherealizeComplete() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   272
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   273
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   274
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   275
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   276
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   277
02bb8761fcce Initial load
duke
parents:
diff changeset
   278
    public ServantManager getServantManager() throws WrongPolicy
02bb8761fcce Initial load
duke
parents:
diff changeset
   279
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   280
        return activator;
02bb8761fcce Initial load
duke
parents:
diff changeset
   281
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   282
02bb8761fcce Initial load
duke
parents:
diff changeset
   283
    public void setServantManager(
02bb8761fcce Initial load
duke
parents:
diff changeset
   284
        ServantManager servantManager ) throws WrongPolicy
02bb8761fcce Initial load
duke
parents:
diff changeset
   285
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   286
        if (activator != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   287
            throw poa.invocationWrapper().servantManagerAlreadySet() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   288
02bb8761fcce Initial load
duke
parents:
diff changeset
   289
        if (servantManager instanceof ServantActivator)
02bb8761fcce Initial load
duke
parents:
diff changeset
   290
            activator = (ServantActivator)servantManager;
02bb8761fcce Initial load
duke
parents:
diff changeset
   291
        else
02bb8761fcce Initial load
duke
parents:
diff changeset
   292
            throw poa.invocationWrapper().servantManagerBadType() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   293
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   294
02bb8761fcce Initial load
duke
parents:
diff changeset
   295
    public Servant getDefaultServant() throws NoServant, WrongPolicy
02bb8761fcce Initial load
duke
parents:
diff changeset
   296
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   297
        throw new WrongPolicy();
02bb8761fcce Initial load
duke
parents:
diff changeset
   298
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   299
02bb8761fcce Initial load
duke
parents:
diff changeset
   300
    public void setDefaultServant( Servant servant ) throws WrongPolicy
02bb8761fcce Initial load
duke
parents:
diff changeset
   301
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   302
        throw new WrongPolicy();
02bb8761fcce Initial load
duke
parents:
diff changeset
   303
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   304
37620
230612715768 8148863: Remove sun.misc.ManagedLocalsThread from corba
chegar
parents: 33680
diff changeset
   305
    class Etherealizer extends Thread {
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   306
        private POAPolicyMediatorImpl_R_USM mediator ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   307
        private ActiveObjectMap.Key key ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   308
        private AOMEntry entry ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   309
        private Servant servant ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   310
        private boolean debug ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   311
29937
c774371adf92 8048997: Enhance thread contexts in CORBA
msheppar
parents: 25862
diff changeset
   312
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   313
        public Etherealizer( POAPolicyMediatorImpl_R_USM mediator,
02bb8761fcce Initial load
duke
parents:
diff changeset
   314
            ActiveObjectMap.Key key, AOMEntry entry, Servant servant,
02bb8761fcce Initial load
duke
parents:
diff changeset
   315
            boolean debug )
02bb8761fcce Initial load
duke
parents:
diff changeset
   316
        {
37620
230612715768 8148863: Remove sun.misc.ManagedLocalsThread from corba
chegar
parents: 33680
diff changeset
   317
            super(null, null, "PAO-Etherealizer-Thread", 0, false);
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   318
            this.mediator = mediator ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   319
            this.key = key ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   320
            this.entry = entry;
02bb8761fcce Initial load
duke
parents:
diff changeset
   321
            this.servant = servant;
02bb8761fcce Initial load
duke
parents:
diff changeset
   322
            this.debug = debug ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   323
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   324
02bb8761fcce Initial load
duke
parents:
diff changeset
   325
        public void run() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   326
            if (debug) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   327
                ORBUtility.dprint( this, "Calling Etherealizer.run on key " +
02bb8761fcce Initial load
duke
parents:
diff changeset
   328
                    key ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   329
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   330
02bb8761fcce Initial load
duke
parents:
diff changeset
   331
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   332
                try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   333
                    mediator.activator.etherealize( key.id, mediator.poa, servant,
02bb8761fcce Initial load
duke
parents:
diff changeset
   334
                        false, mediator.activeObjectMap.hasMultipleIDs( entry ) );
02bb8761fcce Initial load
duke
parents:
diff changeset
   335
                } catch (Exception exc) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   336
                    // ignore all exceptions
02bb8761fcce Initial load
duke
parents:
diff changeset
   337
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   338
02bb8761fcce Initial load
duke
parents:
diff changeset
   339
                try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   340
                    mediator.poa.lock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   341
02bb8761fcce Initial load
duke
parents:
diff changeset
   342
                    entry.etherealizeComplete() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   343
                    mediator.activeObjectMap.remove( key ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   344
02bb8761fcce Initial load
duke
parents:
diff changeset
   345
                    POAManagerImpl pm = (POAManagerImpl)mediator.poa.the_POAManager() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   346
                    POAFactory factory = pm.getFactory() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   347
                    factory.unregisterPOAForServant( mediator.poa, servant);
02bb8761fcce Initial load
duke
parents:
diff changeset
   348
                } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
   349
                    mediator.poa.unlock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   350
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   351
            } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
   352
                if (debug) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   353
                    ORBUtility.dprint( this, "Exiting Etherealizer.run" ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   354
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   355
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   356
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   357
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   358
02bb8761fcce Initial load
duke
parents:
diff changeset
   359
    public void deactivateHelper( ActiveObjectMap.Key key, AOMEntry entry,
02bb8761fcce Initial load
duke
parents:
diff changeset
   360
        Servant servant ) throws ObjectNotActive, WrongPolicy
02bb8761fcce Initial load
duke
parents:
diff changeset
   361
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   362
        if (activator == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   363
            throw poa.invocationWrapper().poaNoServantManager() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   364
02bb8761fcce Initial load
duke
parents:
diff changeset
   365
        Etherealizer eth = new Etherealizer( this, key, entry, servant, poa.getDebug() ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   366
        entry.startEtherealize( eth ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   367
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   368
02bb8761fcce Initial load
duke
parents:
diff changeset
   369
    public Servant idToServant( byte[] id )
02bb8761fcce Initial load
duke
parents:
diff changeset
   370
        throws WrongPolicy, ObjectNotActive
02bb8761fcce Initial load
duke
parents:
diff changeset
   371
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   372
        ActiveObjectMap.Key key = new ActiveObjectMap.Key( id ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   373
        AOMEntry entry = activeObjectMap.get(key);
02bb8761fcce Initial load
duke
parents:
diff changeset
   374
02bb8761fcce Initial load
duke
parents:
diff changeset
   375
        Servant servant = activeObjectMap.getServant( entry ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   376
        if (servant != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   377
            return servant ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   378
        else
02bb8761fcce Initial load
duke
parents:
diff changeset
   379
            throw new ObjectNotActive() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   380
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   381
}