corba/src/share/classes/com/sun/corba/se/impl/oa/poa/POAImpl.java
author ohair
Tue, 25 May 2010 15:52:11 -0700
changeset 5555 b2b5ed3f0d0d
parent 4 02bb8761fcce
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     1
/*
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     2
 * Copyright (c) 1997, 2004, 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.Collection ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    29
import java.util.Set ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    30
import java.util.HashSet ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    31
import java.util.Map ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    32
import java.util.HashMap ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    33
import java.util.Iterator ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    34
02bb8761fcce Initial load
duke
parents:
diff changeset
    35
import org.omg.CORBA.Policy ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    36
import org.omg.CORBA.SystemException ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    37
02bb8761fcce Initial load
duke
parents:
diff changeset
    38
import org.omg.PortableServer.POA ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    39
import org.omg.PortableServer.Servant ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    40
import org.omg.PortableServer.POAManager ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    41
import org.omg.PortableServer.AdapterActivator ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    42
import org.omg.PortableServer.ServantManager ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    43
import org.omg.PortableServer.ForwardRequest ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    44
import org.omg.PortableServer.ThreadPolicy;
02bb8761fcce Initial load
duke
parents:
diff changeset
    45
import org.omg.PortableServer.LifespanPolicy;
02bb8761fcce Initial load
duke
parents:
diff changeset
    46
import org.omg.PortableServer.IdUniquenessPolicy;
02bb8761fcce Initial load
duke
parents:
diff changeset
    47
import org.omg.PortableServer.IdAssignmentPolicy;
02bb8761fcce Initial load
duke
parents:
diff changeset
    48
import org.omg.PortableServer.ImplicitActivationPolicy;
02bb8761fcce Initial load
duke
parents:
diff changeset
    49
import org.omg.PortableServer.ServantRetentionPolicy;
02bb8761fcce Initial load
duke
parents:
diff changeset
    50
import org.omg.PortableServer.RequestProcessingPolicy;
02bb8761fcce Initial load
duke
parents:
diff changeset
    51
import org.omg.PortableServer.ThreadPolicyValue ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    52
import org.omg.PortableServer.LifespanPolicyValue ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    53
import org.omg.PortableServer.IdUniquenessPolicyValue ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    54
import org.omg.PortableServer.IdAssignmentPolicyValue ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    55
import org.omg.PortableServer.ImplicitActivationPolicyValue ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    56
import org.omg.PortableServer.ServantRetentionPolicyValue ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    57
import org.omg.PortableServer.RequestProcessingPolicyValue ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    58
import org.omg.PortableServer.POAPackage.AdapterAlreadyExists ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    59
import org.omg.PortableServer.POAPackage.AdapterNonExistent ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    60
import org.omg.PortableServer.POAPackage.InvalidPolicy ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    61
import org.omg.PortableServer.POAPackage.WrongPolicy ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    62
import org.omg.PortableServer.POAPackage.WrongAdapter ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    63
import org.omg.PortableServer.POAPackage.NoServant ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    64
import org.omg.PortableServer.POAPackage.ServantAlreadyActive ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    65
import org.omg.PortableServer.POAPackage.ObjectAlreadyActive ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    66
import org.omg.PortableServer.POAPackage.ServantNotActive ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    67
import org.omg.PortableServer.POAPackage.ObjectNotActive ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    68
02bb8761fcce Initial load
duke
parents:
diff changeset
    69
import org.omg.PortableInterceptor.ObjectReferenceFactory ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    70
import org.omg.PortableInterceptor.ObjectReferenceTemplate ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    71
import org.omg.PortableInterceptor.NON_EXISTENT ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    72
02bb8761fcce Initial load
duke
parents:
diff changeset
    73
import org.omg.IOP.TAG_INTERNET_IOP ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    74
02bb8761fcce Initial load
duke
parents:
diff changeset
    75
import com.sun.corba.se.spi.copyobject.CopierManager ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    76
import com.sun.corba.se.spi.copyobject.ObjectCopier ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    77
import com.sun.corba.se.spi.copyobject.ObjectCopierFactory ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    78
import com.sun.corba.se.spi.oa.OADestroyed ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    79
import com.sun.corba.se.spi.oa.OAInvocationInfo ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    80
import com.sun.corba.se.spi.oa.ObjectAdapter ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    81
import com.sun.corba.se.spi.oa.ObjectAdapterBase ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    82
import com.sun.corba.se.spi.oa.ObjectAdapterFactory ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    83
import com.sun.corba.se.spi.ior.ObjectKeyTemplate ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    84
import com.sun.corba.se.spi.ior.ObjectId ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    85
import com.sun.corba.se.spi.ior.ObjectAdapterId ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    86
import com.sun.corba.se.spi.ior.IOR ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    87
import com.sun.corba.se.spi.ior.IORFactories ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    88
import com.sun.corba.se.spi.ior.IORTemplate ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    89
import com.sun.corba.se.spi.ior.IORTemplateList ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    90
import com.sun.corba.se.spi.ior.TaggedProfile ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    91
import com.sun.corba.se.spi.ior.iiop.IIOPProfile ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    92
import com.sun.corba.se.spi.ior.iiop.IIOPAddress ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    93
import com.sun.corba.se.spi.ior.iiop.IIOPFactories ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    94
import com.sun.corba.se.spi.orb.ORB ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    95
import com.sun.corba.se.spi.protocol.ForwardException ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    96
import com.sun.corba.se.spi.transport.SocketOrChannelAcceptor;
02bb8761fcce Initial load
duke
parents:
diff changeset
    97
02bb8761fcce Initial load
duke
parents:
diff changeset
    98
import com.sun.corba.se.impl.ior.POAObjectKeyTemplate ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    99
import com.sun.corba.se.impl.ior.ObjectAdapterIdArray ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   100
import com.sun.corba.se.impl.orbutil.ORBUtility;
02bb8761fcce Initial load
duke
parents:
diff changeset
   101
import com.sun.corba.se.impl.orbutil.ORBConstants;
02bb8761fcce Initial load
duke
parents:
diff changeset
   102
import com.sun.corba.se.impl.orbutil.concurrent.Sync ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   103
import com.sun.corba.se.impl.orbutil.concurrent.SyncUtil ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   104
import com.sun.corba.se.impl.orbutil.concurrent.ReentrantMutex ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   105
import com.sun.corba.se.impl.orbutil.concurrent.CondVar ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   106
02bb8761fcce Initial load
duke
parents:
diff changeset
   107
/**
02bb8761fcce Initial load
duke
parents:
diff changeset
   108
 * POAImpl is the implementation of the Portable Object Adapter. It
02bb8761fcce Initial load
duke
parents:
diff changeset
   109
 * contains an implementation of the POA interfaces specified in
02bb8761fcce Initial load
duke
parents:
diff changeset
   110
 * COBRA 2.3.1 chapter 11 (formal/99-10-07).  This implementation
02bb8761fcce Initial load
duke
parents:
diff changeset
   111
 * is moving to comply with CORBA 3.0 due to the many clarifications
02bb8761fcce Initial load
duke
parents:
diff changeset
   112
 * that have been made to the POA semantics since CORBA 2.3.1.
02bb8761fcce Initial load
duke
parents:
diff changeset
   113
 * Specific comments have been added where 3.0 applies, but note that
02bb8761fcce Initial load
duke
parents:
diff changeset
   114
 * we do not have the new 3.0 APIs yet.
02bb8761fcce Initial load
duke
parents:
diff changeset
   115
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
   116
public class POAImpl extends ObjectAdapterBase implements POA
02bb8761fcce Initial load
duke
parents:
diff changeset
   117
{
02bb8761fcce Initial load
duke
parents:
diff changeset
   118
    private boolean debug ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   119
02bb8761fcce Initial load
duke
parents:
diff changeset
   120
    /* POA creation takes place in 2 stages: first, the POAImpl constructor is
02bb8761fcce Initial load
duke
parents:
diff changeset
   121
       called, then the initialize method is called.  This separation is
02bb8761fcce Initial load
duke
parents:
diff changeset
   122
       needed because an AdapterActivator does not know the POAManager or
02bb8761fcce Initial load
duke
parents:
diff changeset
   123
       the policies when
02bb8761fcce Initial load
duke
parents:
diff changeset
   124
       the unknown_adapter method is invoked.  However, the POA must be created
02bb8761fcce Initial load
duke
parents:
diff changeset
   125
       before the unknown_adapter method is invoked, so that the parent knows
02bb8761fcce Initial load
duke
parents:
diff changeset
   126
       when concurrent attempts are made to create the same POA.
02bb8761fcce Initial load
duke
parents:
diff changeset
   127
       Calling the POAImpl constructor results in a new POA in state STATE_START.
02bb8761fcce Initial load
duke
parents:
diff changeset
   128
       Calling initialize( POAManager, Policies ) results in state STATE_RUN.
02bb8761fcce Initial load
duke
parents:
diff changeset
   129
       Calling destroy results in STATE_DESTROY, which marks the beginning of
02bb8761fcce Initial load
duke
parents:
diff changeset
   130
       POA destruction.
02bb8761fcce Initial load
duke
parents:
diff changeset
   131
    */
02bb8761fcce Initial load
duke
parents:
diff changeset
   132
02bb8761fcce Initial load
duke
parents:
diff changeset
   133
    // Notes on concurrency.
02bb8761fcce Initial load
duke
parents:
diff changeset
   134
    // The POA requires careful design for concurrency management to correctly
02bb8761fcce Initial load
duke
parents:
diff changeset
   135
    // implement the specification and avoid deadlocks.  The order of acquiring
02bb8761fcce Initial load
duke
parents:
diff changeset
   136
    // locks must respect the following locking hierarchy:
02bb8761fcce Initial load
duke
parents:
diff changeset
   137
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   138
    // 1. Lock POAs before POAManagers
02bb8761fcce Initial load
duke
parents:
diff changeset
   139
    // 2. Lock a POA before locking its child POA
02bb8761fcce Initial load
duke
parents:
diff changeset
   140
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   141
    // Also note that there are 3 separate conditions on which threads may wait
02bb8761fcce Initial load
duke
parents:
diff changeset
   142
    // in the POA, as defined by invokeCV, beingDestroyedCV, and
02bb8761fcce Initial load
duke
parents:
diff changeset
   143
    // adapterActivatorCV.  This means that (for this reason as well as others)
02bb8761fcce Initial load
duke
parents:
diff changeset
   144
    // we cannot simply use the standard Java synchronized primitive.
02bb8761fcce Initial load
duke
parents:
diff changeset
   145
    // This implementation uses a modified version of Doug Lea's
02bb8761fcce Initial load
duke
parents:
diff changeset
   146
    // util.concurrent (version 1.3.0) that supports reentrant
02bb8761fcce Initial load
duke
parents:
diff changeset
   147
    // mutexes to handle the locking.  This will all be replaced by the new JSR
02bb8761fcce Initial load
duke
parents:
diff changeset
   148
    // 166 concurrency primitives in J2SE 1.5 and later once the ORB moves to
02bb8761fcce Initial load
duke
parents:
diff changeset
   149
    // J2SE 1.5.
02bb8761fcce Initial load
duke
parents:
diff changeset
   150
02bb8761fcce Initial load
duke
parents:
diff changeset
   151
    // POA state constants
02bb8761fcce Initial load
duke
parents:
diff changeset
   152
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   153
    // Note that ordering is important here: we must have the state defined in
02bb8761fcce Initial load
duke
parents:
diff changeset
   154
    // this order so that ordered comparison is possible.
02bb8761fcce Initial load
duke
parents:
diff changeset
   155
    // DO NOT CHANGE THE VALUES OF THE STATE CONSTANTS!!!  In particular, the
02bb8761fcce Initial load
duke
parents:
diff changeset
   156
    // initialization related states must be lower than STATE_RUN.
02bb8761fcce Initial load
duke
parents:
diff changeset
   157
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   158
    // POA is created in STATE_START
02bb8761fcce Initial load
duke
parents:
diff changeset
   159
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   160
    // Valid state transitions:
02bb8761fcce Initial load
duke
parents:
diff changeset
   161
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   162
    // START to INIT                        after find_POA constructor call
02bb8761fcce Initial load
duke
parents:
diff changeset
   163
    // START to RUN                         after initialize completes
02bb8761fcce Initial load
duke
parents:
diff changeset
   164
    // INIT to INIT_DONE                    after initialize completes
02bb8761fcce Initial load
duke
parents:
diff changeset
   165
    // INIT to DESTROYED                    after failed unknown_adapter
02bb8761fcce Initial load
duke
parents:
diff changeset
   166
    // INIT_DONE to RUN                     after successful unknown_adapter
02bb8761fcce Initial load
duke
parents:
diff changeset
   167
    // STATE_RUN to STATE_DESTROYING        after start of destruction
02bb8761fcce Initial load
duke
parents:
diff changeset
   168
    // STATE_DESTROYING to STATE_DESTROYED  after destruction completes.
02bb8761fcce Initial load
duke
parents:
diff changeset
   169
02bb8761fcce Initial load
duke
parents:
diff changeset
   170
    private static final int STATE_START        = 0 ; // constructor complete
02bb8761fcce Initial load
duke
parents:
diff changeset
   171
    private static final int STATE_INIT         = 1 ; // waiting for adapter activator
02bb8761fcce Initial load
duke
parents:
diff changeset
   172
    private static final int STATE_INIT_DONE    = 2 ; // adapter activator called create_POA
02bb8761fcce Initial load
duke
parents:
diff changeset
   173
    private static final int STATE_RUN          = 3 ; // initialized and running
02bb8761fcce Initial load
duke
parents:
diff changeset
   174
    private static final int STATE_DESTROYING   = 4 ; // being destroyed
02bb8761fcce Initial load
duke
parents:
diff changeset
   175
    private static final int STATE_DESTROYED    = 5 ; // destruction complete
02bb8761fcce Initial load
duke
parents:
diff changeset
   176
02bb8761fcce Initial load
duke
parents:
diff changeset
   177
    private String stateToString()
02bb8761fcce Initial load
duke
parents:
diff changeset
   178
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   179
        switch (state) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   180
            case STATE_START :
02bb8761fcce Initial load
duke
parents:
diff changeset
   181
                return "START" ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   182
            case STATE_INIT :
02bb8761fcce Initial load
duke
parents:
diff changeset
   183
                return "INIT" ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   184
            case STATE_INIT_DONE :
02bb8761fcce Initial load
duke
parents:
diff changeset
   185
                return "INIT_DONE" ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   186
            case STATE_RUN :
02bb8761fcce Initial load
duke
parents:
diff changeset
   187
                return "RUN" ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   188
            case STATE_DESTROYING :
02bb8761fcce Initial load
duke
parents:
diff changeset
   189
                return "DESTROYING" ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   190
            case STATE_DESTROYED :
02bb8761fcce Initial load
duke
parents:
diff changeset
   191
                return "DESTROYED" ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   192
            default :
02bb8761fcce Initial load
duke
parents:
diff changeset
   193
                return "UNKNOWN(" + state + ")" ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   194
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   195
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   196
02bb8761fcce Initial load
duke
parents:
diff changeset
   197
    // Current state of the POA
02bb8761fcce Initial load
duke
parents:
diff changeset
   198
    private int state ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   199
02bb8761fcce Initial load
duke
parents:
diff changeset
   200
    // The POA request handler that performs all policy specific operations
02bb8761fcce Initial load
duke
parents:
diff changeset
   201
    // Note that POAImpl handles all synchronization, so mediator is (mostly)
02bb8761fcce Initial load
duke
parents:
diff changeset
   202
    // unsynchronized.
02bb8761fcce Initial load
duke
parents:
diff changeset
   203
    private POAPolicyMediator mediator;
02bb8761fcce Initial load
duke
parents:
diff changeset
   204
02bb8761fcce Initial load
duke
parents:
diff changeset
   205
    // Representation of object adapter ID
02bb8761fcce Initial load
duke
parents:
diff changeset
   206
    private int numLevels;          // counts depth of tree.  Root = 1.
02bb8761fcce Initial load
duke
parents:
diff changeset
   207
    private ObjectAdapterId poaId ; // the actual object adapter ID for this POA
02bb8761fcce Initial load
duke
parents:
diff changeset
   208
    private String name;            // the name of this POA
02bb8761fcce Initial load
duke
parents:
diff changeset
   209
02bb8761fcce Initial load
duke
parents:
diff changeset
   210
    private POAManagerImpl manager; // This POA's POAManager
02bb8761fcce Initial load
duke
parents:
diff changeset
   211
    private int uniquePOAId ;       // ID for this POA that is unique relative
02bb8761fcce Initial load
duke
parents:
diff changeset
   212
                                    // to the POAFactory, which has the same
02bb8761fcce Initial load
duke
parents:
diff changeset
   213
                                    // lifetime as the ORB.
02bb8761fcce Initial load
duke
parents:
diff changeset
   214
    private POAImpl parent;         // The POA that created this POA.
02bb8761fcce Initial load
duke
parents:
diff changeset
   215
    private Map children;           // Map from name to POA of POAs created by
02bb8761fcce Initial load
duke
parents:
diff changeset
   216
                                    // this POA.
02bb8761fcce Initial load
duke
parents:
diff changeset
   217
02bb8761fcce Initial load
duke
parents:
diff changeset
   218
    private AdapterActivator activator;
02bb8761fcce Initial load
duke
parents:
diff changeset
   219
    private int invocationCount ; // pending invocations on this POA.
02bb8761fcce Initial load
duke
parents:
diff changeset
   220
02bb8761fcce Initial load
duke
parents:
diff changeset
   221
    // Data used to control POA concurrency
02bb8761fcce Initial load
duke
parents:
diff changeset
   222
    // XXX revisit for JSR 166
02bb8761fcce Initial load
duke
parents:
diff changeset
   223
02bb8761fcce Initial load
duke
parents:
diff changeset
   224
    // Master lock for all POA synchronization.  See lock and unlock.
02bb8761fcce Initial load
duke
parents:
diff changeset
   225
    // package private for access by AOMEntry.
02bb8761fcce Initial load
duke
parents:
diff changeset
   226
    Sync poaMutex ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   227
02bb8761fcce Initial load
duke
parents:
diff changeset
   228
    // Wait on this CV for AdapterActivator upcalls to complete
02bb8761fcce Initial load
duke
parents:
diff changeset
   229
    private CondVar adapterActivatorCV ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   230
02bb8761fcce Initial load
duke
parents:
diff changeset
   231
    // Wait on this CV for all active invocations to complete
02bb8761fcce Initial load
duke
parents:
diff changeset
   232
    private CondVar invokeCV ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   233
02bb8761fcce Initial load
duke
parents:
diff changeset
   234
    // Wait on this CV for the destroy method to complete doing its work
02bb8761fcce Initial load
duke
parents:
diff changeset
   235
    private CondVar beingDestroyedCV ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   236
02bb8761fcce Initial load
duke
parents:
diff changeset
   237
    // thread local variable to store a boolean to detect deadlock in
02bb8761fcce Initial load
duke
parents:
diff changeset
   238
    // POA.destroy().
02bb8761fcce Initial load
duke
parents:
diff changeset
   239
    protected ThreadLocal isDestroying ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   240
02bb8761fcce Initial load
duke
parents:
diff changeset
   241
    // This includes the most important information for debugging
02bb8761fcce Initial load
duke
parents:
diff changeset
   242
    // POA problems.
02bb8761fcce Initial load
duke
parents:
diff changeset
   243
    public String toString()
02bb8761fcce Initial load
duke
parents:
diff changeset
   244
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   245
        return "POA[" + poaId.toString() +
02bb8761fcce Initial load
duke
parents:
diff changeset
   246
            ", uniquePOAId=" + uniquePOAId +
02bb8761fcce Initial load
duke
parents:
diff changeset
   247
            ", state=" + stateToString() +
02bb8761fcce Initial load
duke
parents:
diff changeset
   248
            ", invocationCount=" + invocationCount + "]" ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   249
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   250
02bb8761fcce Initial load
duke
parents:
diff changeset
   251
    // package private for mediator implementations.
02bb8761fcce Initial load
duke
parents:
diff changeset
   252
    boolean getDebug()
02bb8761fcce Initial load
duke
parents:
diff changeset
   253
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   254
        return debug ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   255
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   256
02bb8761fcce Initial load
duke
parents:
diff changeset
   257
    // package private for access to servant to POA map
02bb8761fcce Initial load
duke
parents:
diff changeset
   258
    static POAFactory getPOAFactory( ORB orb )
02bb8761fcce Initial load
duke
parents:
diff changeset
   259
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   260
        return (POAFactory)orb.getRequestDispatcherRegistry().
02bb8761fcce Initial load
duke
parents:
diff changeset
   261
            getObjectAdapterFactory( ORBConstants.TRANSIENT_SCID ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   262
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   263
02bb8761fcce Initial load
duke
parents:
diff changeset
   264
    // package private so that POAFactory can access it.
02bb8761fcce Initial load
duke
parents:
diff changeset
   265
    static POAImpl makeRootPOA( ORB orb )
02bb8761fcce Initial load
duke
parents:
diff changeset
   266
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   267
        POAManagerImpl poaManager = new POAManagerImpl( getPOAFactory( orb ),
02bb8761fcce Initial load
duke
parents:
diff changeset
   268
            orb.getPIHandler() ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   269
02bb8761fcce Initial load
duke
parents:
diff changeset
   270
        POAImpl result = new POAImpl( ORBConstants.ROOT_POA_NAME,
02bb8761fcce Initial load
duke
parents:
diff changeset
   271
            null, orb, STATE_START ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   272
        result.initialize( poaManager, Policies.rootPOAPolicies ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   273
02bb8761fcce Initial load
duke
parents:
diff changeset
   274
        return result ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   275
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   276
02bb8761fcce Initial load
duke
parents:
diff changeset
   277
    // package private so that POAPolicyMediatorBase can access it.
02bb8761fcce Initial load
duke
parents:
diff changeset
   278
    int getPOAId()
02bb8761fcce Initial load
duke
parents:
diff changeset
   279
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   280
        return uniquePOAId ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   281
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   282
02bb8761fcce Initial load
duke
parents:
diff changeset
   283
02bb8761fcce Initial load
duke
parents:
diff changeset
   284
    // package private so that POAPolicyMediator can access it.
02bb8761fcce Initial load
duke
parents:
diff changeset
   285
    void lock()
02bb8761fcce Initial load
duke
parents:
diff changeset
   286
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   287
        SyncUtil.acquire( poaMutex ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   288
02bb8761fcce Initial load
duke
parents:
diff changeset
   289
        if (debug) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   290
            ORBUtility.dprint( this, "LOCKED poa " + this ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   291
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   292
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   293
02bb8761fcce Initial load
duke
parents:
diff changeset
   294
    // package private so that POAPolicyMediator can access it.
02bb8761fcce Initial load
duke
parents:
diff changeset
   295
    void unlock()
02bb8761fcce Initial load
duke
parents:
diff changeset
   296
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   297
        if (debug) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   298
            ORBUtility.dprint( this, "UNLOCKED poa " + this ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   299
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   300
02bb8761fcce Initial load
duke
parents:
diff changeset
   301
        poaMutex.release() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   302
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   303
02bb8761fcce Initial load
duke
parents:
diff changeset
   304
    // package private so that DelegateImpl can access it.
02bb8761fcce Initial load
duke
parents:
diff changeset
   305
    Policies getPolicies()
02bb8761fcce Initial load
duke
parents:
diff changeset
   306
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   307
        return mediator.getPolicies() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   308
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   309
02bb8761fcce Initial load
duke
parents:
diff changeset
   310
    // Note that the parent POA must be locked when this constructor is called.
02bb8761fcce Initial load
duke
parents:
diff changeset
   311
    private POAImpl( String name, POAImpl parent, ORB orb, int initialState )
02bb8761fcce Initial load
duke
parents:
diff changeset
   312
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   313
        super( orb ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   314
02bb8761fcce Initial load
duke
parents:
diff changeset
   315
        debug = orb.poaDebugFlag ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   316
02bb8761fcce Initial load
duke
parents:
diff changeset
   317
        if (debug) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   318
            ORBUtility.dprint( this, "Creating POA with name=" + name +
02bb8761fcce Initial load
duke
parents:
diff changeset
   319
                " parent=" + parent ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   320
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   321
02bb8761fcce Initial load
duke
parents:
diff changeset
   322
        this.state     = initialState ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   323
        this.name      = name ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   324
        this.parent    = parent;
02bb8761fcce Initial load
duke
parents:
diff changeset
   325
        children = new HashMap();
02bb8761fcce Initial load
duke
parents:
diff changeset
   326
        activator = null ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   327
02bb8761fcce Initial load
duke
parents:
diff changeset
   328
        // This was done in initialize, but I moved it here
02bb8761fcce Initial load
duke
parents:
diff changeset
   329
        // to get better searchability when tracing.
02bb8761fcce Initial load
duke
parents:
diff changeset
   330
        uniquePOAId = getPOAFactory( orb ).newPOAId() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   331
02bb8761fcce Initial load
duke
parents:
diff changeset
   332
        if (parent == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   333
            // This is the root POA, which counts as 1 level
02bb8761fcce Initial load
duke
parents:
diff changeset
   334
            numLevels = 1 ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   335
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   336
            // My level is one more than that of my parent
02bb8761fcce Initial load
duke
parents:
diff changeset
   337
            numLevels = parent.numLevels + 1 ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   338
02bb8761fcce Initial load
duke
parents:
diff changeset
   339
            parent.children.put(name, this);
02bb8761fcce Initial load
duke
parents:
diff changeset
   340
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   341
02bb8761fcce Initial load
duke
parents:
diff changeset
   342
        // Get an array of all of the POA names in order to
02bb8761fcce Initial load
duke
parents:
diff changeset
   343
        // create the poaid.
02bb8761fcce Initial load
duke
parents:
diff changeset
   344
        String[] names = new String[ numLevels ] ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   345
        POAImpl poaImpl = this ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   346
        int ctr = numLevels - 1 ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   347
        while (poaImpl != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   348
            names[ctr--] = poaImpl.name ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   349
            poaImpl = poaImpl.parent ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   350
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   351
02bb8761fcce Initial load
duke
parents:
diff changeset
   352
        poaId = new ObjectAdapterIdArray( names ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   353
02bb8761fcce Initial load
duke
parents:
diff changeset
   354
        invocationCount = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
   355
02bb8761fcce Initial load
duke
parents:
diff changeset
   356
        poaMutex = new ReentrantMutex( orb.poaConcurrencyDebugFlag ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   357
02bb8761fcce Initial load
duke
parents:
diff changeset
   358
        adapterActivatorCV = new CondVar( poaMutex,
02bb8761fcce Initial load
duke
parents:
diff changeset
   359
            orb.poaConcurrencyDebugFlag ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   360
        invokeCV           = new CondVar( poaMutex,
02bb8761fcce Initial load
duke
parents:
diff changeset
   361
            orb.poaConcurrencyDebugFlag ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   362
        beingDestroyedCV   = new CondVar( poaMutex,
02bb8761fcce Initial load
duke
parents:
diff changeset
   363
            orb.poaConcurrencyDebugFlag ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   364
02bb8761fcce Initial load
duke
parents:
diff changeset
   365
        isDestroying = new ThreadLocal () {
02bb8761fcce Initial load
duke
parents:
diff changeset
   366
            protected java.lang.Object initialValue() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   367
                return Boolean.FALSE;
02bb8761fcce Initial load
duke
parents:
diff changeset
   368
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   369
        };
02bb8761fcce Initial load
duke
parents:
diff changeset
   370
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   371
02bb8761fcce Initial load
duke
parents:
diff changeset
   372
    // The POA lock must be held when this method is called.
02bb8761fcce Initial load
duke
parents:
diff changeset
   373
    private void initialize( POAManagerImpl manager, Policies policies )
02bb8761fcce Initial load
duke
parents:
diff changeset
   374
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   375
        if (debug) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   376
            ORBUtility.dprint( this, "Initializing poa " + this +
02bb8761fcce Initial load
duke
parents:
diff changeset
   377
                " with POAManager=" + manager + " policies=" + policies ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   378
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   379
02bb8761fcce Initial load
duke
parents:
diff changeset
   380
        this.manager = manager;
02bb8761fcce Initial load
duke
parents:
diff changeset
   381
        manager.addPOA(this);
02bb8761fcce Initial load
duke
parents:
diff changeset
   382
02bb8761fcce Initial load
duke
parents:
diff changeset
   383
        mediator = POAPolicyMediatorFactory.create( policies, this ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   384
02bb8761fcce Initial load
duke
parents:
diff changeset
   385
        // Construct the object key template
02bb8761fcce Initial load
duke
parents:
diff changeset
   386
        int serverid = mediator.getServerId() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   387
        int scid = mediator.getScid() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   388
        String orbId = getORB().getORBData().getORBId();
02bb8761fcce Initial load
duke
parents:
diff changeset
   389
02bb8761fcce Initial load
duke
parents:
diff changeset
   390
        ObjectKeyTemplate oktemp = new POAObjectKeyTemplate( getORB(),
02bb8761fcce Initial load
duke
parents:
diff changeset
   391
            scid, serverid, orbId, poaId ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   392
02bb8761fcce Initial load
duke
parents:
diff changeset
   393
        if (debug) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   394
            ORBUtility.dprint( this, "Initializing poa: oktemp=" + oktemp ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   395
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   396
02bb8761fcce Initial load
duke
parents:
diff changeset
   397
        // Note that parent == null iff this is the root POA.
02bb8761fcce Initial load
duke
parents:
diff changeset
   398
        // This was used to avoid executing interceptors on the RootPOA.
02bb8761fcce Initial load
duke
parents:
diff changeset
   399
        // That is no longer necessary.
02bb8761fcce Initial load
duke
parents:
diff changeset
   400
        boolean objectAdapterCreated = true; // parent != null ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   401
02bb8761fcce Initial load
duke
parents:
diff changeset
   402
        // XXX extract codebase from policies and pass into initializeTemplate
02bb8761fcce Initial load
duke
parents:
diff changeset
   403
        // after the codebase policy change is finalized.
02bb8761fcce Initial load
duke
parents:
diff changeset
   404
        initializeTemplate( oktemp, objectAdapterCreated,
02bb8761fcce Initial load
duke
parents:
diff changeset
   405
                            policies,
02bb8761fcce Initial load
duke
parents:
diff changeset
   406
                            null, // codebase
02bb8761fcce Initial load
duke
parents:
diff changeset
   407
                            null, // manager id
02bb8761fcce Initial load
duke
parents:
diff changeset
   408
                            oktemp.getObjectAdapterId()
02bb8761fcce Initial load
duke
parents:
diff changeset
   409
                            ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   410
02bb8761fcce Initial load
duke
parents:
diff changeset
   411
        if (state == STATE_START)
02bb8761fcce Initial load
duke
parents:
diff changeset
   412
            state = STATE_RUN ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   413
        else if (state == STATE_INIT)
02bb8761fcce Initial load
duke
parents:
diff changeset
   414
            state = STATE_INIT_DONE ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   415
        else
02bb8761fcce Initial load
duke
parents:
diff changeset
   416
            throw lifecycleWrapper().illegalPoaStateTrans() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   417
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   418
02bb8761fcce Initial load
duke
parents:
diff changeset
   419
    // The poaMutex must be held when this method is called
02bb8761fcce Initial load
duke
parents:
diff changeset
   420
    private boolean waitUntilRunning()
02bb8761fcce Initial load
duke
parents:
diff changeset
   421
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   422
        if (debug) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   423
            ORBUtility.dprint( this,
02bb8761fcce Initial load
duke
parents:
diff changeset
   424
                "Calling waitUntilRunning on poa " + this ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   425
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   426
02bb8761fcce Initial load
duke
parents:
diff changeset
   427
        while (state < STATE_RUN) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   428
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   429
                adapterActivatorCV.await() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   430
            } catch (InterruptedException exc) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   431
                // NO-OP
02bb8761fcce Initial load
duke
parents:
diff changeset
   432
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   433
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   434
02bb8761fcce Initial load
duke
parents:
diff changeset
   435
        if (debug) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   436
            ORBUtility.dprint( this,
02bb8761fcce Initial load
duke
parents:
diff changeset
   437
                "Exiting waitUntilRunning on poa " + this ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   438
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   439
02bb8761fcce Initial load
duke
parents:
diff changeset
   440
        // Note that a POA could be destroyed while in STATE_INIT due to a
02bb8761fcce Initial load
duke
parents:
diff changeset
   441
        // failure in the AdapterActivator upcall.
02bb8761fcce Initial load
duke
parents:
diff changeset
   442
        return (state == STATE_RUN) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   443
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   444
02bb8761fcce Initial load
duke
parents:
diff changeset
   445
    // This method checks that the AdapterActivator finished the
02bb8761fcce Initial load
duke
parents:
diff changeset
   446
    // initialization of a POA activated in find_POA.  This is
02bb8761fcce Initial load
duke
parents:
diff changeset
   447
    // determined by checking the state of the POA.  If the state is
02bb8761fcce Initial load
duke
parents:
diff changeset
   448
    // STATE_INIT, the AdapterActivator did not complete the
02bb8761fcce Initial load
duke
parents:
diff changeset
   449
    // inialization.  In this case, we destroy the POA that was
02bb8761fcce Initial load
duke
parents:
diff changeset
   450
    // partially created and return false.  Otherwise, we return true.
02bb8761fcce Initial load
duke
parents:
diff changeset
   451
    // In any case, we must wake up all threads waiting for the adapter
02bb8761fcce Initial load
duke
parents:
diff changeset
   452
    // activator, either to continue their invocations, or to return
02bb8761fcce Initial load
duke
parents:
diff changeset
   453
    // errors to their client.
02bb8761fcce Initial load
duke
parents:
diff changeset
   454
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   455
    // The poaMutex must NOT be held when this method is called.
02bb8761fcce Initial load
duke
parents:
diff changeset
   456
    private boolean destroyIfNotInitDone()
02bb8761fcce Initial load
duke
parents:
diff changeset
   457
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   458
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   459
            lock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   460
02bb8761fcce Initial load
duke
parents:
diff changeset
   461
            if (debug) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   462
                ORBUtility.dprint( this,
02bb8761fcce Initial load
duke
parents:
diff changeset
   463
                    "Calling destroyIfNotInitDone on poa " + this ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   464
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   465
02bb8761fcce Initial load
duke
parents:
diff changeset
   466
            boolean success = (state == STATE_INIT_DONE) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   467
02bb8761fcce Initial load
duke
parents:
diff changeset
   468
            if (success)
02bb8761fcce Initial load
duke
parents:
diff changeset
   469
                state = STATE_RUN ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   470
            else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   471
                // Don't just use destroy, because the check for
02bb8761fcce Initial load
duke
parents:
diff changeset
   472
                // deadlock is too general, and can prevent this from
02bb8761fcce Initial load
duke
parents:
diff changeset
   473
                // functioning properly.
02bb8761fcce Initial load
duke
parents:
diff changeset
   474
                DestroyThread destroyer = new DestroyThread( false, debug );
02bb8761fcce Initial load
duke
parents:
diff changeset
   475
                destroyer.doIt( this, true ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   476
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   477
02bb8761fcce Initial load
duke
parents:
diff changeset
   478
            return success ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   479
        } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
   480
            adapterActivatorCV.broadcast() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   481
02bb8761fcce Initial load
duke
parents:
diff changeset
   482
            if (debug) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   483
                ORBUtility.dprint( this,
02bb8761fcce Initial load
duke
parents:
diff changeset
   484
                    "Exiting destroyIfNotInitDone on poa " + this ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   485
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   486
02bb8761fcce Initial load
duke
parents:
diff changeset
   487
            unlock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   488
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   489
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   490
02bb8761fcce Initial load
duke
parents:
diff changeset
   491
    private byte[] internalReferenceToId(
02bb8761fcce Initial load
duke
parents:
diff changeset
   492
        org.omg.CORBA.Object reference ) throws WrongAdapter
02bb8761fcce Initial load
duke
parents:
diff changeset
   493
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   494
        IOR ior = ORBUtility.getIOR( reference ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   495
        IORTemplateList thisTemplate = ior.getIORTemplates() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   496
02bb8761fcce Initial load
duke
parents:
diff changeset
   497
        ObjectReferenceFactory orf = getCurrentFactory() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   498
        IORTemplateList poaTemplate =
02bb8761fcce Initial load
duke
parents:
diff changeset
   499
            IORFactories.getIORTemplateList( orf ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   500
02bb8761fcce Initial load
duke
parents:
diff changeset
   501
        if (!poaTemplate.isEquivalent( thisTemplate ))
02bb8761fcce Initial load
duke
parents:
diff changeset
   502
            throw new WrongAdapter();
02bb8761fcce Initial load
duke
parents:
diff changeset
   503
02bb8761fcce Initial load
duke
parents:
diff changeset
   504
        // Extract the ObjectId from the first TaggedProfile in the IOR.
02bb8761fcce Initial load
duke
parents:
diff changeset
   505
        // If ior was created in this POA, the same ID was used for
02bb8761fcce Initial load
duke
parents:
diff changeset
   506
        // every profile through the profile templates in the currentFactory,
02bb8761fcce Initial load
duke
parents:
diff changeset
   507
        // so we will get the same result from any profile.
02bb8761fcce Initial load
duke
parents:
diff changeset
   508
        Iterator iter = ior.iterator() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   509
        if (!iter.hasNext())
02bb8761fcce Initial load
duke
parents:
diff changeset
   510
            throw iorWrapper().noProfilesInIor() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   511
        TaggedProfile prof = (TaggedProfile)(iter.next()) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   512
        ObjectId oid = prof.getObjectId() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   513
02bb8761fcce Initial load
duke
parents:
diff changeset
   514
        return oid.getId();
02bb8761fcce Initial load
duke
parents:
diff changeset
   515
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   516
02bb8761fcce Initial load
duke
parents:
diff changeset
   517
    // Converted from anonymous class to local class
02bb8761fcce Initial load
duke
parents:
diff changeset
   518
    // so that we can call performDestroy() directly.
02bb8761fcce Initial load
duke
parents:
diff changeset
   519
    static class DestroyThread extends Thread {
02bb8761fcce Initial load
duke
parents:
diff changeset
   520
        private boolean wait ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   521
        private boolean etherealize ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   522
        private boolean debug ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   523
        private POAImpl thePoa ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   524
02bb8761fcce Initial load
duke
parents:
diff changeset
   525
        public DestroyThread( boolean etherealize, boolean debug )
02bb8761fcce Initial load
duke
parents:
diff changeset
   526
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
   527
            this.etherealize = etherealize ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   528
            this.debug = debug ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   529
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   530
02bb8761fcce Initial load
duke
parents:
diff changeset
   531
        public void doIt( POAImpl thePoa, boolean wait )
02bb8761fcce Initial load
duke
parents:
diff changeset
   532
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
   533
            if (debug) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   534
                ORBUtility.dprint( this,
02bb8761fcce Initial load
duke
parents:
diff changeset
   535
                    "Calling DestroyThread.doIt(thePOA=" + thePoa +
02bb8761fcce Initial load
duke
parents:
diff changeset
   536
                    " wait=" + wait + " etherealize=" + etherealize ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   537
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   538
02bb8761fcce Initial load
duke
parents:
diff changeset
   539
            this.thePoa = thePoa ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   540
            this.wait = wait ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   541
02bb8761fcce Initial load
duke
parents:
diff changeset
   542
            if (wait) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   543
                run() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   544
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   545
                // Catch exceptions since setDaemon can cause a
02bb8761fcce Initial load
duke
parents:
diff changeset
   546
                // security exception to be thrown under netscape
02bb8761fcce Initial load
duke
parents:
diff changeset
   547
                // in the Applet mode
02bb8761fcce Initial load
duke
parents:
diff changeset
   548
                try { setDaemon(true); } catch (Exception e) {}
02bb8761fcce Initial load
duke
parents:
diff changeset
   549
                start() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   550
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   551
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   552
02bb8761fcce Initial load
duke
parents:
diff changeset
   553
        public void run()
02bb8761fcce Initial load
duke
parents:
diff changeset
   554
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
   555
            Set destroyedPOATemplates = new HashSet() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   556
02bb8761fcce Initial load
duke
parents:
diff changeset
   557
            performDestroy( thePoa, destroyedPOATemplates );
02bb8761fcce Initial load
duke
parents:
diff changeset
   558
02bb8761fcce Initial load
duke
parents:
diff changeset
   559
            Iterator iter = destroyedPOATemplates.iterator() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   560
            ObjectReferenceTemplate[] orts = new ObjectReferenceTemplate[
02bb8761fcce Initial load
duke
parents:
diff changeset
   561
                destroyedPOATemplates.size() ] ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   562
            int index = 0 ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   563
            while (iter.hasNext())
02bb8761fcce Initial load
duke
parents:
diff changeset
   564
                orts[ index++ ] = (ObjectReferenceTemplate)iter.next();
02bb8761fcce Initial load
duke
parents:
diff changeset
   565
02bb8761fcce Initial load
duke
parents:
diff changeset
   566
            thePoa.getORB().getPIHandler().adapterStateChanged( orts,
02bb8761fcce Initial load
duke
parents:
diff changeset
   567
                NON_EXISTENT.value ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   568
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   569
02bb8761fcce Initial load
duke
parents:
diff changeset
   570
        // Returns true if destruction must be completed, false
02bb8761fcce Initial load
duke
parents:
diff changeset
   571
        // if not, which means that another thread is already
02bb8761fcce Initial load
duke
parents:
diff changeset
   572
        // destroying poa.
02bb8761fcce Initial load
duke
parents:
diff changeset
   573
        private boolean prepareForDestruction( POAImpl poa,
02bb8761fcce Initial load
duke
parents:
diff changeset
   574
            Set destroyedPOATemplates )
02bb8761fcce Initial load
duke
parents:
diff changeset
   575
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
   576
            POAImpl[] childPoas = null ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   577
02bb8761fcce Initial load
duke
parents:
diff changeset
   578
            // Note that we do not synchronize on this, since this is
02bb8761fcce Initial load
duke
parents:
diff changeset
   579
            // the PerformDestroy instance, not the POA.
02bb8761fcce Initial load
duke
parents:
diff changeset
   580
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   581
                poa.lock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   582
02bb8761fcce Initial load
duke
parents:
diff changeset
   583
                if (debug) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   584
                    ORBUtility.dprint( this,
02bb8761fcce Initial load
duke
parents:
diff changeset
   585
                        "Calling performDestroy on poa " + poa ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   586
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   587
02bb8761fcce Initial load
duke
parents:
diff changeset
   588
                if (poa.state <= STATE_RUN) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   589
                    poa.state = STATE_DESTROYING ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   590
                } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   591
                    // destroy may be called multiple times, and each call
02bb8761fcce Initial load
duke
parents:
diff changeset
   592
                    // is allowed to proceed with its own setting of the wait
02bb8761fcce Initial load
duke
parents:
diff changeset
   593
                    // flag, but the etherealize value is used from the first
02bb8761fcce Initial load
duke
parents:
diff changeset
   594
                    // call to destroy.  Also all children should be destroyed
02bb8761fcce Initial load
duke
parents:
diff changeset
   595
                    // before the parent POA.  If the poa is already destroyed,
02bb8761fcce Initial load
duke
parents:
diff changeset
   596
                    // we can just return.  If the poa has started destruction,
02bb8761fcce Initial load
duke
parents:
diff changeset
   597
                    // but not completed, and wait is true, we need to wait
02bb8761fcce Initial load
duke
parents:
diff changeset
   598
                    // until destruction is complete, then just return.
02bb8761fcce Initial load
duke
parents:
diff changeset
   599
                    if (wait)
02bb8761fcce Initial load
duke
parents:
diff changeset
   600
                        while (poa.state != STATE_DESTROYED) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   601
                            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   602
                                poa.beingDestroyedCV.await() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   603
                            } catch (InterruptedException exc) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   604
                                // NO-OP
02bb8761fcce Initial load
duke
parents:
diff changeset
   605
                            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   606
                        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   607
02bb8761fcce Initial load
duke
parents:
diff changeset
   608
                    return false ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   609
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   610
02bb8761fcce Initial load
duke
parents:
diff changeset
   611
                poa.isDestroying.set(Boolean.TRUE);
02bb8761fcce Initial load
duke
parents:
diff changeset
   612
02bb8761fcce Initial load
duke
parents:
diff changeset
   613
                // Make a copy since we can't hold the lock while destroying
02bb8761fcce Initial load
duke
parents:
diff changeset
   614
                // the children, and an iterator is not deletion-safe.
02bb8761fcce Initial load
duke
parents:
diff changeset
   615
                childPoas = (POAImpl[])poa.children.values().toArray(
02bb8761fcce Initial load
duke
parents:
diff changeset
   616
                    new POAImpl[0] );
02bb8761fcce Initial load
duke
parents:
diff changeset
   617
            } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
   618
                poa.unlock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   619
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   620
02bb8761fcce Initial load
duke
parents:
diff changeset
   621
            // We are not holding the POA mutex here to avoid holding it
02bb8761fcce Initial load
duke
parents:
diff changeset
   622
            // while destroying the POA's children, since this may involve
02bb8761fcce Initial load
duke
parents:
diff changeset
   623
            // upcalls to etherealize methods.
02bb8761fcce Initial load
duke
parents:
diff changeset
   624
02bb8761fcce Initial load
duke
parents:
diff changeset
   625
            for (int ctr=0; ctr<childPoas.length; ctr++ ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   626
                performDestroy( childPoas[ctr], destroyedPOATemplates ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   627
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   628
02bb8761fcce Initial load
duke
parents:
diff changeset
   629
            return true ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   630
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   631
02bb8761fcce Initial load
duke
parents:
diff changeset
   632
        public void performDestroy( POAImpl poa, Set destroyedPOATemplates )
02bb8761fcce Initial load
duke
parents:
diff changeset
   633
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
   634
            if (!prepareForDestruction( poa, destroyedPOATemplates ))
02bb8761fcce Initial load
duke
parents:
diff changeset
   635
                return ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   636
02bb8761fcce Initial load
duke
parents:
diff changeset
   637
            // NOTE: If we are here, poa is in STATE_DESTROYING state. All
02bb8761fcce Initial load
duke
parents:
diff changeset
   638
            // other state checks are taken care of in prepareForDestruction.
02bb8761fcce Initial load
duke
parents:
diff changeset
   639
            // No other threads may either be starting new invocations
02bb8761fcce Initial load
duke
parents:
diff changeset
   640
            // by calling enter or starting to destroy poa.  There may
02bb8761fcce Initial load
duke
parents:
diff changeset
   641
            // still be pending invocations.
02bb8761fcce Initial load
duke
parents:
diff changeset
   642
02bb8761fcce Initial load
duke
parents:
diff changeset
   643
            POAImpl parent = poa.parent ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   644
            boolean isRoot = parent == null ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   645
02bb8761fcce Initial load
duke
parents:
diff changeset
   646
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   647
                // Note that we must lock the parent before the child.
02bb8761fcce Initial load
duke
parents:
diff changeset
   648
                // The parent lock is required (if poa is not the root)
02bb8761fcce Initial load
duke
parents:
diff changeset
   649
                // to safely remove poa from parent's children Map.
02bb8761fcce Initial load
duke
parents:
diff changeset
   650
                if (!isRoot)
02bb8761fcce Initial load
duke
parents:
diff changeset
   651
                    parent.lock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   652
02bb8761fcce Initial load
duke
parents:
diff changeset
   653
                try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   654
                    poa.lock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   655
02bb8761fcce Initial load
duke
parents:
diff changeset
   656
                    completeDestruction( poa, parent,
02bb8761fcce Initial load
duke
parents:
diff changeset
   657
                        destroyedPOATemplates ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   658
                } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
   659
                    poa.unlock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   660
02bb8761fcce Initial load
duke
parents:
diff changeset
   661
                    if (isRoot)
02bb8761fcce Initial load
duke
parents:
diff changeset
   662
                        // We have just destroyed the root POA, so we need to
02bb8761fcce Initial load
duke
parents:
diff changeset
   663
                        // make sure that the next call to
02bb8761fcce Initial load
duke
parents:
diff changeset
   664
                        // resolve_initial_reference( "RootPOA" )
02bb8761fcce Initial load
duke
parents:
diff changeset
   665
                        // will recreate a valid root POA.
02bb8761fcce Initial load
duke
parents:
diff changeset
   666
                        poa.manager.getFactory().registerRootPOA() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   667
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   668
            } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
   669
                if (!isRoot) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   670
                    parent.unlock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   671
                    poa.parent = null ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   672
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   673
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   674
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   675
02bb8761fcce Initial load
duke
parents:
diff changeset
   676
        private void completeDestruction( POAImpl poa, POAImpl parent,
02bb8761fcce Initial load
duke
parents:
diff changeset
   677
            Set destroyedPOATemplates )
02bb8761fcce Initial load
duke
parents:
diff changeset
   678
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
   679
            if (debug) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   680
                ORBUtility.dprint( this,
02bb8761fcce Initial load
duke
parents:
diff changeset
   681
                    "Calling completeDestruction on poa " + poa ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   682
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   683
02bb8761fcce Initial load
duke
parents:
diff changeset
   684
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   685
                while (poa.invocationCount != 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   686
                    try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   687
                        poa.invokeCV.await() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   688
                    } catch (InterruptedException ex) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   689
                        // NO-OP
02bb8761fcce Initial load
duke
parents:
diff changeset
   690
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   691
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   692
02bb8761fcce Initial load
duke
parents:
diff changeset
   693
                if (poa.mediator != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   694
                    if (etherealize)
02bb8761fcce Initial load
duke
parents:
diff changeset
   695
                        poa.mediator.etherealizeAll();
02bb8761fcce Initial load
duke
parents:
diff changeset
   696
02bb8761fcce Initial load
duke
parents:
diff changeset
   697
                    poa.mediator.clearAOM() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   698
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   699
02bb8761fcce Initial load
duke
parents:
diff changeset
   700
                if (poa.manager != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   701
                    poa.manager.removePOA(poa);
02bb8761fcce Initial load
duke
parents:
diff changeset
   702
02bb8761fcce Initial load
duke
parents:
diff changeset
   703
                if (parent != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   704
                    parent.children.remove( poa.name ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   705
02bb8761fcce Initial load
duke
parents:
diff changeset
   706
                destroyedPOATemplates.add( poa.getAdapterTemplate() ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   707
            } catch (Throwable thr) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   708
                if (thr instanceof ThreadDeath)
02bb8761fcce Initial load
duke
parents:
diff changeset
   709
                    throw (ThreadDeath)thr ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   710
02bb8761fcce Initial load
duke
parents:
diff changeset
   711
                poa.lifecycleWrapper().unexpectedException( thr, poa.toString() ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   712
            } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
   713
                poa.state = STATE_DESTROYED ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   714
                poa.beingDestroyedCV.broadcast();
02bb8761fcce Initial load
duke
parents:
diff changeset
   715
                poa.isDestroying.set(Boolean.FALSE);
02bb8761fcce Initial load
duke
parents:
diff changeset
   716
02bb8761fcce Initial load
duke
parents:
diff changeset
   717
                if (debug) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   718
                    ORBUtility.dprint( this,
02bb8761fcce Initial load
duke
parents:
diff changeset
   719
                        "Exiting completeDestruction on poa " + poa ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   720
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   721
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   722
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   723
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   724
02bb8761fcce Initial load
duke
parents:
diff changeset
   725
    void etherealizeAll()
02bb8761fcce Initial load
duke
parents:
diff changeset
   726
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   727
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   728
            lock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   729
02bb8761fcce Initial load
duke
parents:
diff changeset
   730
            if (debug) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   731
                ORBUtility.dprint( this,
02bb8761fcce Initial load
duke
parents:
diff changeset
   732
                    "Calling etheralizeAll on poa " + this ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   733
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   734
02bb8761fcce Initial load
duke
parents:
diff changeset
   735
            mediator.etherealizeAll() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   736
        } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
   737
            if (debug) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   738
                ORBUtility.dprint( this,
02bb8761fcce Initial load
duke
parents:
diff changeset
   739
                    "Exiting etheralizeAll on poa " + this ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   740
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   741
02bb8761fcce Initial load
duke
parents:
diff changeset
   742
            unlock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   743
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   744
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   745
02bb8761fcce Initial load
duke
parents:
diff changeset
   746
 //*******************************************************************
02bb8761fcce Initial load
duke
parents:
diff changeset
   747
 // Public POA API
02bb8761fcce Initial load
duke
parents:
diff changeset
   748
 //*******************************************************************
02bb8761fcce Initial load
duke
parents:
diff changeset
   749
02bb8761fcce Initial load
duke
parents:
diff changeset
   750
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   751
     * <code>create_POA</code>
02bb8761fcce Initial load
duke
parents:
diff changeset
   752
     * <b>Section 3.3.8.2</b>
02bb8761fcce Initial load
duke
parents:
diff changeset
   753
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   754
    public POA create_POA(String name, POAManager
02bb8761fcce Initial load
duke
parents:
diff changeset
   755
        theManager, Policy[] policies) throws AdapterAlreadyExists,
02bb8761fcce Initial load
duke
parents:
diff changeset
   756
        InvalidPolicy
02bb8761fcce Initial load
duke
parents:
diff changeset
   757
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   758
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   759
            lock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   760
02bb8761fcce Initial load
duke
parents:
diff changeset
   761
            if (debug) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   762
                ORBUtility.dprint( this, "Calling create_POA(name=" + name +
02bb8761fcce Initial load
duke
parents:
diff changeset
   763
                    " theManager=" + theManager + " policies=" + policies +
02bb8761fcce Initial load
duke
parents:
diff changeset
   764
                    ") on poa " + this ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   765
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   766
02bb8761fcce Initial load
duke
parents:
diff changeset
   767
            // We cannot create children of a POA that is (being) destroyed.
02bb8761fcce Initial load
duke
parents:
diff changeset
   768
            // This has been added to the CORBA 3.0 spec.
02bb8761fcce Initial load
duke
parents:
diff changeset
   769
            if (state > STATE_RUN)
02bb8761fcce Initial load
duke
parents:
diff changeset
   770
                throw omgLifecycleWrapper().createPoaDestroy() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   771
02bb8761fcce Initial load
duke
parents:
diff changeset
   772
            POAImpl poa = (POAImpl)(children.get(name)) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   773
02bb8761fcce Initial load
duke
parents:
diff changeset
   774
            if (poa == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   775
                poa = new POAImpl( name, this, getORB(), STATE_START ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   776
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   777
02bb8761fcce Initial load
duke
parents:
diff changeset
   778
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   779
                poa.lock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   780
02bb8761fcce Initial load
duke
parents:
diff changeset
   781
                if (debug) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   782
                    ORBUtility.dprint( this,
02bb8761fcce Initial load
duke
parents:
diff changeset
   783
                        "Calling create_POA: new poa is " + poa ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   784
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   785
02bb8761fcce Initial load
duke
parents:
diff changeset
   786
                if ((poa.state != STATE_START) && (poa.state != STATE_INIT))
02bb8761fcce Initial load
duke
parents:
diff changeset
   787
                    throw new AdapterAlreadyExists();
02bb8761fcce Initial load
duke
parents:
diff changeset
   788
02bb8761fcce Initial load
duke
parents:
diff changeset
   789
                POAManagerImpl newManager = (POAManagerImpl)theManager ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   790
                if (newManager == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   791
                    newManager = new POAManagerImpl( manager.getFactory(),
02bb8761fcce Initial load
duke
parents:
diff changeset
   792
                        manager.getPIHandler() );
02bb8761fcce Initial load
duke
parents:
diff changeset
   793
02bb8761fcce Initial load
duke
parents:
diff changeset
   794
                int defaultCopierId =
02bb8761fcce Initial load
duke
parents:
diff changeset
   795
                    getORB().getCopierManager().getDefaultId() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   796
                Policies POAPolicies =
02bb8761fcce Initial load
duke
parents:
diff changeset
   797
                    new Policies( policies, defaultCopierId ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   798
02bb8761fcce Initial load
duke
parents:
diff changeset
   799
                poa.initialize( newManager, POAPolicies ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   800
02bb8761fcce Initial load
duke
parents:
diff changeset
   801
                return poa;
02bb8761fcce Initial load
duke
parents:
diff changeset
   802
            } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
   803
                poa.unlock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   804
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   805
        } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
   806
            unlock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   807
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   808
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   809
02bb8761fcce Initial load
duke
parents:
diff changeset
   810
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   811
     * <code>find_POA</code>
02bb8761fcce Initial load
duke
parents:
diff changeset
   812
     * <b>Section 3.3.8.3</b>
02bb8761fcce Initial load
duke
parents:
diff changeset
   813
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   814
    public POA find_POA(String name, boolean activate)
02bb8761fcce Initial load
duke
parents:
diff changeset
   815
        throws AdapterNonExistent
02bb8761fcce Initial load
duke
parents:
diff changeset
   816
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   817
        POAImpl found = null ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   818
        AdapterActivator act = null ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   819
02bb8761fcce Initial load
duke
parents:
diff changeset
   820
        lock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   821
02bb8761fcce Initial load
duke
parents:
diff changeset
   822
        if (debug) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   823
            ORBUtility.dprint( this, "Calling find_POA(name=" + name +
02bb8761fcce Initial load
duke
parents:
diff changeset
   824
                " activate=" + activate + ") on poa " + this ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   825
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   826
02bb8761fcce Initial load
duke
parents:
diff changeset
   827
        found = (POAImpl) children.get(name);
02bb8761fcce Initial load
duke
parents:
diff changeset
   828
02bb8761fcce Initial load
duke
parents:
diff changeset
   829
        if (found != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   830
            if (debug) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   831
                ORBUtility.dprint( this,
02bb8761fcce Initial load
duke
parents:
diff changeset
   832
                    "Calling find_POA: found poa " + found ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   833
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   834
02bb8761fcce Initial load
duke
parents:
diff changeset
   835
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   836
                found.lock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   837
02bb8761fcce Initial load
duke
parents:
diff changeset
   838
                // Do not hold the parent POA lock while
02bb8761fcce Initial load
duke
parents:
diff changeset
   839
                // waiting for child to complete initialization.
02bb8761fcce Initial load
duke
parents:
diff changeset
   840
                unlock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   841
02bb8761fcce Initial load
duke
parents:
diff changeset
   842
                // Make sure that the child has completed its initialization,
02bb8761fcce Initial load
duke
parents:
diff changeset
   843
                // if it was created by an AdapterActivator, otherwise throw
02bb8761fcce Initial load
duke
parents:
diff changeset
   844
                // a standard TRANSIENT exception with minor code 4 (see
02bb8761fcce Initial load
duke
parents:
diff changeset
   845
                // CORBA 3.0 11.3.9.3, in reference to unknown_adapter)
02bb8761fcce Initial load
duke
parents:
diff changeset
   846
                if (!found.waitUntilRunning())
02bb8761fcce Initial load
duke
parents:
diff changeset
   847
                    throw omgLifecycleWrapper().poaDestroyed() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   848
02bb8761fcce Initial load
duke
parents:
diff changeset
   849
                // Note that found may be in state DESTROYING or DESTROYED at
02bb8761fcce Initial load
duke
parents:
diff changeset
   850
                // this point.  That's OK, since destruction could start at
02bb8761fcce Initial load
duke
parents:
diff changeset
   851
                // any time.
02bb8761fcce Initial load
duke
parents:
diff changeset
   852
            } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
   853
                found.unlock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   854
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   855
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   856
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   857
                if (debug) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   858
                    ORBUtility.dprint( this,
02bb8761fcce Initial load
duke
parents:
diff changeset
   859
                        "Calling find_POA: no poa found" ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   860
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   861
02bb8761fcce Initial load
duke
parents:
diff changeset
   862
                if (activate && (activator != null)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   863
                    // Create a child, but don't initialize it.  The newly
02bb8761fcce Initial load
duke
parents:
diff changeset
   864
                    // created POA will be in state STATE_START, which will
02bb8761fcce Initial load
duke
parents:
diff changeset
   865
                    // cause other calls to find_POA that are creating the same
02bb8761fcce Initial load
duke
parents:
diff changeset
   866
                    // POA to block on the waitUntilRunning call above.
02bb8761fcce Initial load
duke
parents:
diff changeset
   867
                    // Initialization must be completed by a call to create_POA
02bb8761fcce Initial load
duke
parents:
diff changeset
   868
                    // inside the unknown_adapter upcall.  Note that
02bb8761fcce Initial load
duke
parents:
diff changeset
   869
                    // this.poaMutex must be held here so that this.children
02bb8761fcce Initial load
duke
parents:
diff changeset
   870
                    // can be safely updated.  The state is set to STATE_INIT
02bb8761fcce Initial load
duke
parents:
diff changeset
   871
                    // so that initialize can make the correct state transition
02bb8761fcce Initial load
duke
parents:
diff changeset
   872
                    // when create_POA is called inside the AdapterActivator.
02bb8761fcce Initial load
duke
parents:
diff changeset
   873
                    // This avoids activating the new POA too soon
02bb8761fcce Initial load
duke
parents:
diff changeset
   874
                    // by transitioning to STATE_RUN after unknown_adapter
02bb8761fcce Initial load
duke
parents:
diff changeset
   875
                    // returns.
02bb8761fcce Initial load
duke
parents:
diff changeset
   876
                    found = new POAImpl( name, this, getORB(), STATE_INIT ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   877
02bb8761fcce Initial load
duke
parents:
diff changeset
   878
                    if (debug) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   879
                        ORBUtility.dprint( this,
02bb8761fcce Initial load
duke
parents:
diff changeset
   880
                            "Calling find_POA: created poa " + found ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   881
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   882
02bb8761fcce Initial load
duke
parents:
diff changeset
   883
                    act = activator ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   884
                } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   885
                    throw new AdapterNonExistent();
02bb8761fcce Initial load
duke
parents:
diff changeset
   886
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   887
            } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
   888
                unlock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   889
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   890
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   891
02bb8761fcce Initial load
duke
parents:
diff changeset
   892
        // assert (found != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   893
        // assert not holding this.poaMutex OR found.poaMutex
02bb8761fcce Initial load
duke
parents:
diff changeset
   894
02bb8761fcce Initial load
duke
parents:
diff changeset
   895
        // We must not hold either this.poaMutex or found.poaMutex here while
02bb8761fcce Initial load
duke
parents:
diff changeset
   896
        // waiting for intialization of found to complete to prevent possible
02bb8761fcce Initial load
duke
parents:
diff changeset
   897
        // deadlocks.
02bb8761fcce Initial load
duke
parents:
diff changeset
   898
02bb8761fcce Initial load
duke
parents:
diff changeset
   899
        if (act != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   900
            boolean status = false ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   901
            boolean adapterResult = false ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   902
02bb8761fcce Initial load
duke
parents:
diff changeset
   903
            if (debug) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   904
                ORBUtility.dprint( this,
02bb8761fcce Initial load
duke
parents:
diff changeset
   905
                    "Calling find_POA: calling AdapterActivator"  ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   906
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   907
02bb8761fcce Initial load
duke
parents:
diff changeset
   908
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   909
                // Prevent more than one thread at a time from executing in act
02bb8761fcce Initial load
duke
parents:
diff changeset
   910
                // in case act is shared between multiple POAs.
02bb8761fcce Initial load
duke
parents:
diff changeset
   911
                synchronized (act) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   912
                    status = act.unknown_adapter(this, name);
02bb8761fcce Initial load
duke
parents:
diff changeset
   913
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   914
            } catch (SystemException exc) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   915
                throw omgLifecycleWrapper().adapterActivatorException( exc,
02bb8761fcce Initial load
duke
parents:
diff changeset
   916
                    name, poaId.toString() ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   917
            } catch (Throwable thr) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   918
                // ignore most non-system exceptions, but log them for
02bb8761fcce Initial load
duke
parents:
diff changeset
   919
                // diagnostic purposes.
02bb8761fcce Initial load
duke
parents:
diff changeset
   920
                lifecycleWrapper().unexpectedException( thr, this.toString() ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   921
02bb8761fcce Initial load
duke
parents:
diff changeset
   922
                if (thr instanceof ThreadDeath)
02bb8761fcce Initial load
duke
parents:
diff changeset
   923
                    throw (ThreadDeath)thr ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   924
            } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
   925
                // At this point, we have completed adapter activation.
02bb8761fcce Initial load
duke
parents:
diff changeset
   926
                // Whether this was successful or not, we must call
02bb8761fcce Initial load
duke
parents:
diff changeset
   927
                // destroyIfNotInitDone so that calls to enter() and create_POA()
02bb8761fcce Initial load
duke
parents:
diff changeset
   928
                // that are waiting can execute again.  Failing to do this
02bb8761fcce Initial load
duke
parents:
diff changeset
   929
                // will cause the system to hang in complex tests.
02bb8761fcce Initial load
duke
parents:
diff changeset
   930
                adapterResult = found.destroyIfNotInitDone() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   931
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   932
02bb8761fcce Initial load
duke
parents:
diff changeset
   933
            if (status) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   934
                if (!adapterResult)
02bb8761fcce Initial load
duke
parents:
diff changeset
   935
                    throw omgLifecycleWrapper().adapterActivatorException( name,
02bb8761fcce Initial load
duke
parents:
diff changeset
   936
                        poaId.toString() ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   937
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   938
                if (debug) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   939
                    ORBUtility.dprint( this,
02bb8761fcce Initial load
duke
parents:
diff changeset
   940
                        "Calling find_POA: AdapterActivator returned false"  ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   941
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   942
02bb8761fcce Initial load
duke
parents:
diff changeset
   943
                // OMG Issue 3740 is resolved to throw AdapterNonExistent if
02bb8761fcce Initial load
duke
parents:
diff changeset
   944
                // unknown_adapter() returns false.
02bb8761fcce Initial load
duke
parents:
diff changeset
   945
                throw new AdapterNonExistent();
02bb8761fcce Initial load
duke
parents:
diff changeset
   946
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   947
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   948
02bb8761fcce Initial load
duke
parents:
diff changeset
   949
        return found;
02bb8761fcce Initial load
duke
parents:
diff changeset
   950
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   951
02bb8761fcce Initial load
duke
parents:
diff changeset
   952
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   953
     * <code>destroy</code>
02bb8761fcce Initial load
duke
parents:
diff changeset
   954
     * <b>Section 3.3.8.4</b>
02bb8761fcce Initial load
duke
parents:
diff changeset
   955
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   956
    public void destroy(boolean etherealize, boolean wait_for_completion)
02bb8761fcce Initial load
duke
parents:
diff changeset
   957
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   958
        // This is to avoid deadlock
02bb8761fcce Initial load
duke
parents:
diff changeset
   959
        if (wait_for_completion && getORB().isDuringDispatch()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   960
            throw lifecycleWrapper().destroyDeadlock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   961
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   962
02bb8761fcce Initial load
duke
parents:
diff changeset
   963
        DestroyThread destroyer = new DestroyThread( etherealize, debug );
02bb8761fcce Initial load
duke
parents:
diff changeset
   964
        destroyer.doIt( this, wait_for_completion ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   965
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   966
02bb8761fcce Initial load
duke
parents:
diff changeset
   967
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   968
     * <code>create_thread_policy</code>
02bb8761fcce Initial load
duke
parents:
diff changeset
   969
     * <b>Section 3.3.8.5</b>
02bb8761fcce Initial load
duke
parents:
diff changeset
   970
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   971
    public ThreadPolicy create_thread_policy(
02bb8761fcce Initial load
duke
parents:
diff changeset
   972
        ThreadPolicyValue value)
02bb8761fcce Initial load
duke
parents:
diff changeset
   973
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   974
        return new ThreadPolicyImpl(value);
02bb8761fcce Initial load
duke
parents:
diff changeset
   975
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   976
02bb8761fcce Initial load
duke
parents:
diff changeset
   977
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   978
     * <code>create_lifespan_policy</code>
02bb8761fcce Initial load
duke
parents:
diff changeset
   979
     * <b>Section 3.3.8.5</b>
02bb8761fcce Initial load
duke
parents:
diff changeset
   980
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   981
    public LifespanPolicy create_lifespan_policy(
02bb8761fcce Initial load
duke
parents:
diff changeset
   982
        LifespanPolicyValue value)
02bb8761fcce Initial load
duke
parents:
diff changeset
   983
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   984
        return new LifespanPolicyImpl(value);
02bb8761fcce Initial load
duke
parents:
diff changeset
   985
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   986
02bb8761fcce Initial load
duke
parents:
diff changeset
   987
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   988
     * <code>create_id_uniqueness_policy</code>
02bb8761fcce Initial load
duke
parents:
diff changeset
   989
     * <b>Section 3.3.8.5</b>
02bb8761fcce Initial load
duke
parents:
diff changeset
   990
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   991
    public IdUniquenessPolicy create_id_uniqueness_policy(
02bb8761fcce Initial load
duke
parents:
diff changeset
   992
        IdUniquenessPolicyValue value)
02bb8761fcce Initial load
duke
parents:
diff changeset
   993
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   994
        return new IdUniquenessPolicyImpl(value);
02bb8761fcce Initial load
duke
parents:
diff changeset
   995
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   996
02bb8761fcce Initial load
duke
parents:
diff changeset
   997
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   998
     * <code>create_id_assignment_policy</code>
02bb8761fcce Initial load
duke
parents:
diff changeset
   999
     * <b>Section 3.3.8.5</b>
02bb8761fcce Initial load
duke
parents:
diff changeset
  1000
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1001
    public IdAssignmentPolicy create_id_assignment_policy(
02bb8761fcce Initial load
duke
parents:
diff changeset
  1002
        IdAssignmentPolicyValue value)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1003
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1004
        return new IdAssignmentPolicyImpl(value);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1005
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1006
02bb8761fcce Initial load
duke
parents:
diff changeset
  1007
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1008
     * <code>create_implicit_activation_policy</code>
02bb8761fcce Initial load
duke
parents:
diff changeset
  1009
     * <b>Section 3.3.8.5</b>
02bb8761fcce Initial load
duke
parents:
diff changeset
  1010
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1011
    public ImplicitActivationPolicy create_implicit_activation_policy(
02bb8761fcce Initial load
duke
parents:
diff changeset
  1012
        ImplicitActivationPolicyValue value)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1013
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1014
        return new ImplicitActivationPolicyImpl(value);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1015
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1016
02bb8761fcce Initial load
duke
parents:
diff changeset
  1017
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1018
     * <code>create_servant_retention_policy</code>
02bb8761fcce Initial load
duke
parents:
diff changeset
  1019
     * <b>Section 3.3.8.5</b>
02bb8761fcce Initial load
duke
parents:
diff changeset
  1020
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1021
    public ServantRetentionPolicy create_servant_retention_policy(
02bb8761fcce Initial load
duke
parents:
diff changeset
  1022
        ServantRetentionPolicyValue value)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1023
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1024
        return new ServantRetentionPolicyImpl(value);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1025
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1026
02bb8761fcce Initial load
duke
parents:
diff changeset
  1027
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1028
     * <code>create_request_processing_policy</code>
02bb8761fcce Initial load
duke
parents:
diff changeset
  1029
     * <b>Section 3.3.8.5</b>
02bb8761fcce Initial load
duke
parents:
diff changeset
  1030
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1031
    public RequestProcessingPolicy create_request_processing_policy(
02bb8761fcce Initial load
duke
parents:
diff changeset
  1032
        RequestProcessingPolicyValue value)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1033
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1034
        return new RequestProcessingPolicyImpl(value);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1035
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1036
02bb8761fcce Initial load
duke
parents:
diff changeset
  1037
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1038
     * <code>the_name</code>
02bb8761fcce Initial load
duke
parents:
diff changeset
  1039
     * <b>Section 3.3.8.6</b>
02bb8761fcce Initial load
duke
parents:
diff changeset
  1040
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1041
    public String the_name()
02bb8761fcce Initial load
duke
parents:
diff changeset
  1042
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1043
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1044
            lock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1045
02bb8761fcce Initial load
duke
parents:
diff changeset
  1046
            return name;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1047
        } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1048
            unlock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1049
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1050
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1051
02bb8761fcce Initial load
duke
parents:
diff changeset
  1052
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1053
     * <code>the_parent</code>
02bb8761fcce Initial load
duke
parents:
diff changeset
  1054
     * <b>Section 3.3.8.7</b>
02bb8761fcce Initial load
duke
parents:
diff changeset
  1055
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1056
    public POA the_parent()
02bb8761fcce Initial load
duke
parents:
diff changeset
  1057
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1058
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1059
            lock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1060
02bb8761fcce Initial load
duke
parents:
diff changeset
  1061
            return parent;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1062
        } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1063
            unlock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1064
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1065
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1066
02bb8761fcce Initial load
duke
parents:
diff changeset
  1067
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1068
     * <code>the_children</code>
02bb8761fcce Initial load
duke
parents:
diff changeset
  1069
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1070
    public org.omg.PortableServer.POA[] the_children()
02bb8761fcce Initial load
duke
parents:
diff changeset
  1071
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1072
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1073
            lock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1074
02bb8761fcce Initial load
duke
parents:
diff changeset
  1075
            Collection coll = children.values() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1076
            int size = coll.size() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1077
            POA[] result = new POA[ size ] ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1078
            int index = 0 ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1079
            Iterator iter = coll.iterator() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1080
            while (iter.hasNext()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1081
                POA poa = (POA)(iter.next()) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1082
                result[ index++ ] = poa ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1083
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1084
02bb8761fcce Initial load
duke
parents:
diff changeset
  1085
            return result ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1086
        } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1087
            unlock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1088
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1089
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1090
02bb8761fcce Initial load
duke
parents:
diff changeset
  1091
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1092
     * <code>the_POAManager</code>
02bb8761fcce Initial load
duke
parents:
diff changeset
  1093
     * <b>Section 3.3.8.8</b>
02bb8761fcce Initial load
duke
parents:
diff changeset
  1094
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1095
    public POAManager the_POAManager()
02bb8761fcce Initial load
duke
parents:
diff changeset
  1096
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1097
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1098
            lock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1099
02bb8761fcce Initial load
duke
parents:
diff changeset
  1100
            return manager;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1101
        } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1102
            unlock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1103
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1104
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1105
02bb8761fcce Initial load
duke
parents:
diff changeset
  1106
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1107
     * <code>the_activator</code>
02bb8761fcce Initial load
duke
parents:
diff changeset
  1108
     * <b>Section 3.3.8.9</b>
02bb8761fcce Initial load
duke
parents:
diff changeset
  1109
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1110
    public AdapterActivator the_activator()
02bb8761fcce Initial load
duke
parents:
diff changeset
  1111
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1112
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1113
            lock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1114
02bb8761fcce Initial load
duke
parents:
diff changeset
  1115
            return activator;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1116
        } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1117
            unlock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1118
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1119
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1120
02bb8761fcce Initial load
duke
parents:
diff changeset
  1121
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1122
     * <code>the_activator</code>
02bb8761fcce Initial load
duke
parents:
diff changeset
  1123
     * <b>Section 3.3.8.9</b>
02bb8761fcce Initial load
duke
parents:
diff changeset
  1124
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1125
    public void the_activator(AdapterActivator activator)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1126
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1127
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1128
            lock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1129
02bb8761fcce Initial load
duke
parents:
diff changeset
  1130
            if (debug) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1131
                ORBUtility.dprint( this, "Calling the_activator on poa " +
02bb8761fcce Initial load
duke
parents:
diff changeset
  1132
                    this + " activator=" + activator ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1133
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1134
02bb8761fcce Initial load
duke
parents:
diff changeset
  1135
            this.activator = activator;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1136
        } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1137
            unlock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1138
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1139
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1140
02bb8761fcce Initial load
duke
parents:
diff changeset
  1141
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1142
     * <code>get_servant_manager</code>
02bb8761fcce Initial load
duke
parents:
diff changeset
  1143
     * <b>Section 3.3.8.10</b>
02bb8761fcce Initial load
duke
parents:
diff changeset
  1144
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1145
    public ServantManager get_servant_manager() throws WrongPolicy
02bb8761fcce Initial load
duke
parents:
diff changeset
  1146
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1147
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1148
            lock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1149
02bb8761fcce Initial load
duke
parents:
diff changeset
  1150
            return mediator.getServantManager() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1151
        } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1152
            unlock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1153
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1154
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1155
02bb8761fcce Initial load
duke
parents:
diff changeset
  1156
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1157
     * <code>set_servant_manager</code>
02bb8761fcce Initial load
duke
parents:
diff changeset
  1158
     * <b>Section 3.3.8.10</b>
02bb8761fcce Initial load
duke
parents:
diff changeset
  1159
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1160
    public void set_servant_manager(ServantManager servantManager)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1161
        throws WrongPolicy
02bb8761fcce Initial load
duke
parents:
diff changeset
  1162
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1163
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1164
            lock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1165
02bb8761fcce Initial load
duke
parents:
diff changeset
  1166
            if (debug) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1167
                ORBUtility.dprint( this, "Calling set_servant_manager on poa " +
02bb8761fcce Initial load
duke
parents:
diff changeset
  1168
                    this + " servantManager=" + servantManager ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1169
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1170
02bb8761fcce Initial load
duke
parents:
diff changeset
  1171
            mediator.setServantManager( servantManager ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1172
        } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1173
            unlock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1174
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1175
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1176
02bb8761fcce Initial load
duke
parents:
diff changeset
  1177
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1178
     * <code>get_servant</code>
02bb8761fcce Initial load
duke
parents:
diff changeset
  1179
     * <b>Section 3.3.8.12</b>
02bb8761fcce Initial load
duke
parents:
diff changeset
  1180
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1181
    public Servant get_servant() throws NoServant, WrongPolicy
02bb8761fcce Initial load
duke
parents:
diff changeset
  1182
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1183
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1184
            lock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1185
02bb8761fcce Initial load
duke
parents:
diff changeset
  1186
            return mediator.getDefaultServant() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1187
        } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1188
            unlock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1189
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1190
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1191
02bb8761fcce Initial load
duke
parents:
diff changeset
  1192
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1193
     * <code>set_servant</code>
02bb8761fcce Initial load
duke
parents:
diff changeset
  1194
     * <b>Section 3.3.8.13</b>
02bb8761fcce Initial load
duke
parents:
diff changeset
  1195
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1196
    public void set_servant(Servant defaultServant)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1197
        throws WrongPolicy
02bb8761fcce Initial load
duke
parents:
diff changeset
  1198
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1199
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1200
            lock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1201
02bb8761fcce Initial load
duke
parents:
diff changeset
  1202
            if (debug) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1203
                ORBUtility.dprint( this, "Calling set_servant on poa " +
02bb8761fcce Initial load
duke
parents:
diff changeset
  1204
                    this + " defaultServant=" + defaultServant ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1205
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1206
02bb8761fcce Initial load
duke
parents:
diff changeset
  1207
            mediator.setDefaultServant( defaultServant ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1208
        } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1209
            unlock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1210
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1211
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1212
02bb8761fcce Initial load
duke
parents:
diff changeset
  1213
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1214
     * <code>activate_object</code>
02bb8761fcce Initial load
duke
parents:
diff changeset
  1215
     * <b>Section 3.3.8.14</b>
02bb8761fcce Initial load
duke
parents:
diff changeset
  1216
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1217
    public byte[] activate_object(Servant servant)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1218
        throws ServantAlreadyActive, WrongPolicy
02bb8761fcce Initial load
duke
parents:
diff changeset
  1219
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1220
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1221
            lock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1222
02bb8761fcce Initial load
duke
parents:
diff changeset
  1223
            if (debug) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1224
                ORBUtility.dprint( this,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1225
                    "Calling activate_object on poa " + this +
02bb8761fcce Initial load
duke
parents:
diff changeset
  1226
                    " (servant=" + servant + ")" ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1227
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1228
02bb8761fcce Initial load
duke
parents:
diff changeset
  1229
            // Allocate a new system-generated object-id.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1230
            // This will throw WrongPolicy if not SYSTEM_ID
02bb8761fcce Initial load
duke
parents:
diff changeset
  1231
            // policy.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1232
            byte[] id = mediator.newSystemId();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1233
02bb8761fcce Initial load
duke
parents:
diff changeset
  1234
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1235
                mediator.activateObject( id, servant ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1236
            } catch (ObjectAlreadyActive oaa) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1237
                // This exception can not occur in this case,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1238
                // since id is always brand new.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1239
                //
02bb8761fcce Initial load
duke
parents:
diff changeset
  1240
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1241
02bb8761fcce Initial load
duke
parents:
diff changeset
  1242
            return id ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1243
        } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1244
            if (debug) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1245
                ORBUtility.dprint( this,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1246
                    "Exiting activate_object on poa " + this ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1247
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1248
02bb8761fcce Initial load
duke
parents:
diff changeset
  1249
            unlock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1250
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1251
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1252
02bb8761fcce Initial load
duke
parents:
diff changeset
  1253
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1254
     * <code>activate_object_with_id</code>
02bb8761fcce Initial load
duke
parents:
diff changeset
  1255
     * <b>Section 3.3.8.15</b>
02bb8761fcce Initial load
duke
parents:
diff changeset
  1256
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1257
    public void activate_object_with_id(byte[] id,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1258
                                                     Servant servant)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1259
        throws ObjectAlreadyActive, ServantAlreadyActive, WrongPolicy
02bb8761fcce Initial load
duke
parents:
diff changeset
  1260
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1261
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1262
            lock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1263
02bb8761fcce Initial load
duke
parents:
diff changeset
  1264
            if (debug) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1265
                ORBUtility.dprint( this,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1266
                    "Calling activate_object_with_id on poa " + this +
02bb8761fcce Initial load
duke
parents:
diff changeset
  1267
                    " (servant=" + servant + " id=" + id + ")" ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1268
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1269
02bb8761fcce Initial load
duke
parents:
diff changeset
  1270
            // Clone the id to avoid possible errors due to aliasing
02bb8761fcce Initial load
duke
parents:
diff changeset
  1271
            // (e.g. the client passes the id in and then changes it later).
02bb8761fcce Initial load
duke
parents:
diff changeset
  1272
            byte[] idClone = (byte[])(id.clone()) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1273
02bb8761fcce Initial load
duke
parents:
diff changeset
  1274
            mediator.activateObject( idClone, servant ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1275
        } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1276
            if (debug) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1277
                ORBUtility.dprint( this,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1278
                    "Exiting activate_object_with_id on poa " + this ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1279
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1280
02bb8761fcce Initial load
duke
parents:
diff changeset
  1281
            unlock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1282
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1283
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1284
02bb8761fcce Initial load
duke
parents:
diff changeset
  1285
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1286
     * <code>deactivate_object</code>
02bb8761fcce Initial load
duke
parents:
diff changeset
  1287
     * <b>3.3.8.16</b>
02bb8761fcce Initial load
duke
parents:
diff changeset
  1288
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1289
    public void deactivate_object(byte[] id)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1290
        throws ObjectNotActive, WrongPolicy
02bb8761fcce Initial load
duke
parents:
diff changeset
  1291
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1292
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1293
            lock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1294
02bb8761fcce Initial load
duke
parents:
diff changeset
  1295
            if (debug) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1296
                ORBUtility.dprint( this,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1297
                    "Calling deactivate_object on poa " + this +
02bb8761fcce Initial load
duke
parents:
diff changeset
  1298
                    " (id=" + id + ")" ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1299
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1300
02bb8761fcce Initial load
duke
parents:
diff changeset
  1301
            mediator.deactivateObject( id ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1302
        } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1303
            if (debug) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1304
                ORBUtility.dprint( this,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1305
                    "Exiting deactivate_object on poa " + this ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1306
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1307
02bb8761fcce Initial load
duke
parents:
diff changeset
  1308
            unlock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1309
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1310
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1311
02bb8761fcce Initial load
duke
parents:
diff changeset
  1312
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1313
     * <code>create_reference</code>
02bb8761fcce Initial load
duke
parents:
diff changeset
  1314
     * <b>3.3.8.17</b>
02bb8761fcce Initial load
duke
parents:
diff changeset
  1315
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1316
    public org.omg.CORBA.Object create_reference(String repId)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1317
        throws WrongPolicy
02bb8761fcce Initial load
duke
parents:
diff changeset
  1318
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1319
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1320
            lock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1321
02bb8761fcce Initial load
duke
parents:
diff changeset
  1322
            if (debug) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1323
                ORBUtility.dprint( this, "Calling create_reference(repId=" +
02bb8761fcce Initial load
duke
parents:
diff changeset
  1324
                    repId + ") on poa " + this ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1325
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1326
02bb8761fcce Initial load
duke
parents:
diff changeset
  1327
            return makeObject( repId, mediator.newSystemId()) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1328
        } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1329
            unlock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1330
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1331
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1332
02bb8761fcce Initial load
duke
parents:
diff changeset
  1333
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1334
     * <code>create_reference_with_id</code>
02bb8761fcce Initial load
duke
parents:
diff changeset
  1335
     * <b>3.3.8.18</b>
02bb8761fcce Initial load
duke
parents:
diff changeset
  1336
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1337
    public org.omg.CORBA.Object
02bb8761fcce Initial load
duke
parents:
diff changeset
  1338
        create_reference_with_id(byte[] oid, String repId)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1339
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1340
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1341
            lock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1342
02bb8761fcce Initial load
duke
parents:
diff changeset
  1343
            if (debug) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1344
                ORBUtility.dprint( this,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1345
                    "Calling create_reference_with_id(oid=" +
02bb8761fcce Initial load
duke
parents:
diff changeset
  1346
                    oid + " repId=" + repId + ") on poa " + this ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1347
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1348
02bb8761fcce Initial load
duke
parents:
diff changeset
  1349
            // Clone the id to avoid possible errors due to aliasing
02bb8761fcce Initial load
duke
parents:
diff changeset
  1350
            // (e.g. the client passes the id in and then changes it later).
02bb8761fcce Initial load
duke
parents:
diff changeset
  1351
            byte[] idClone = (byte[])(oid.clone()) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1352
02bb8761fcce Initial load
duke
parents:
diff changeset
  1353
            return makeObject( repId, idClone ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1354
        } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1355
            unlock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1356
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1357
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1358
02bb8761fcce Initial load
duke
parents:
diff changeset
  1359
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1360
     * <code>servant_to_id</code>
02bb8761fcce Initial load
duke
parents:
diff changeset
  1361
     * <b>3.3.8.19</b>
02bb8761fcce Initial load
duke
parents:
diff changeset
  1362
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1363
    public byte[] servant_to_id(Servant servant)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1364
        throws ServantNotActive, WrongPolicy
02bb8761fcce Initial load
duke
parents:
diff changeset
  1365
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1366
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1367
            lock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1368
02bb8761fcce Initial load
duke
parents:
diff changeset
  1369
            if (debug) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1370
                ORBUtility.dprint( this, "Calling servant_to_id(servant=" +
02bb8761fcce Initial load
duke
parents:
diff changeset
  1371
                    servant + ") on poa " + this ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1372
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1373
02bb8761fcce Initial load
duke
parents:
diff changeset
  1374
            return mediator.servantToId( servant ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1375
        } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1376
            unlock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1377
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1378
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1379
02bb8761fcce Initial load
duke
parents:
diff changeset
  1380
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1381
     * <code>servant_to_reference</code>
02bb8761fcce Initial load
duke
parents:
diff changeset
  1382
     * <b>3.3.8.20</b>
02bb8761fcce Initial load
duke
parents:
diff changeset
  1383
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1384
    public org.omg.CORBA.Object servant_to_reference(Servant servant)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1385
        throws ServantNotActive, WrongPolicy
02bb8761fcce Initial load
duke
parents:
diff changeset
  1386
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1387
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1388
            lock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1389
02bb8761fcce Initial load
duke
parents:
diff changeset
  1390
            if (debug) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1391
                ORBUtility.dprint( this,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1392
                    "Calling servant_to_reference(servant=" +
02bb8761fcce Initial load
duke
parents:
diff changeset
  1393
                    servant + ") on poa " + this ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1394
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1395
02bb8761fcce Initial load
duke
parents:
diff changeset
  1396
            byte[] oid = mediator.servantToId(servant);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1397
            String repId = servant._all_interfaces( this, oid )[0] ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1398
            return create_reference_with_id(oid, repId);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1399
        } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1400
            unlock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1401
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1402
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1403
02bb8761fcce Initial load
duke
parents:
diff changeset
  1404
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1405
     * <code>reference_to_servant</code>
02bb8761fcce Initial load
duke
parents:
diff changeset
  1406
     * <b>3.3.8.21</b>
02bb8761fcce Initial load
duke
parents:
diff changeset
  1407
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1408
    public Servant reference_to_servant(org.omg.CORBA.Object reference)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1409
        throws ObjectNotActive, WrongPolicy, WrongAdapter
02bb8761fcce Initial load
duke
parents:
diff changeset
  1410
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1411
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1412
            lock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1413
02bb8761fcce Initial load
duke
parents:
diff changeset
  1414
            if (debug) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1415
                ORBUtility.dprint( this,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1416
                    "Calling reference_to_servant(reference=" +
02bb8761fcce Initial load
duke
parents:
diff changeset
  1417
                    reference + ") on poa " + this ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1418
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1419
02bb8761fcce Initial load
duke
parents:
diff changeset
  1420
            if ( state >= STATE_DESTROYING ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1421
                throw lifecycleWrapper().adapterDestroyed() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1422
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1423
02bb8761fcce Initial load
duke
parents:
diff changeset
  1424
            // reference_to_id should throw WrongAdapter
02bb8761fcce Initial load
duke
parents:
diff changeset
  1425
            // if the objref was not created by this POA
02bb8761fcce Initial load
duke
parents:
diff changeset
  1426
            byte [] id = internalReferenceToId(reference);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1427
02bb8761fcce Initial load
duke
parents:
diff changeset
  1428
            return mediator.idToServant( id ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1429
        } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1430
            unlock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1431
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1432
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1433
02bb8761fcce Initial load
duke
parents:
diff changeset
  1434
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1435
     * <code>reference_to_id</code>
02bb8761fcce Initial load
duke
parents:
diff changeset
  1436
     * <b>3.3.8.22</b>
02bb8761fcce Initial load
duke
parents:
diff changeset
  1437
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1438
    public byte[] reference_to_id(org.omg.CORBA.Object reference)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1439
        throws WrongAdapter, WrongPolicy
02bb8761fcce Initial load
duke
parents:
diff changeset
  1440
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1441
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1442
            lock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1443
02bb8761fcce Initial load
duke
parents:
diff changeset
  1444
            if (debug) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1445
                ORBUtility.dprint( this, "Calling reference_to_id(reference=" +
02bb8761fcce Initial load
duke
parents:
diff changeset
  1446
                    reference + ") on poa " + this ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1447
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1448
02bb8761fcce Initial load
duke
parents:
diff changeset
  1449
            if( state >= STATE_DESTROYING ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1450
                throw lifecycleWrapper().adapterDestroyed() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1451
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1452
02bb8761fcce Initial load
duke
parents:
diff changeset
  1453
            return internalReferenceToId( reference ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1454
        } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1455
            unlock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1456
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1457
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1458
02bb8761fcce Initial load
duke
parents:
diff changeset
  1459
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1460
     * <code>id_to_servant</code>
02bb8761fcce Initial load
duke
parents:
diff changeset
  1461
     * <b>3.3.8.23</b>
02bb8761fcce Initial load
duke
parents:
diff changeset
  1462
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1463
    public Servant id_to_servant(byte[] id)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1464
        throws ObjectNotActive, WrongPolicy
02bb8761fcce Initial load
duke
parents:
diff changeset
  1465
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1466
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1467
            lock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1468
02bb8761fcce Initial load
duke
parents:
diff changeset
  1469
            if (debug) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1470
                ORBUtility.dprint( this, "Calling id_to_servant(id=" +
02bb8761fcce Initial load
duke
parents:
diff changeset
  1471
                    id + ") on poa " + this ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1472
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1473
02bb8761fcce Initial load
duke
parents:
diff changeset
  1474
            if( state >= STATE_DESTROYING ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1475
                throw lifecycleWrapper().adapterDestroyed() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1476
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1477
            return mediator.idToServant( id ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1478
        } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1479
            unlock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1480
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1481
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1482
02bb8761fcce Initial load
duke
parents:
diff changeset
  1483
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1484
     * <code>id_to_reference</code>
02bb8761fcce Initial load
duke
parents:
diff changeset
  1485
     * <b>3.3.8.24</b>
02bb8761fcce Initial load
duke
parents:
diff changeset
  1486
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1487
    public org.omg.CORBA.Object id_to_reference(byte[] id)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1488
        throws ObjectNotActive, WrongPolicy
02bb8761fcce Initial load
duke
parents:
diff changeset
  1489
02bb8761fcce Initial load
duke
parents:
diff changeset
  1490
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1491
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1492
            lock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1493
02bb8761fcce Initial load
duke
parents:
diff changeset
  1494
            if (debug) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1495
                ORBUtility.dprint( this, "Calling id_to_reference(id=" +
02bb8761fcce Initial load
duke
parents:
diff changeset
  1496
                    id + ") on poa " + this ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1497
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1498
02bb8761fcce Initial load
duke
parents:
diff changeset
  1499
            if( state >= STATE_DESTROYING ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1500
                throw lifecycleWrapper().adapterDestroyed() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1501
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1502
02bb8761fcce Initial load
duke
parents:
diff changeset
  1503
            Servant s = mediator.idToServant( id ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1504
            String repId = s._all_interfaces( this, id )[0] ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1505
            return makeObject(repId, id );
02bb8761fcce Initial load
duke
parents:
diff changeset
  1506
        } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1507
            unlock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1508
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1509
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1510
02bb8761fcce Initial load
duke
parents:
diff changeset
  1511
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1512
     * <code>id</code>
02bb8761fcce Initial load
duke
parents:
diff changeset
  1513
     * <b>11.3.8.26 in ptc/00-08-06</b>
02bb8761fcce Initial load
duke
parents:
diff changeset
  1514
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1515
    public byte[] id()
02bb8761fcce Initial load
duke
parents:
diff changeset
  1516
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1517
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1518
            lock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1519
02bb8761fcce Initial load
duke
parents:
diff changeset
  1520
            return getAdapterId() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1521
        } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1522
            unlock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1523
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1524
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1525
02bb8761fcce Initial load
duke
parents:
diff changeset
  1526
    //***************************************************************
02bb8761fcce Initial load
duke
parents:
diff changeset
  1527
    //Implementation of ObjectAdapter interface
02bb8761fcce Initial load
duke
parents:
diff changeset
  1528
    //***************************************************************
02bb8761fcce Initial load
duke
parents:
diff changeset
  1529
02bb8761fcce Initial load
duke
parents:
diff changeset
  1530
    public Policy getEffectivePolicy( int type )
02bb8761fcce Initial load
duke
parents:
diff changeset
  1531
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1532
        return mediator.getPolicies().get_effective_policy( type ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1533
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1534
02bb8761fcce Initial load
duke
parents:
diff changeset
  1535
    public int getManagerId()
02bb8761fcce Initial load
duke
parents:
diff changeset
  1536
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1537
        return manager.getManagerId() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1538
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1539
02bb8761fcce Initial load
duke
parents:
diff changeset
  1540
    public short getState()
02bb8761fcce Initial load
duke
parents:
diff changeset
  1541
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1542
        return manager.getORTState() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1543
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1544
02bb8761fcce Initial load
duke
parents:
diff changeset
  1545
    public String[] getInterfaces( java.lang.Object servant, byte[] objectId )
02bb8761fcce Initial load
duke
parents:
diff changeset
  1546
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1547
        Servant serv = (Servant)servant ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1548
        return serv._all_interfaces( this, objectId ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1549
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1550
02bb8761fcce Initial load
duke
parents:
diff changeset
  1551
    protected ObjectCopierFactory getObjectCopierFactory()
02bb8761fcce Initial load
duke
parents:
diff changeset
  1552
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1553
        int copierId = mediator.getPolicies().getCopierId() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1554
        CopierManager cm = getORB().getCopierManager() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1555
        return cm.getObjectCopierFactory( copierId ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1556
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1557
02bb8761fcce Initial load
duke
parents:
diff changeset
  1558
    public void enter() throws OADestroyed
02bb8761fcce Initial load
duke
parents:
diff changeset
  1559
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1560
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1561
            lock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1562
02bb8761fcce Initial load
duke
parents:
diff changeset
  1563
            if (debug) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1564
                ORBUtility.dprint( this, "Calling enter on poa " + this ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1565
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1566
02bb8761fcce Initial load
duke
parents:
diff changeset
  1567
            // Avoid deadlock if this is the thread that is processing the
02bb8761fcce Initial load
duke
parents:
diff changeset
  1568
            // POA.destroy because this is the only thread that can notify
02bb8761fcce Initial load
duke
parents:
diff changeset
  1569
            // waiters on beingDestroyedCV.  This can happen if an
02bb8761fcce Initial load
duke
parents:
diff changeset
  1570
            // etherealize upcall invokes a method on a colocated object
02bb8761fcce Initial load
duke
parents:
diff changeset
  1571
            // served by this POA.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1572
            while ((state == STATE_DESTROYING) &&
02bb8761fcce Initial load
duke
parents:
diff changeset
  1573
                (isDestroying.get() == Boolean.FALSE)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1574
                try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1575
                    beingDestroyedCV.await();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1576
                } catch (InterruptedException ex) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1577
                    // NO-OP
02bb8761fcce Initial load
duke
parents:
diff changeset
  1578
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1579
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1580
02bb8761fcce Initial load
duke
parents:
diff changeset
  1581
            if (!waitUntilRunning())
02bb8761fcce Initial load
duke
parents:
diff changeset
  1582
                throw new OADestroyed() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1583
02bb8761fcce Initial load
duke
parents:
diff changeset
  1584
            invocationCount++;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1585
        } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1586
            if (debug) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1587
                ORBUtility.dprint( this, "Exiting enter on poa " + this ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1588
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1589
02bb8761fcce Initial load
duke
parents:
diff changeset
  1590
            unlock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1591
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1592
02bb8761fcce Initial load
duke
parents:
diff changeset
  1593
        manager.enter();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1594
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1595
02bb8761fcce Initial load
duke
parents:
diff changeset
  1596
    public void exit()
02bb8761fcce Initial load
duke
parents:
diff changeset
  1597
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1598
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1599
            lock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1600
02bb8761fcce Initial load
duke
parents:
diff changeset
  1601
            if (debug) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1602
                ORBUtility.dprint( this, "Calling exit on poa " + this ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1603
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1604
02bb8761fcce Initial load
duke
parents:
diff changeset
  1605
            invocationCount--;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1606
02bb8761fcce Initial load
duke
parents:
diff changeset
  1607
            if ((invocationCount == 0) && (state == STATE_DESTROYING)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1608
                invokeCV.broadcast();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1609
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1610
        } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1611
            if (debug) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1612
                ORBUtility.dprint( this, "Exiting exit on poa " + this ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1613
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1614
02bb8761fcce Initial load
duke
parents:
diff changeset
  1615
            unlock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1616
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1617
02bb8761fcce Initial load
duke
parents:
diff changeset
  1618
        manager.exit();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1619
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1620
02bb8761fcce Initial load
duke
parents:
diff changeset
  1621
    public void getInvocationServant( OAInvocationInfo info )
02bb8761fcce Initial load
duke
parents:
diff changeset
  1622
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1623
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1624
            lock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1625
02bb8761fcce Initial load
duke
parents:
diff changeset
  1626
            if (debug) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1627
                ORBUtility.dprint( this,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1628
                    "Calling getInvocationServant on poa " + this ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1629
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1630
02bb8761fcce Initial load
duke
parents:
diff changeset
  1631
            java.lang.Object servant = null ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1632
02bb8761fcce Initial load
duke
parents:
diff changeset
  1633
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1634
                servant = mediator.getInvocationServant( info.id(),
02bb8761fcce Initial load
duke
parents:
diff changeset
  1635
                    info.getOperation() );
02bb8761fcce Initial load
duke
parents:
diff changeset
  1636
            } catch (ForwardRequest freq) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1637
                throw new ForwardException( getORB(), freq.forward_reference ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1638
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1639
02bb8761fcce Initial load
duke
parents:
diff changeset
  1640
            info.setServant( servant ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1641
        } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1642
            if (debug) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1643
                ORBUtility.dprint( this,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1644
                    "Exiting getInvocationServant on poa " + this ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1645
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1646
02bb8761fcce Initial load
duke
parents:
diff changeset
  1647
            unlock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1648
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1649
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1650
02bb8761fcce Initial load
duke
parents:
diff changeset
  1651
    public org.omg.CORBA.Object getLocalServant( byte[] objectId )
02bb8761fcce Initial load
duke
parents:
diff changeset
  1652
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1653
        return null ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1654
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1655
02bb8761fcce Initial load
duke
parents:
diff changeset
  1656
    /** Called from the subcontract to let this POA cleanup after an
02bb8761fcce Initial load
duke
parents:
diff changeset
  1657
     *  invocation. Note: If getServant was called, then returnServant
02bb8761fcce Initial load
duke
parents:
diff changeset
  1658
     *  MUST be called, even in the case of exceptions.  This may be
02bb8761fcce Initial load
duke
parents:
diff changeset
  1659
     *  called multiple times for a single request.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1660
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1661
    public void returnServant()
02bb8761fcce Initial load
duke
parents:
diff changeset
  1662
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1663
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1664
            lock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1665
02bb8761fcce Initial load
duke
parents:
diff changeset
  1666
            if (debug) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1667
                ORBUtility.dprint( this,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1668
                    "Calling returnServant on poa " + this  ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1669
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1670
02bb8761fcce Initial load
duke
parents:
diff changeset
  1671
            mediator.returnServant();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1672
        } catch (Throwable thr) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1673
            if (debug) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1674
                ORBUtility.dprint( this,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1675
                    "Exception " + thr + " in returnServant on poa " + this  ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1676
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1677
02bb8761fcce Initial load
duke
parents:
diff changeset
  1678
            if (thr instanceof Error)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1679
                throw (Error)thr ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1680
            else if (thr instanceof RuntimeException)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1681
                throw (RuntimeException)thr ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1682
02bb8761fcce Initial load
duke
parents:
diff changeset
  1683
        } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1684
            if (debug) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1685
                ORBUtility.dprint( this,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1686
                    "Exiting returnServant on poa " + this  ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1687
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1688
02bb8761fcce Initial load
duke
parents:
diff changeset
  1689
            unlock() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1690
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1691
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1692
}