corba/src/share/classes/com/sun/corba/se/impl/interceptors/PIHandlerImpl.java
author coffeys
Wed, 27 Jun 2012 21:09:29 +0100
changeset 13171 1ac5e9a54a6e
parent 7672 aec650969dd5
child 18304 56149cf29cf9
permissions -rw-r--r--
7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8 Reviewed-by: lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     1
/*
13171
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 7672
diff changeset
     2
 * Copyright (c) 2002, 2012, 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
package com.sun.corba.se.impl.interceptors;
02bb8761fcce Initial load
duke
parents:
diff changeset
    26
02bb8761fcce Initial load
duke
parents:
diff changeset
    27
import java.util.*;
02bb8761fcce Initial load
duke
parents:
diff changeset
    28
import java.io.IOException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    29
02bb8761fcce Initial load
duke
parents:
diff changeset
    30
import org.omg.CORBA.Any;
02bb8761fcce Initial load
duke
parents:
diff changeset
    31
import org.omg.CORBA.BAD_PARAM;
02bb8761fcce Initial load
duke
parents:
diff changeset
    32
import org.omg.CORBA.BAD_POLICY;
02bb8761fcce Initial load
duke
parents:
diff changeset
    33
import org.omg.CORBA.BAD_INV_ORDER;
02bb8761fcce Initial load
duke
parents:
diff changeset
    34
import org.omg.CORBA.COMM_FAILURE;
02bb8761fcce Initial load
duke
parents:
diff changeset
    35
import org.omg.CORBA.CompletionStatus;
02bb8761fcce Initial load
duke
parents:
diff changeset
    36
import org.omg.CORBA.INTERNAL;
02bb8761fcce Initial load
duke
parents:
diff changeset
    37
import org.omg.CORBA.NVList;
02bb8761fcce Initial load
duke
parents:
diff changeset
    38
import org.omg.CORBA.OBJECT_NOT_EXIST;
02bb8761fcce Initial load
duke
parents:
diff changeset
    39
import org.omg.CORBA.ORBPackage.InvalidName;
02bb8761fcce Initial load
duke
parents:
diff changeset
    40
import org.omg.CORBA.SystemException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    41
import org.omg.CORBA.UserException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    42
import org.omg.CORBA.UNKNOWN;
02bb8761fcce Initial load
duke
parents:
diff changeset
    43
02bb8761fcce Initial load
duke
parents:
diff changeset
    44
import org.omg.CORBA.portable.ApplicationException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    45
import org.omg.CORBA.portable.RemarshalException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    46
02bb8761fcce Initial load
duke
parents:
diff changeset
    47
import org.omg.IOP.CodecFactory;
02bb8761fcce Initial load
duke
parents:
diff changeset
    48
02bb8761fcce Initial load
duke
parents:
diff changeset
    49
import org.omg.PortableInterceptor.ForwardRequest;
02bb8761fcce Initial load
duke
parents:
diff changeset
    50
import org.omg.PortableInterceptor.Current;
02bb8761fcce Initial load
duke
parents:
diff changeset
    51
import org.omg.PortableInterceptor.Interceptor;
02bb8761fcce Initial load
duke
parents:
diff changeset
    52
import org.omg.PortableInterceptor.LOCATION_FORWARD;
02bb8761fcce Initial load
duke
parents:
diff changeset
    53
import org.omg.PortableInterceptor.ORBInitializer;
02bb8761fcce Initial load
duke
parents:
diff changeset
    54
import org.omg.PortableInterceptor.ORBInitInfo;
02bb8761fcce Initial load
duke
parents:
diff changeset
    55
import org.omg.PortableInterceptor.ORBInitInfoPackage.DuplicateName;
02bb8761fcce Initial load
duke
parents:
diff changeset
    56
import org.omg.PortableInterceptor.SUCCESSFUL;
02bb8761fcce Initial load
duke
parents:
diff changeset
    57
import org.omg.PortableInterceptor.SYSTEM_EXCEPTION;
02bb8761fcce Initial load
duke
parents:
diff changeset
    58
import org.omg.PortableInterceptor.TRANSPORT_RETRY;
02bb8761fcce Initial load
duke
parents:
diff changeset
    59
import org.omg.PortableInterceptor.USER_EXCEPTION;
02bb8761fcce Initial load
duke
parents:
diff changeset
    60
import org.omg.PortableInterceptor.PolicyFactory;
13171
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 7672
diff changeset
    61
import org.omg.PortableInterceptor.ObjectReferenceTemplate;
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    62
02bb8761fcce Initial load
duke
parents:
diff changeset
    63
import com.sun.corba.se.pept.encoding.OutputObject;
02bb8761fcce Initial load
duke
parents:
diff changeset
    64
02bb8761fcce Initial load
duke
parents:
diff changeset
    65
import com.sun.corba.se.spi.ior.IOR;
02bb8761fcce Initial load
duke
parents:
diff changeset
    66
import com.sun.corba.se.spi.ior.ObjectKeyTemplate;
02bb8761fcce Initial load
duke
parents:
diff changeset
    67
import com.sun.corba.se.spi.oa.ObjectAdapter;
02bb8761fcce Initial load
duke
parents:
diff changeset
    68
import com.sun.corba.se.spi.orb.ORB;
02bb8761fcce Initial load
duke
parents:
diff changeset
    69
import com.sun.corba.se.spi.orbutil.closure.ClosureFactory;
02bb8761fcce Initial load
duke
parents:
diff changeset
    70
import com.sun.corba.se.spi.protocol.CorbaMessageMediator;
02bb8761fcce Initial load
duke
parents:
diff changeset
    71
import com.sun.corba.se.spi.protocol.ForwardException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    72
import com.sun.corba.se.spi.protocol.PIHandler;
7197
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
    73
import com.sun.corba.se.spi.protocol.RetryType;
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    74
import com.sun.corba.se.spi.logging.CORBALogDomains;
02bb8761fcce Initial load
duke
parents:
diff changeset
    75
02bb8761fcce Initial load
duke
parents:
diff changeset
    76
import com.sun.corba.se.impl.logging.InterceptorsSystemException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    77
import com.sun.corba.se.impl.logging.ORBUtilSystemException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    78
import com.sun.corba.se.impl.logging.OMGSystemException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    79
import com.sun.corba.se.impl.corba.RequestImpl;
02bb8761fcce Initial load
duke
parents:
diff changeset
    80
import com.sun.corba.se.impl.orbutil.ORBClassLoader;
02bb8761fcce Initial load
duke
parents:
diff changeset
    81
import com.sun.corba.se.impl.orbutil.ORBConstants;
02bb8761fcce Initial load
duke
parents:
diff changeset
    82
import com.sun.corba.se.impl.orbutil.ORBUtility;
02bb8761fcce Initial load
duke
parents:
diff changeset
    83
import com.sun.corba.se.impl.orbutil.StackImpl;
02bb8761fcce Initial load
duke
parents:
diff changeset
    84
import com.sun.corba.se.impl.protocol.giopmsgheaders.ReplyMessage;
02bb8761fcce Initial load
duke
parents:
diff changeset
    85
02bb8761fcce Initial load
duke
parents:
diff changeset
    86
/**
02bb8761fcce Initial load
duke
parents:
diff changeset
    87
 * Provides portable interceptor functionality.
02bb8761fcce Initial load
duke
parents:
diff changeset
    88
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    89
public class PIHandlerImpl implements PIHandler
02bb8761fcce Initial load
duke
parents:
diff changeset
    90
{
02bb8761fcce Initial load
duke
parents:
diff changeset
    91
    // REVISIT - delete these after framework merging.
02bb8761fcce Initial load
duke
parents:
diff changeset
    92
    boolean printPushPopEnabled = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
    93
    int pushLevel = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
    94
    private void printPush()
02bb8761fcce Initial load
duke
parents:
diff changeset
    95
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
    96
        if (! printPushPopEnabled) return;
02bb8761fcce Initial load
duke
parents:
diff changeset
    97
        printSpaces(pushLevel);
02bb8761fcce Initial load
duke
parents:
diff changeset
    98
        pushLevel++;
02bb8761fcce Initial load
duke
parents:
diff changeset
    99
        System.out.println("PUSH");
02bb8761fcce Initial load
duke
parents:
diff changeset
   100
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   101
    private void printPop()
02bb8761fcce Initial load
duke
parents:
diff changeset
   102
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   103
        if (! printPushPopEnabled) return;
02bb8761fcce Initial load
duke
parents:
diff changeset
   104
        pushLevel--;
02bb8761fcce Initial load
duke
parents:
diff changeset
   105
        printSpaces(pushLevel);
02bb8761fcce Initial load
duke
parents:
diff changeset
   106
        System.out.println("POP");
02bb8761fcce Initial load
duke
parents:
diff changeset
   107
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   108
    private void printSpaces(int n)
02bb8761fcce Initial load
duke
parents:
diff changeset
   109
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   110
        for (int i = 0; i < n; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   111
            System.out.print(" ");
02bb8761fcce Initial load
duke
parents:
diff changeset
   112
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   113
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   114
13171
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 7672
diff changeset
   115
    private ORB orb;
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 7672
diff changeset
   116
    InterceptorsSystemException wrapper;
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 7672
diff changeset
   117
    ORBUtilSystemException orbutilWrapper;
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 7672
diff changeset
   118
    OMGSystemException omgWrapper;
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   119
02bb8761fcce Initial load
duke
parents:
diff changeset
   120
    // A unique id used in ServerRequestInfo.
02bb8761fcce Initial load
duke
parents:
diff changeset
   121
    // This does not correspond to the GIOP request id.
02bb8761fcce Initial load
duke
parents:
diff changeset
   122
    private int serverRequestIdCounter = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
   123
02bb8761fcce Initial load
duke
parents:
diff changeset
   124
    // Stores the codec factory for producing codecs
02bb8761fcce Initial load
duke
parents:
diff changeset
   125
    CodecFactory codecFactory = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   126
02bb8761fcce Initial load
duke
parents:
diff changeset
   127
    // The arguments passed to the application's main method.  May be null.
02bb8761fcce Initial load
duke
parents:
diff changeset
   128
    // This is used for ORBInitializers and set from set_parameters.
02bb8761fcce Initial load
duke
parents:
diff changeset
   129
    String[] arguments = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   130
02bb8761fcce Initial load
duke
parents:
diff changeset
   131
    // The list of portable interceptors, organized by type:
02bb8761fcce Initial load
duke
parents:
diff changeset
   132
    private InterceptorList interceptorList;
02bb8761fcce Initial load
duke
parents:
diff changeset
   133
02bb8761fcce Initial load
duke
parents:
diff changeset
   134
    // Cached information for optimization - do we have any interceptors
02bb8761fcce Initial load
duke
parents:
diff changeset
   135
    // registered of the given types?  Set during ORB initialization.
02bb8761fcce Initial load
duke
parents:
diff changeset
   136
    private boolean hasIORInterceptors;
02bb8761fcce Initial load
duke
parents:
diff changeset
   137
    private boolean hasClientInterceptors;  // temp always true
02bb8761fcce Initial load
duke
parents:
diff changeset
   138
    private boolean hasServerInterceptors;
02bb8761fcce Initial load
duke
parents:
diff changeset
   139
02bb8761fcce Initial load
duke
parents:
diff changeset
   140
    // The class responsible for invoking interceptors
02bb8761fcce Initial load
duke
parents:
diff changeset
   141
    private InterceptorInvoker interceptorInvoker;
02bb8761fcce Initial load
duke
parents:
diff changeset
   142
02bb8761fcce Initial load
duke
parents:
diff changeset
   143
    // There will be one PICurrent instantiated for every ORB.
02bb8761fcce Initial load
duke
parents:
diff changeset
   144
    private PICurrent current;
02bb8761fcce Initial load
duke
parents:
diff changeset
   145
02bb8761fcce Initial load
duke
parents:
diff changeset
   146
    // This table contains a list of PolicyFactories registered using
02bb8761fcce Initial load
duke
parents:
diff changeset
   147
    // ORBInitInfo.registerPolicyFactory() method.
02bb8761fcce Initial load
duke
parents:
diff changeset
   148
    // Key for the table is PolicyType which is an Integer
02bb8761fcce Initial load
duke
parents:
diff changeset
   149
    // Value is PolicyFactory.
02bb8761fcce Initial load
duke
parents:
diff changeset
   150
    private HashMap policyFactoryTable;
02bb8761fcce Initial load
duke
parents:
diff changeset
   151
02bb8761fcce Initial load
duke
parents:
diff changeset
   152
    // Table to convert from a ReplyMessage.? to a PI replyStatus short.
02bb8761fcce Initial load
duke
parents:
diff changeset
   153
    // Note that this table relies on the order and constants of
02bb8761fcce Initial load
duke
parents:
diff changeset
   154
    // ReplyMessage not to change.
02bb8761fcce Initial load
duke
parents:
diff changeset
   155
    private final static short REPLY_MESSAGE_TO_PI_REPLY_STATUS[] = {
02bb8761fcce Initial load
duke
parents:
diff changeset
   156
        SUCCESSFUL.value,       // = ReplyMessage.NO_EXCEPTION
02bb8761fcce Initial load
duke
parents:
diff changeset
   157
        USER_EXCEPTION.value,   // = ReplyMessage.USER_EXCEPTION
02bb8761fcce Initial load
duke
parents:
diff changeset
   158
        SYSTEM_EXCEPTION.value, // = ReplyMessage.SYSTEM_EXCEPTION
02bb8761fcce Initial load
duke
parents:
diff changeset
   159
        LOCATION_FORWARD.value, // = ReplyMessage.LOCATION_FORWARD
02bb8761fcce Initial load
duke
parents:
diff changeset
   160
        LOCATION_FORWARD.value, // = ReplyMessage.LOCATION_FORWARD_PERM
02bb8761fcce Initial load
duke
parents:
diff changeset
   161
        TRANSPORT_RETRY.value   // = ReplyMessage.NEEDS_ADDRESSING_MODE
02bb8761fcce Initial load
duke
parents:
diff changeset
   162
    };
02bb8761fcce Initial load
duke
parents:
diff changeset
   163
02bb8761fcce Initial load
duke
parents:
diff changeset
   164
    // ThreadLocal containing a stack to store client request info objects
02bb8761fcce Initial load
duke
parents:
diff changeset
   165
    // and a disable count.
02bb8761fcce Initial load
duke
parents:
diff changeset
   166
    private ThreadLocal threadLocalClientRequestInfoStack =
02bb8761fcce Initial load
duke
parents:
diff changeset
   167
        new ThreadLocal() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   168
            protected Object initialValue() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   169
                return new RequestInfoStack();
02bb8761fcce Initial load
duke
parents:
diff changeset
   170
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   171
        };
02bb8761fcce Initial load
duke
parents:
diff changeset
   172
02bb8761fcce Initial load
duke
parents:
diff changeset
   173
    // ThreadLocal containing the current server request info object.
02bb8761fcce Initial load
duke
parents:
diff changeset
   174
    private ThreadLocal threadLocalServerRequestInfoStack =
02bb8761fcce Initial load
duke
parents:
diff changeset
   175
        new ThreadLocal() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   176
            protected Object initialValue() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   177
                return new RequestInfoStack();
02bb8761fcce Initial load
duke
parents:
diff changeset
   178
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   179
        };
02bb8761fcce Initial load
duke
parents:
diff changeset
   180
13171
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 7672
diff changeset
   181
    public void close() {
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 7672
diff changeset
   182
        orb = null;
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 7672
diff changeset
   183
        wrapper = null;
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 7672
diff changeset
   184
        orbutilWrapper = null;
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 7672
diff changeset
   185
        omgWrapper = null;
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 7672
diff changeset
   186
        codecFactory = null;
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 7672
diff changeset
   187
        arguments = null;
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 7672
diff changeset
   188
        interceptorList = null;
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 7672
diff changeset
   189
        interceptorInvoker = null;
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 7672
diff changeset
   190
        current = null;
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 7672
diff changeset
   191
        policyFactoryTable = null;
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 7672
diff changeset
   192
        threadLocalClientRequestInfoStack = null;
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 7672
diff changeset
   193
        threadLocalServerRequestInfoStack = null;
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 7672
diff changeset
   194
    }
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 7672
diff changeset
   195
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   196
    // Class to contain all ThreadLocal data for ClientRequestInfo
02bb8761fcce Initial load
duke
parents:
diff changeset
   197
    // maintenance.
02bb8761fcce Initial load
duke
parents:
diff changeset
   198
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   199
    // We use an ArrayList instead since it is not thread-safe.
02bb8761fcce Initial load
duke
parents:
diff changeset
   200
    // RequestInfoStack is used quite frequently.
02bb8761fcce Initial load
duke
parents:
diff changeset
   201
    private final class RequestInfoStack extends Stack {
02bb8761fcce Initial load
duke
parents:
diff changeset
   202
        // Number of times a request has been made to disable interceptors.
02bb8761fcce Initial load
duke
parents:
diff changeset
   203
        // When this reaches 0, interception hooks are disabled.  Any higher
02bb8761fcce Initial load
duke
parents:
diff changeset
   204
        // value indicates they are enabled.
02bb8761fcce Initial load
duke
parents:
diff changeset
   205
        // NOTE: The is only currently used on the client side.
02bb8761fcce Initial load
duke
parents:
diff changeset
   206
        public int disableCount = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
   207
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   208
02bb8761fcce Initial load
duke
parents:
diff changeset
   209
    public PIHandlerImpl( ORB orb, String[] args ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   210
        this.orb = orb ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   211
        wrapper = InterceptorsSystemException.get( orb,
02bb8761fcce Initial load
duke
parents:
diff changeset
   212
            CORBALogDomains.RPC_PROTOCOL ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   213
        orbutilWrapper = ORBUtilSystemException.get( orb,
02bb8761fcce Initial load
duke
parents:
diff changeset
   214
            CORBALogDomains.RPC_PROTOCOL ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   215
        omgWrapper = OMGSystemException.get( orb,
02bb8761fcce Initial load
duke
parents:
diff changeset
   216
            CORBALogDomains.RPC_PROTOCOL ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   217
        arguments = args ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   218
02bb8761fcce Initial load
duke
parents:
diff changeset
   219
        // Create codec factory:
02bb8761fcce Initial load
duke
parents:
diff changeset
   220
        codecFactory = new CodecFactoryImpl( orb );
02bb8761fcce Initial load
duke
parents:
diff changeset
   221
02bb8761fcce Initial load
duke
parents:
diff changeset
   222
        // Create new interceptor list:
02bb8761fcce Initial load
duke
parents:
diff changeset
   223
        interceptorList = new InterceptorList( wrapper );
02bb8761fcce Initial load
duke
parents:
diff changeset
   224
02bb8761fcce Initial load
duke
parents:
diff changeset
   225
        // Create a new PICurrent.
02bb8761fcce Initial load
duke
parents:
diff changeset
   226
        current = new PICurrent( orb );
02bb8761fcce Initial load
duke
parents:
diff changeset
   227
02bb8761fcce Initial load
duke
parents:
diff changeset
   228
        // Create new interceptor invoker, initially disabled:
02bb8761fcce Initial load
duke
parents:
diff changeset
   229
        interceptorInvoker = new InterceptorInvoker( orb, interceptorList,
02bb8761fcce Initial load
duke
parents:
diff changeset
   230
                                                     current );
02bb8761fcce Initial load
duke
parents:
diff changeset
   231
02bb8761fcce Initial load
duke
parents:
diff changeset
   232
        // Register the PI current and Codec factory objects
02bb8761fcce Initial load
duke
parents:
diff changeset
   233
        orb.getLocalResolver().register( ORBConstants.PI_CURRENT_NAME,
02bb8761fcce Initial load
duke
parents:
diff changeset
   234
            ClosureFactory.makeConstant( current ) ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   235
        orb.getLocalResolver().register( ORBConstants.CODEC_FACTORY_NAME,
02bb8761fcce Initial load
duke
parents:
diff changeset
   236
            ClosureFactory.makeConstant( codecFactory ) ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   237
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   238
02bb8761fcce Initial load
duke
parents:
diff changeset
   239
    public void initialize() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   240
        // If we have any orb initializers, make use of them:
02bb8761fcce Initial load
duke
parents:
diff changeset
   241
        if( orb.getORBData().getORBInitializers() != null ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   242
            // Create the ORBInitInfo object to pass to ORB intializers:
02bb8761fcce Initial load
duke
parents:
diff changeset
   243
            ORBInitInfoImpl orbInitInfo = createORBInitInfo();
02bb8761fcce Initial load
duke
parents:
diff changeset
   244
02bb8761fcce Initial load
duke
parents:
diff changeset
   245
            // Make sure get_slot and set_slot are not called from within
02bb8761fcce Initial load
duke
parents:
diff changeset
   246
            // ORB initializers:
02bb8761fcce Initial load
duke
parents:
diff changeset
   247
            current.setORBInitializing( true );
02bb8761fcce Initial load
duke
parents:
diff changeset
   248
02bb8761fcce Initial load
duke
parents:
diff changeset
   249
            // Call pre_init on all ORB initializers:
02bb8761fcce Initial load
duke
parents:
diff changeset
   250
            preInitORBInitializers( orbInitInfo );
02bb8761fcce Initial load
duke
parents:
diff changeset
   251
02bb8761fcce Initial load
duke
parents:
diff changeset
   252
            // Call post_init on all ORB initializers:
02bb8761fcce Initial load
duke
parents:
diff changeset
   253
            postInitORBInitializers( orbInitInfo );
02bb8761fcce Initial load
duke
parents:
diff changeset
   254
02bb8761fcce Initial load
duke
parents:
diff changeset
   255
            // Proprietary: sort interceptors:
02bb8761fcce Initial load
duke
parents:
diff changeset
   256
            interceptorList.sortInterceptors();
02bb8761fcce Initial load
duke
parents:
diff changeset
   257
02bb8761fcce Initial load
duke
parents:
diff changeset
   258
            // Re-enable get_slot and set_slot to be called from within
02bb8761fcce Initial load
duke
parents:
diff changeset
   259
            // ORB initializers:
02bb8761fcce Initial load
duke
parents:
diff changeset
   260
            current.setORBInitializing( false );
02bb8761fcce Initial load
duke
parents:
diff changeset
   261
02bb8761fcce Initial load
duke
parents:
diff changeset
   262
            // Ensure nobody makes any more calls on this object.
02bb8761fcce Initial load
duke
parents:
diff changeset
   263
            orbInitInfo.setStage( ORBInitInfoImpl.STAGE_CLOSED );
02bb8761fcce Initial load
duke
parents:
diff changeset
   264
02bb8761fcce Initial load
duke
parents:
diff changeset
   265
            // Set cached flags indicating whether we have interceptors
02bb8761fcce Initial load
duke
parents:
diff changeset
   266
            // registered of a given type.
02bb8761fcce Initial load
duke
parents:
diff changeset
   267
            hasIORInterceptors = interceptorList.hasInterceptorsOfType(
02bb8761fcce Initial load
duke
parents:
diff changeset
   268
                InterceptorList.INTERCEPTOR_TYPE_IOR );
02bb8761fcce Initial load
duke
parents:
diff changeset
   269
            // XXX This must always be true, so that using the new generic
02bb8761fcce Initial load
duke
parents:
diff changeset
   270
            // RPC framework can pass info between the PI stack and the
02bb8761fcce Initial load
duke
parents:
diff changeset
   271
            // framework invocation stack.  Temporary until Harold fixes
02bb8761fcce Initial load
duke
parents:
diff changeset
   272
            // this.  Note that this must never be true until after the
02bb8761fcce Initial load
duke
parents:
diff changeset
   273
            // ORBInitializer instances complete executing.
02bb8761fcce Initial load
duke
parents:
diff changeset
   274
            //hasClientInterceptors = interceptorList.hasInterceptorsOfType(
02bb8761fcce Initial load
duke
parents:
diff changeset
   275
                //InterceptorList.INTERCEPTOR_TYPE_CLIENT );
02bb8761fcce Initial load
duke
parents:
diff changeset
   276
            hasClientInterceptors = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   277
            hasServerInterceptors = interceptorList.hasInterceptorsOfType(
02bb8761fcce Initial load
duke
parents:
diff changeset
   278
                InterceptorList.INTERCEPTOR_TYPE_SERVER );
02bb8761fcce Initial load
duke
parents:
diff changeset
   279
02bb8761fcce Initial load
duke
parents:
diff changeset
   280
            // Enable interceptor invoker (not necessary if no interceptors
02bb8761fcce Initial load
duke
parents:
diff changeset
   281
            // are registered).  This should be the last stage of ORB
02bb8761fcce Initial load
duke
parents:
diff changeset
   282
            // initialization.
02bb8761fcce Initial load
duke
parents:
diff changeset
   283
            interceptorInvoker.setEnabled( true );
02bb8761fcce Initial load
duke
parents:
diff changeset
   284
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   285
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   286
02bb8761fcce Initial load
duke
parents:
diff changeset
   287
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   288
     *  ptc/00-08-06 p 205: "When an application calls ORB::destroy, the ORB
02bb8761fcce Initial load
duke
parents:
diff changeset
   289
     *  1) waits for all requests in progress to complete
02bb8761fcce Initial load
duke
parents:
diff changeset
   290
     *  2) calls the Interceptor::destroy operation for each interceptor
02bb8761fcce Initial load
duke
parents:
diff changeset
   291
     *  3) completes destruction of the ORB"
02bb8761fcce Initial load
duke
parents:
diff changeset
   292
     *
02bb8761fcce Initial load
duke
parents:
diff changeset
   293
     * This must be called at the end of ORB.destroy.  Note that this is not
02bb8761fcce Initial load
duke
parents:
diff changeset
   294
     * part of the PIHandler interface, since ORBImpl implements the ORB interface.
02bb8761fcce Initial load
duke
parents:
diff changeset
   295
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   296
    public void destroyInterceptors() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   297
        interceptorList.destroyAll();
02bb8761fcce Initial load
duke
parents:
diff changeset
   298
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   299
02bb8761fcce Initial load
duke
parents:
diff changeset
   300
    public void objectAdapterCreated( ObjectAdapter oa )
02bb8761fcce Initial load
duke
parents:
diff changeset
   301
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   302
        if (!hasIORInterceptors)
02bb8761fcce Initial load
duke
parents:
diff changeset
   303
            return ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   304
02bb8761fcce Initial load
duke
parents:
diff changeset
   305
        interceptorInvoker.objectAdapterCreated( oa ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   306
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   307
02bb8761fcce Initial load
duke
parents:
diff changeset
   308
    public void adapterManagerStateChanged( int managerId,
02bb8761fcce Initial load
duke
parents:
diff changeset
   309
        short newState )
02bb8761fcce Initial load
duke
parents:
diff changeset
   310
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   311
        if (!hasIORInterceptors)
02bb8761fcce Initial load
duke
parents:
diff changeset
   312
            return ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   313
02bb8761fcce Initial load
duke
parents:
diff changeset
   314
        interceptorInvoker.adapterManagerStateChanged( managerId, newState ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   315
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   316
02bb8761fcce Initial load
duke
parents:
diff changeset
   317
    public void adapterStateChanged( ObjectReferenceTemplate[]
02bb8761fcce Initial load
duke
parents:
diff changeset
   318
        templates, short newState )
02bb8761fcce Initial load
duke
parents:
diff changeset
   319
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   320
        if (!hasIORInterceptors)
02bb8761fcce Initial load
duke
parents:
diff changeset
   321
            return ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   322
02bb8761fcce Initial load
duke
parents:
diff changeset
   323
        interceptorInvoker.adapterStateChanged( templates, newState ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   324
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   325
02bb8761fcce Initial load
duke
parents:
diff changeset
   326
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
   327
     *****************
02bb8761fcce Initial load
duke
parents:
diff changeset
   328
     * Client PI hooks
02bb8761fcce Initial load
duke
parents:
diff changeset
   329
     *****************/
02bb8761fcce Initial load
duke
parents:
diff changeset
   330
02bb8761fcce Initial load
duke
parents:
diff changeset
   331
    public void disableInterceptorsThisThread() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   332
        if( !hasClientInterceptors ) return;
02bb8761fcce Initial load
duke
parents:
diff changeset
   333
02bb8761fcce Initial load
duke
parents:
diff changeset
   334
        RequestInfoStack infoStack =
02bb8761fcce Initial load
duke
parents:
diff changeset
   335
            (RequestInfoStack)threadLocalClientRequestInfoStack.get();
02bb8761fcce Initial load
duke
parents:
diff changeset
   336
        infoStack.disableCount++;
02bb8761fcce Initial load
duke
parents:
diff changeset
   337
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   338
02bb8761fcce Initial load
duke
parents:
diff changeset
   339
    public void enableInterceptorsThisThread() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   340
        if( !hasClientInterceptors ) return;
02bb8761fcce Initial load
duke
parents:
diff changeset
   341
02bb8761fcce Initial load
duke
parents:
diff changeset
   342
        RequestInfoStack infoStack =
02bb8761fcce Initial load
duke
parents:
diff changeset
   343
            (RequestInfoStack)threadLocalClientRequestInfoStack.get();
02bb8761fcce Initial load
duke
parents:
diff changeset
   344
        infoStack.disableCount--;
02bb8761fcce Initial load
duke
parents:
diff changeset
   345
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   346
02bb8761fcce Initial load
duke
parents:
diff changeset
   347
    public void invokeClientPIStartingPoint()
02bb8761fcce Initial load
duke
parents:
diff changeset
   348
        throws RemarshalException
02bb8761fcce Initial load
duke
parents:
diff changeset
   349
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   350
        if( !hasClientInterceptors ) return;
02bb8761fcce Initial load
duke
parents:
diff changeset
   351
        if( !isClientPIEnabledForThisThread() ) return;
02bb8761fcce Initial load
duke
parents:
diff changeset
   352
02bb8761fcce Initial load
duke
parents:
diff changeset
   353
        // Invoke the starting interception points and record exception
02bb8761fcce Initial load
duke
parents:
diff changeset
   354
        // and reply status info in the info object:
02bb8761fcce Initial load
duke
parents:
diff changeset
   355
        ClientRequestInfoImpl info = peekClientRequestInfoImplStack();
02bb8761fcce Initial load
duke
parents:
diff changeset
   356
        interceptorInvoker.invokeClientInterceptorStartingPoint( info );
02bb8761fcce Initial load
duke
parents:
diff changeset
   357
02bb8761fcce Initial load
duke
parents:
diff changeset
   358
        // Check reply status.  If we will not have another chance later
02bb8761fcce Initial load
duke
parents:
diff changeset
   359
        // to invoke the client ending points, do it now.
02bb8761fcce Initial load
duke
parents:
diff changeset
   360
        short replyStatus = info.getReplyStatus();
02bb8761fcce Initial load
duke
parents:
diff changeset
   361
        if( (replyStatus == SYSTEM_EXCEPTION.value) ||
02bb8761fcce Initial load
duke
parents:
diff changeset
   362
            (replyStatus == LOCATION_FORWARD.value) )
02bb8761fcce Initial load
duke
parents:
diff changeset
   363
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
   364
            // Note: Transport retry cannot happen here since this happens
02bb8761fcce Initial load
duke
parents:
diff changeset
   365
            // before the request hits the wire.
02bb8761fcce Initial load
duke
parents:
diff changeset
   366
02bb8761fcce Initial load
duke
parents:
diff changeset
   367
            Exception exception = invokeClientPIEndingPoint(
02bb8761fcce Initial load
duke
parents:
diff changeset
   368
                convertPIReplyStatusToReplyMessage( replyStatus ),
02bb8761fcce Initial load
duke
parents:
diff changeset
   369
                info.getException() );
02bb8761fcce Initial load
duke
parents:
diff changeset
   370
            if( exception == null ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   371
                // Do not throw anything.  Otherwise, it must be a
02bb8761fcce Initial load
duke
parents:
diff changeset
   372
                // SystemException, UserException or RemarshalException.
02bb8761fcce Initial load
duke
parents:
diff changeset
   373
            } if( exception instanceof SystemException ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   374
                throw (SystemException)exception;
02bb8761fcce Initial load
duke
parents:
diff changeset
   375
            } else if( exception instanceof RemarshalException ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   376
                throw (RemarshalException)exception;
02bb8761fcce Initial load
duke
parents:
diff changeset
   377
            } else if( (exception instanceof UserException) ||
02bb8761fcce Initial load
duke
parents:
diff changeset
   378
                     (exception instanceof ApplicationException) ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   379
                // It should not be possible for an interceptor to throw
02bb8761fcce Initial load
duke
parents:
diff changeset
   380
                // a UserException.  By asserting instead of throwing the
02bb8761fcce Initial load
duke
parents:
diff changeset
   381
                // UserException, we need not declare anything but
02bb8761fcce Initial load
duke
parents:
diff changeset
   382
                // RemarshalException in the throws clause.
02bb8761fcce Initial load
duke
parents:
diff changeset
   383
                throw wrapper.exceptionInvalid() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   384
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   385
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   386
        else if( replyStatus != ClientRequestInfoImpl.UNINITIALIZED ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   387
            throw wrapper.replyStatusNotInit() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   388
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   389
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   390
7197
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   391
    // Needed when an error forces a retry AFTER initiateClientPIRequest
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   392
    // but BEFORE invokeClientPIStartingPoint.
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   393
    public Exception makeCompletedClientRequest( int replyStatus,
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   394
        Exception exception ) {
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   395
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   396
        // 6763340
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   397
        return handleClientPIEndingPoint( replyStatus, exception, false ) ;
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   398
    }
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   399
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   400
    public Exception invokeClientPIEndingPoint( int replyStatus,
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   401
        Exception exception ) {
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   402
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   403
        // 6763340
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   404
        return handleClientPIEndingPoint( replyStatus, exception, true ) ;
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   405
    }
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   406
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   407
    public Exception handleClientPIEndingPoint(
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   408
        int replyStatus, Exception exception, boolean invokeEndingPoint ) {
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   409
        if( !hasClientInterceptors ) return exception;
02bb8761fcce Initial load
duke
parents:
diff changeset
   410
        if( !isClientPIEnabledForThisThread() ) return exception;
02bb8761fcce Initial load
duke
parents:
diff changeset
   411
02bb8761fcce Initial load
duke
parents:
diff changeset
   412
        // Translate ReplyMessage.replyStatus into PI replyStatus:
02bb8761fcce Initial load
duke
parents:
diff changeset
   413
        // Note: this is also an assertion to make sure a valid replyStatus
02bb8761fcce Initial load
duke
parents:
diff changeset
   414
        // is passed in (IndexOutOfBoundsException will be thrown otherwise)
02bb8761fcce Initial load
duke
parents:
diff changeset
   415
        short piReplyStatus = REPLY_MESSAGE_TO_PI_REPLY_STATUS[replyStatus];
02bb8761fcce Initial load
duke
parents:
diff changeset
   416
02bb8761fcce Initial load
duke
parents:
diff changeset
   417
        // Invoke the ending interception points and record exception
02bb8761fcce Initial load
duke
parents:
diff changeset
   418
        // and reply status info in the info object:
02bb8761fcce Initial load
duke
parents:
diff changeset
   419
        ClientRequestInfoImpl info = peekClientRequestInfoImplStack();
02bb8761fcce Initial load
duke
parents:
diff changeset
   420
        info.setReplyStatus( piReplyStatus );
02bb8761fcce Initial load
duke
parents:
diff changeset
   421
        info.setException( exception );
7197
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   422
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   423
        if (invokeEndingPoint) {
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   424
            // 6763340
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   425
            interceptorInvoker.invokeClientInterceptorEndingPoint( info );
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   426
            piReplyStatus = info.getReplyStatus();
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   427
        }
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   428
02bb8761fcce Initial load
duke
parents:
diff changeset
   429
        // Check reply status:
02bb8761fcce Initial load
duke
parents:
diff changeset
   430
        if( (piReplyStatus == LOCATION_FORWARD.value) ||
7197
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   431
            (piReplyStatus == TRANSPORT_RETRY.value) ) {
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   432
            // If this is a forward or a retry, reset and reuse
02bb8761fcce Initial load
duke
parents:
diff changeset
   433
            // info object:
02bb8761fcce Initial load
duke
parents:
diff changeset
   434
            info.reset();
7197
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   435
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   436
            // fix for 6763340:
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   437
            if (invokeEndingPoint) {
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   438
                info.setRetryRequest( RetryType.AFTER_RESPONSE ) ;
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   439
            } else {
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   440
                info.setRetryRequest( RetryType.BEFORE_RESPONSE ) ;
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   441
            }
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   442
02bb8761fcce Initial load
duke
parents:
diff changeset
   443
            // ... and return a RemarshalException so the orb internals know
02bb8761fcce Initial load
duke
parents:
diff changeset
   444
            exception = new RemarshalException();
7197
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   445
        } else if( (piReplyStatus == SYSTEM_EXCEPTION.value) ||
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   446
                 (piReplyStatus == USER_EXCEPTION.value) ) {
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   447
            exception = info.getException();
02bb8761fcce Initial load
duke
parents:
diff changeset
   448
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   449
02bb8761fcce Initial load
duke
parents:
diff changeset
   450
        return exception;
02bb8761fcce Initial load
duke
parents:
diff changeset
   451
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   452
02bb8761fcce Initial load
duke
parents:
diff changeset
   453
    public void initiateClientPIRequest( boolean diiRequest ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   454
        if( !hasClientInterceptors ) return;
02bb8761fcce Initial load
duke
parents:
diff changeset
   455
        if( !isClientPIEnabledForThisThread() ) return;
02bb8761fcce Initial load
duke
parents:
diff changeset
   456
02bb8761fcce Initial load
duke
parents:
diff changeset
   457
        // Get the most recent info object from the thread local
02bb8761fcce Initial load
duke
parents:
diff changeset
   458
        // ClientRequestInfoImpl stack:
02bb8761fcce Initial load
duke
parents:
diff changeset
   459
        RequestInfoStack infoStack =
02bb8761fcce Initial load
duke
parents:
diff changeset
   460
            (RequestInfoStack)threadLocalClientRequestInfoStack.get();
02bb8761fcce Initial load
duke
parents:
diff changeset
   461
        ClientRequestInfoImpl info = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   462
7197
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   463
        if (!infoStack.empty() ) {
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   464
            info = (ClientRequestInfoImpl)infoStack.peek();
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   465
        }
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   466
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   467
        if (!diiRequest && (info != null) && info.isDIIInitiate() ) {
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   468
            // In RequestImpl.doInvocation we already called
02bb8761fcce Initial load
duke
parents:
diff changeset
   469
            // initiateClientPIRequest( true ), so ignore this initiate.
02bb8761fcce Initial load
duke
parents:
diff changeset
   470
            info.setDIIInitiate( false );
7197
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   471
        } else {
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   472
            // If there is no info object or if we are not retrying a request,
02bb8761fcce Initial load
duke
parents:
diff changeset
   473
            // push a new ClientRequestInfoImpl on the stack:
7197
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   474
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   475
            // 6763340: don't push unless this is not a retry
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   476
            if( (info == null) || !info.getRetryRequest().isRetry() ) {
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   477
                info = new ClientRequestInfoImpl( orb );
02bb8761fcce Initial load
duke
parents:
diff changeset
   478
                infoStack.push( info );
02bb8761fcce Initial load
duke
parents:
diff changeset
   479
                printPush();
02bb8761fcce Initial load
duke
parents:
diff changeset
   480
                // Note: the entry count is automatically initialized to 0.
02bb8761fcce Initial load
duke
parents:
diff changeset
   481
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   482
02bb8761fcce Initial load
duke
parents:
diff changeset
   483
            // Reset the retry request flag so that recursive calls will
02bb8761fcce Initial load
duke
parents:
diff changeset
   484
            // push a new info object, and bump up entry count so we know
02bb8761fcce Initial load
duke
parents:
diff changeset
   485
            // when to pop this info object:
7197
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   486
            info.setRetryRequest( RetryType.NONE );
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   487
            info.incrementEntryCount();
02bb8761fcce Initial load
duke
parents:
diff changeset
   488
7197
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   489
            // KMC 6763340: I don't know why this wasn't set earlier,
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   490
            // but we do not want a retry to pick up the previous
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   491
            // reply status, so clear it here.  Most likely a new
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   492
            // info was pushed before, so that this was not a problem.
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   493
            info.setReplyStatus( RequestInfoImpl.UNINITIALIZED ) ;
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   494
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   495
            // If this is a DII request, make sure we ignore the next initiate.
02bb8761fcce Initial load
duke
parents:
diff changeset
   496
            if( diiRequest ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   497
                info.setDIIInitiate( true );
02bb8761fcce Initial load
duke
parents:
diff changeset
   498
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   499
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   500
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   501
02bb8761fcce Initial load
duke
parents:
diff changeset
   502
    public void cleanupClientPIRequest() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   503
        if( !hasClientInterceptors ) return;
02bb8761fcce Initial load
duke
parents:
diff changeset
   504
        if( !isClientPIEnabledForThisThread() ) return;
02bb8761fcce Initial load
duke
parents:
diff changeset
   505
02bb8761fcce Initial load
duke
parents:
diff changeset
   506
        ClientRequestInfoImpl info = peekClientRequestInfoImplStack();
7197
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   507
        RetryType rt = info.getRetryRequest() ;
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   508
7197
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   509
        // fix for 6763340
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   510
        if (!rt.equals( RetryType.BEFORE_RESPONSE )) {
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   511
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   512
            // If the replyStatus has not yet been set, this is an indication
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   513
            // that the ORB threw an exception before we had a chance to
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   514
            // invoke the client interceptor ending points.
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   515
            //
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   516
            // _REVISIT_ We cannot handle any exceptions or ForwardRequests
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   517
            // flagged by the ending points here because there is no way
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   518
            // to gracefully handle this in any of the calling code.
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   519
            // This is a rare corner case, so we will ignore this for now.
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   520
            short replyStatus = info.getReplyStatus();
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   521
            if (replyStatus == info.UNINITIALIZED ) {
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   522
                invokeClientPIEndingPoint( ReplyMessage.SYSTEM_EXCEPTION,
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   523
                    wrapper.unknownRequestInvoke(
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   524
                        CompletionStatus.COMPLETED_MAYBE ) ) ;
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   525
            }
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   526
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   527
02bb8761fcce Initial load
duke
parents:
diff changeset
   528
        // Decrement entry count, and if it is zero, pop it from the stack.
02bb8761fcce Initial load
duke
parents:
diff changeset
   529
        info.decrementEntryCount();
7197
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   530
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   531
        // fix for 6763340, and probably other cases (non-recursive retry)
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   532
        if (info.getEntryCount() == 0 && !info.getRetryRequest().isRetry()) {
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   533
            // RequestInfoStack<ClientRequestInfoImpl> infoStack =
a3c4c326e934 6763340: memory leak in com.sun.corba.se.* classes
robm
parents: 5555
diff changeset
   534
            //     threadLocalClientRequestInfoStack.get();
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   535
            RequestInfoStack infoStack =
02bb8761fcce Initial load
duke
parents:
diff changeset
   536
                (RequestInfoStack)threadLocalClientRequestInfoStack.get();
02bb8761fcce Initial load
duke
parents:
diff changeset
   537
            infoStack.pop();
02bb8761fcce Initial load
duke
parents:
diff changeset
   538
            printPop();
02bb8761fcce Initial load
duke
parents:
diff changeset
   539
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   540
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   541
02bb8761fcce Initial load
duke
parents:
diff changeset
   542
    public void setClientPIInfo(CorbaMessageMediator messageMediator)
02bb8761fcce Initial load
duke
parents:
diff changeset
   543
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   544
        if( !hasClientInterceptors ) return;
02bb8761fcce Initial load
duke
parents:
diff changeset
   545
        if( !isClientPIEnabledForThisThread() ) return;
02bb8761fcce Initial load
duke
parents:
diff changeset
   546
02bb8761fcce Initial load
duke
parents:
diff changeset
   547
        peekClientRequestInfoImplStack().setInfo(messageMediator);
02bb8761fcce Initial load
duke
parents:
diff changeset
   548
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   549
02bb8761fcce Initial load
duke
parents:
diff changeset
   550
    public void setClientPIInfo( RequestImpl requestImpl ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   551
        if( !hasClientInterceptors ) return;
02bb8761fcce Initial load
duke
parents:
diff changeset
   552
        if( !isClientPIEnabledForThisThread() ) return;
02bb8761fcce Initial load
duke
parents:
diff changeset
   553
02bb8761fcce Initial load
duke
parents:
diff changeset
   554
        peekClientRequestInfoImplStack().setDIIRequest( requestImpl );
02bb8761fcce Initial load
duke
parents:
diff changeset
   555
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   556
02bb8761fcce Initial load
duke
parents:
diff changeset
   557
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
   558
     *****************
02bb8761fcce Initial load
duke
parents:
diff changeset
   559
     * Server PI hooks
02bb8761fcce Initial load
duke
parents:
diff changeset
   560
     *****************/
02bb8761fcce Initial load
duke
parents:
diff changeset
   561
02bb8761fcce Initial load
duke
parents:
diff changeset
   562
    public void invokeServerPIStartingPoint()
02bb8761fcce Initial load
duke
parents:
diff changeset
   563
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   564
        if( !hasServerInterceptors ) return;
02bb8761fcce Initial load
duke
parents:
diff changeset
   565
02bb8761fcce Initial load
duke
parents:
diff changeset
   566
        ServerRequestInfoImpl info = peekServerRequestInfoImplStack();
02bb8761fcce Initial load
duke
parents:
diff changeset
   567
        interceptorInvoker.invokeServerInterceptorStartingPoint( info );
02bb8761fcce Initial load
duke
parents:
diff changeset
   568
02bb8761fcce Initial load
duke
parents:
diff changeset
   569
        // Handle SystemException or ForwardRequest:
02bb8761fcce Initial load
duke
parents:
diff changeset
   570
        serverPIHandleExceptions( info );
02bb8761fcce Initial load
duke
parents:
diff changeset
   571
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   572
02bb8761fcce Initial load
duke
parents:
diff changeset
   573
    public void invokeServerPIIntermediatePoint()
02bb8761fcce Initial load
duke
parents:
diff changeset
   574
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   575
        if( !hasServerInterceptors ) return;
02bb8761fcce Initial load
duke
parents:
diff changeset
   576
02bb8761fcce Initial load
duke
parents:
diff changeset
   577
        ServerRequestInfoImpl info = peekServerRequestInfoImplStack();
02bb8761fcce Initial load
duke
parents:
diff changeset
   578
        interceptorInvoker.invokeServerInterceptorIntermediatePoint( info );
02bb8761fcce Initial load
duke
parents:
diff changeset
   579
02bb8761fcce Initial load
duke
parents:
diff changeset
   580
        // Clear servant from info object so that the user has control over
02bb8761fcce Initial load
duke
parents:
diff changeset
   581
        // its lifetime:
02bb8761fcce Initial load
duke
parents:
diff changeset
   582
        info.releaseServant();
02bb8761fcce Initial load
duke
parents:
diff changeset
   583
02bb8761fcce Initial load
duke
parents:
diff changeset
   584
        // Handle SystemException or ForwardRequest:
02bb8761fcce Initial load
duke
parents:
diff changeset
   585
        serverPIHandleExceptions( info );
02bb8761fcce Initial load
duke
parents:
diff changeset
   586
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   587
02bb8761fcce Initial load
duke
parents:
diff changeset
   588
    public void invokeServerPIEndingPoint( ReplyMessage replyMessage )
02bb8761fcce Initial load
duke
parents:
diff changeset
   589
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   590
        if( !hasServerInterceptors ) return;
02bb8761fcce Initial load
duke
parents:
diff changeset
   591
        ServerRequestInfoImpl info = peekServerRequestInfoImplStack();
02bb8761fcce Initial load
duke
parents:
diff changeset
   592
02bb8761fcce Initial load
duke
parents:
diff changeset
   593
        // REVISIT: This needs to be done "early" for the following workaround.
02bb8761fcce Initial load
duke
parents:
diff changeset
   594
        info.setReplyMessage( replyMessage );
02bb8761fcce Initial load
duke
parents:
diff changeset
   595
02bb8761fcce Initial load
duke
parents:
diff changeset
   596
        // REVISIT: This was done inside of invokeServerInterceptorEndingPoint
02bb8761fcce Initial load
duke
parents:
diff changeset
   597
        // but needs to be here for now.  See comment in that method for why.
02bb8761fcce Initial load
duke
parents:
diff changeset
   598
        info.setCurrentExecutionPoint( info.EXECUTION_POINT_ENDING );
02bb8761fcce Initial load
duke
parents:
diff changeset
   599
02bb8761fcce Initial load
duke
parents:
diff changeset
   600
        // It is possible we might have entered this method more than
02bb8761fcce Initial load
duke
parents:
diff changeset
   601
        // once (e.g. if an ending point threw a SystemException, then
02bb8761fcce Initial load
duke
parents:
diff changeset
   602
        // a new ServerResponseImpl is created).
02bb8761fcce Initial load
duke
parents:
diff changeset
   603
        if( !info.getAlreadyExecuted() ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   604
            int replyStatus = replyMessage.getReplyStatus();
02bb8761fcce Initial load
duke
parents:
diff changeset
   605
02bb8761fcce Initial load
duke
parents:
diff changeset
   606
            // Translate ReplyMessage.replyStatus into PI replyStatus:
02bb8761fcce Initial load
duke
parents:
diff changeset
   607
            // Note: this is also an assertion to make sure a valid
02bb8761fcce Initial load
duke
parents:
diff changeset
   608
            // replyStatus is passed in (IndexOutOfBoundsException will be
02bb8761fcce Initial load
duke
parents:
diff changeset
   609
            // thrown otherwise)
02bb8761fcce Initial load
duke
parents:
diff changeset
   610
            short piReplyStatus =
02bb8761fcce Initial load
duke
parents:
diff changeset
   611
                REPLY_MESSAGE_TO_PI_REPLY_STATUS[replyStatus];
02bb8761fcce Initial load
duke
parents:
diff changeset
   612
02bb8761fcce Initial load
duke
parents:
diff changeset
   613
            // Make forwarded IOR available to interceptors, if applicable:
02bb8761fcce Initial load
duke
parents:
diff changeset
   614
            if( ( piReplyStatus == LOCATION_FORWARD.value ) ||
02bb8761fcce Initial load
duke
parents:
diff changeset
   615
                ( piReplyStatus == TRANSPORT_RETRY.value ) )
02bb8761fcce Initial load
duke
parents:
diff changeset
   616
            {
02bb8761fcce Initial load
duke
parents:
diff changeset
   617
                info.setForwardRequest( replyMessage.getIOR() );
02bb8761fcce Initial load
duke
parents:
diff changeset
   618
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   619
02bb8761fcce Initial load
duke
parents:
diff changeset
   620
            // REVISIT: Do early above for now.
02bb8761fcce Initial load
duke
parents:
diff changeset
   621
            // Make reply message available to interceptors:
02bb8761fcce Initial load
duke
parents:
diff changeset
   622
            //info.setReplyMessage( replyMessage );
02bb8761fcce Initial load
duke
parents:
diff changeset
   623
02bb8761fcce Initial load
duke
parents:
diff changeset
   624
            // Remember exception so we can tell if an interceptor changed it.
02bb8761fcce Initial load
duke
parents:
diff changeset
   625
            Exception prevException = info.getException();
02bb8761fcce Initial load
duke
parents:
diff changeset
   626
02bb8761fcce Initial load
duke
parents:
diff changeset
   627
            // _REVISIT_ We do not have access to the User Exception at
02bb8761fcce Initial load
duke
parents:
diff changeset
   628
            // this point, so treat it as an UNKNOWN for now.
02bb8761fcce Initial load
duke
parents:
diff changeset
   629
            // Note that if this is a DSI call, we do have the user exception.
02bb8761fcce Initial load
duke
parents:
diff changeset
   630
            if( !info.isDynamic() &&
02bb8761fcce Initial load
duke
parents:
diff changeset
   631
                (piReplyStatus == USER_EXCEPTION.value) )
02bb8761fcce Initial load
duke
parents:
diff changeset
   632
            {
02bb8761fcce Initial load
duke
parents:
diff changeset
   633
                info.setException( omgWrapper.unknownUserException(
02bb8761fcce Initial load
duke
parents:
diff changeset
   634
                    CompletionStatus.COMPLETED_MAYBE ) ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   635
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   636
02bb8761fcce Initial load
duke
parents:
diff changeset
   637
            // Invoke the ending interception points:
02bb8761fcce Initial load
duke
parents:
diff changeset
   638
            info.setReplyStatus( piReplyStatus );
02bb8761fcce Initial load
duke
parents:
diff changeset
   639
            interceptorInvoker.invokeServerInterceptorEndingPoint( info );
02bb8761fcce Initial load
duke
parents:
diff changeset
   640
            short newPIReplyStatus = info.getReplyStatus();
02bb8761fcce Initial load
duke
parents:
diff changeset
   641
            Exception newException = info.getException();
02bb8761fcce Initial load
duke
parents:
diff changeset
   642
02bb8761fcce Initial load
duke
parents:
diff changeset
   643
            // Check reply status.  If an interceptor threw a SystemException
02bb8761fcce Initial load
duke
parents:
diff changeset
   644
            // and it is different than the one that we came in with,
02bb8761fcce Initial load
duke
parents:
diff changeset
   645
            // rethrow it so the proper response can be constructed:
02bb8761fcce Initial load
duke
parents:
diff changeset
   646
            if( ( newPIReplyStatus == SYSTEM_EXCEPTION.value ) &&
02bb8761fcce Initial load
duke
parents:
diff changeset
   647
                ( newException != prevException ) )
02bb8761fcce Initial load
duke
parents:
diff changeset
   648
            {
02bb8761fcce Initial load
duke
parents:
diff changeset
   649
                throw (SystemException)newException;
02bb8761fcce Initial load
duke
parents:
diff changeset
   650
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   651
02bb8761fcce Initial load
duke
parents:
diff changeset
   652
            // If we are to forward the location:
02bb8761fcce Initial load
duke
parents:
diff changeset
   653
            if( newPIReplyStatus == LOCATION_FORWARD.value ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   654
                if( piReplyStatus != LOCATION_FORWARD.value ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   655
                    // Treat a ForwardRequest as a ForwardException.
02bb8761fcce Initial load
duke
parents:
diff changeset
   656
                    IOR ior = info.getForwardRequestIOR();
02bb8761fcce Initial load
duke
parents:
diff changeset
   657
                    throw new ForwardException( orb, ior ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   658
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   659
                else if( info.isForwardRequestRaisedInEnding() ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   660
                    // Treat a ForwardRequest by changing the IOR.
02bb8761fcce Initial load
duke
parents:
diff changeset
   661
                    replyMessage.setIOR( info.getForwardRequestIOR() );
02bb8761fcce Initial load
duke
parents:
diff changeset
   662
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   663
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   664
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   665
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   666
02bb8761fcce Initial load
duke
parents:
diff changeset
   667
    public void setServerPIInfo( Exception exception ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   668
        if( !hasServerInterceptors ) return;
02bb8761fcce Initial load
duke
parents:
diff changeset
   669
02bb8761fcce Initial load
duke
parents:
diff changeset
   670
        ServerRequestInfoImpl info = peekServerRequestInfoImplStack();
02bb8761fcce Initial load
duke
parents:
diff changeset
   671
        info.setException( exception );
02bb8761fcce Initial load
duke
parents:
diff changeset
   672
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   673
02bb8761fcce Initial load
duke
parents:
diff changeset
   674
    public void setServerPIInfo( NVList arguments )
02bb8761fcce Initial load
duke
parents:
diff changeset
   675
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   676
        if( !hasServerInterceptors ) return;
02bb8761fcce Initial load
duke
parents:
diff changeset
   677
02bb8761fcce Initial load
duke
parents:
diff changeset
   678
        ServerRequestInfoImpl info = peekServerRequestInfoImplStack();
02bb8761fcce Initial load
duke
parents:
diff changeset
   679
        info.setDSIArguments( arguments );
02bb8761fcce Initial load
duke
parents:
diff changeset
   680
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   681
02bb8761fcce Initial load
duke
parents:
diff changeset
   682
    public void setServerPIExceptionInfo( Any exception )
02bb8761fcce Initial load
duke
parents:
diff changeset
   683
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   684
        if( !hasServerInterceptors ) return;
02bb8761fcce Initial load
duke
parents:
diff changeset
   685
02bb8761fcce Initial load
duke
parents:
diff changeset
   686
        ServerRequestInfoImpl info = peekServerRequestInfoImplStack();
02bb8761fcce Initial load
duke
parents:
diff changeset
   687
        info.setDSIException( exception );
02bb8761fcce Initial load
duke
parents:
diff changeset
   688
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   689
02bb8761fcce Initial load
duke
parents:
diff changeset
   690
    public void setServerPIInfo( Any result )
02bb8761fcce Initial load
duke
parents:
diff changeset
   691
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   692
        if( !hasServerInterceptors ) return;
02bb8761fcce Initial load
duke
parents:
diff changeset
   693
02bb8761fcce Initial load
duke
parents:
diff changeset
   694
        ServerRequestInfoImpl info = peekServerRequestInfoImplStack();
02bb8761fcce Initial load
duke
parents:
diff changeset
   695
        info.setDSIResult( result );
02bb8761fcce Initial load
duke
parents:
diff changeset
   696
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   697
02bb8761fcce Initial load
duke
parents:
diff changeset
   698
    public void initializeServerPIInfo( CorbaMessageMediator request,
02bb8761fcce Initial load
duke
parents:
diff changeset
   699
        ObjectAdapter oa, byte[] objectId, ObjectKeyTemplate oktemp )
02bb8761fcce Initial load
duke
parents:
diff changeset
   700
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   701
        if( !hasServerInterceptors ) return;
02bb8761fcce Initial load
duke
parents:
diff changeset
   702
02bb8761fcce Initial load
duke
parents:
diff changeset
   703
        RequestInfoStack infoStack =
02bb8761fcce Initial load
duke
parents:
diff changeset
   704
            (RequestInfoStack)threadLocalServerRequestInfoStack.get();
02bb8761fcce Initial load
duke
parents:
diff changeset
   705
        ServerRequestInfoImpl info = new ServerRequestInfoImpl( orb );
02bb8761fcce Initial load
duke
parents:
diff changeset
   706
        infoStack.push( info );
02bb8761fcce Initial load
duke
parents:
diff changeset
   707
        printPush();
02bb8761fcce Initial load
duke
parents:
diff changeset
   708
02bb8761fcce Initial load
duke
parents:
diff changeset
   709
        // Notify request object that once response is constructed, make
02bb8761fcce Initial load
duke
parents:
diff changeset
   710
        // sure we execute ending points.
02bb8761fcce Initial load
duke
parents:
diff changeset
   711
        request.setExecutePIInResponseConstructor( true );
02bb8761fcce Initial load
duke
parents:
diff changeset
   712
02bb8761fcce Initial load
duke
parents:
diff changeset
   713
        info.setInfo( request, oa, objectId, oktemp );
02bb8761fcce Initial load
duke
parents:
diff changeset
   714
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   715
02bb8761fcce Initial load
duke
parents:
diff changeset
   716
    public void setServerPIInfo( java.lang.Object servant,
02bb8761fcce Initial load
duke
parents:
diff changeset
   717
                                          String targetMostDerivedInterface )
02bb8761fcce Initial load
duke
parents:
diff changeset
   718
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   719
        if( !hasServerInterceptors ) return;
02bb8761fcce Initial load
duke
parents:
diff changeset
   720
02bb8761fcce Initial load
duke
parents:
diff changeset
   721
        ServerRequestInfoImpl info = peekServerRequestInfoImplStack();
02bb8761fcce Initial load
duke
parents:
diff changeset
   722
        info.setInfo( servant, targetMostDerivedInterface );
02bb8761fcce Initial load
duke
parents:
diff changeset
   723
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   724
02bb8761fcce Initial load
duke
parents:
diff changeset
   725
    public void cleanupServerPIRequest() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   726
        if( !hasServerInterceptors ) return;
02bb8761fcce Initial load
duke
parents:
diff changeset
   727
02bb8761fcce Initial load
duke
parents:
diff changeset
   728
        RequestInfoStack infoStack =
02bb8761fcce Initial load
duke
parents:
diff changeset
   729
            (RequestInfoStack)threadLocalServerRequestInfoStack.get();
02bb8761fcce Initial load
duke
parents:
diff changeset
   730
        infoStack.pop();
02bb8761fcce Initial load
duke
parents:
diff changeset
   731
        printPop();
02bb8761fcce Initial load
duke
parents:
diff changeset
   732
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   733
02bb8761fcce Initial load
duke
parents:
diff changeset
   734
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
   735
     **********************************************************************
02bb8761fcce Initial load
duke
parents:
diff changeset
   736
     *  The following methods are private utility methods.
02bb8761fcce Initial load
duke
parents:
diff changeset
   737
     ************************************************************************/
02bb8761fcce Initial load
duke
parents:
diff changeset
   738
02bb8761fcce Initial load
duke
parents:
diff changeset
   739
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   740
     * Handles exceptions for the starting and intermediate points for
02bb8761fcce Initial load
duke
parents:
diff changeset
   741
     * server request interceptors.  This is common code that has been
02bb8761fcce Initial load
duke
parents:
diff changeset
   742
     * factored out into this utility method.
02bb8761fcce Initial load
duke
parents:
diff changeset
   743
     * <p>
02bb8761fcce Initial load
duke
parents:
diff changeset
   744
     * This method will NOT work for ending points.
02bb8761fcce Initial load
duke
parents:
diff changeset
   745
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   746
    private void serverPIHandleExceptions( ServerRequestInfoImpl info )
02bb8761fcce Initial load
duke
parents:
diff changeset
   747
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   748
        int endingPointCall = info.getEndingPointCall();
02bb8761fcce Initial load
duke
parents:
diff changeset
   749
        if(endingPointCall == ServerRequestInfoImpl.CALL_SEND_EXCEPTION) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   750
            // If a system exception was thrown, throw it to caller:
02bb8761fcce Initial load
duke
parents:
diff changeset
   751
            throw (SystemException)info.getException();
02bb8761fcce Initial load
duke
parents:
diff changeset
   752
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   753
        else if( (endingPointCall == ServerRequestInfoImpl.CALL_SEND_OTHER) &&
02bb8761fcce Initial load
duke
parents:
diff changeset
   754
                 (info.getForwardRequestException() != null) )
02bb8761fcce Initial load
duke
parents:
diff changeset
   755
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
   756
            // If an interceptor throws a forward request, convert it
02bb8761fcce Initial load
duke
parents:
diff changeset
   757
            // into a ForwardException for easier handling:
02bb8761fcce Initial load
duke
parents:
diff changeset
   758
            IOR ior = info.getForwardRequestIOR();
02bb8761fcce Initial load
duke
parents:
diff changeset
   759
            throw new ForwardException( orb, ior );
02bb8761fcce Initial load
duke
parents:
diff changeset
   760
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   761
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   762
02bb8761fcce Initial load
duke
parents:
diff changeset
   763
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   764
     * Utility method to convert a PI reply status short to a ReplyMessage
02bb8761fcce Initial load
duke
parents:
diff changeset
   765
     * constant.  This is a reverse lookup on the table defined in
02bb8761fcce Initial load
duke
parents:
diff changeset
   766
     * REPLY_MESSAGE_TO_PI_REPLY_STATUS.  The reverse lookup need not be
02bb8761fcce Initial load
duke
parents:
diff changeset
   767
     * performed as quickly since it is only executed in exception
02bb8761fcce Initial load
duke
parents:
diff changeset
   768
     * conditions.
02bb8761fcce Initial load
duke
parents:
diff changeset
   769
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   770
    private int convertPIReplyStatusToReplyMessage( short replyStatus ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   771
        int result = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
   772
        for( int i = 0; i < REPLY_MESSAGE_TO_PI_REPLY_STATUS.length; i++ ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   773
            if( REPLY_MESSAGE_TO_PI_REPLY_STATUS[i] == replyStatus ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   774
                result = i;
02bb8761fcce Initial load
duke
parents:
diff changeset
   775
                break;
02bb8761fcce Initial load
duke
parents:
diff changeset
   776
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   777
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   778
        return result;
02bb8761fcce Initial load
duke
parents:
diff changeset
   779
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   780
02bb8761fcce Initial load
duke
parents:
diff changeset
   781
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   782
     * Convenience method to get the ClientRequestInfoImpl object off the
02bb8761fcce Initial load
duke
parents:
diff changeset
   783
     * top of the ThreadLocal stack.  Throws an INTERNAL exception if
02bb8761fcce Initial load
duke
parents:
diff changeset
   784
     * the Info stack is empty.
02bb8761fcce Initial load
duke
parents:
diff changeset
   785
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   786
    private ClientRequestInfoImpl peekClientRequestInfoImplStack() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   787
        RequestInfoStack infoStack =
02bb8761fcce Initial load
duke
parents:
diff changeset
   788
            (RequestInfoStack)threadLocalClientRequestInfoStack.get();
02bb8761fcce Initial load
duke
parents:
diff changeset
   789
        ClientRequestInfoImpl info = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   790
        if( !infoStack.empty() ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   791
            info = (ClientRequestInfoImpl)infoStack.peek();
02bb8761fcce Initial load
duke
parents:
diff changeset
   792
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   793
            throw wrapper.clientInfoStackNull() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   794
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   795
02bb8761fcce Initial load
duke
parents:
diff changeset
   796
        return info;
02bb8761fcce Initial load
duke
parents:
diff changeset
   797
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   798
02bb8761fcce Initial load
duke
parents:
diff changeset
   799
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   800
     * Convenience method to get the ServerRequestInfoImpl object off the
02bb8761fcce Initial load
duke
parents:
diff changeset
   801
     * top of the ThreadLocal stack.  Returns null if there are none.
02bb8761fcce Initial load
duke
parents:
diff changeset
   802
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   803
    private ServerRequestInfoImpl peekServerRequestInfoImplStack() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   804
        RequestInfoStack infoStack =
02bb8761fcce Initial load
duke
parents:
diff changeset
   805
            (RequestInfoStack)threadLocalServerRequestInfoStack.get();
02bb8761fcce Initial load
duke
parents:
diff changeset
   806
        ServerRequestInfoImpl info = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   807
02bb8761fcce Initial load
duke
parents:
diff changeset
   808
        if( !infoStack.empty() ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   809
            info = (ServerRequestInfoImpl)infoStack.peek();
02bb8761fcce Initial load
duke
parents:
diff changeset
   810
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   811
            throw wrapper.serverInfoStackNull() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   812
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   813
02bb8761fcce Initial load
duke
parents:
diff changeset
   814
        return info;
02bb8761fcce Initial load
duke
parents:
diff changeset
   815
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   816
02bb8761fcce Initial load
duke
parents:
diff changeset
   817
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   818
     * Convenience method to determine whether Client PI is enabled
02bb8761fcce Initial load
duke
parents:
diff changeset
   819
     * for requests on this thread.
02bb8761fcce Initial load
duke
parents:
diff changeset
   820
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   821
    private boolean isClientPIEnabledForThisThread() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   822
        RequestInfoStack infoStack =
02bb8761fcce Initial load
duke
parents:
diff changeset
   823
            (RequestInfoStack)threadLocalClientRequestInfoStack.get();
02bb8761fcce Initial load
duke
parents:
diff changeset
   824
        return (infoStack.disableCount == 0);
02bb8761fcce Initial load
duke
parents:
diff changeset
   825
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   826
02bb8761fcce Initial load
duke
parents:
diff changeset
   827
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   828
     * Call pre_init on all ORB initializers
02bb8761fcce Initial load
duke
parents:
diff changeset
   829
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   830
    private void preInitORBInitializers( ORBInitInfoImpl info ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   831
02bb8761fcce Initial load
duke
parents:
diff changeset
   832
        // Inform ORBInitInfo we are in pre_init stage
02bb8761fcce Initial load
duke
parents:
diff changeset
   833
        info.setStage( ORBInitInfoImpl.STAGE_PRE_INIT );
02bb8761fcce Initial load
duke
parents:
diff changeset
   834
02bb8761fcce Initial load
duke
parents:
diff changeset
   835
        // Step through each initializer instantiation and call its
02bb8761fcce Initial load
duke
parents:
diff changeset
   836
        // pre_init.  Ignore any exceptions.
02bb8761fcce Initial load
duke
parents:
diff changeset
   837
        for( int i = 0; i < orb.getORBData().getORBInitializers().length;
02bb8761fcce Initial load
duke
parents:
diff changeset
   838
            i++ ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   839
            ORBInitializer init = orb.getORBData().getORBInitializers()[i];
02bb8761fcce Initial load
duke
parents:
diff changeset
   840
            if( init != null ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   841
                try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   842
                    init.pre_init( info );
02bb8761fcce Initial load
duke
parents:
diff changeset
   843
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   844
                catch( Exception e ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   845
                    // As per orbos/99-12-02, section 9.3.1.2, "If there are
02bb8761fcce Initial load
duke
parents:
diff changeset
   846
                    // any exceptions, the ORB shall ignore them and proceed."
02bb8761fcce Initial load
duke
parents:
diff changeset
   847
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   848
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   849
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   850
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   851
02bb8761fcce Initial load
duke
parents:
diff changeset
   852
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   853
     * Call post_init on all ORB initializers
02bb8761fcce Initial load
duke
parents:
diff changeset
   854
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   855
    private void postInitORBInitializers( ORBInitInfoImpl info ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   856
02bb8761fcce Initial load
duke
parents:
diff changeset
   857
        // Inform ORBInitInfo we are in post_init stage
02bb8761fcce Initial load
duke
parents:
diff changeset
   858
        info.setStage( ORBInitInfoImpl.STAGE_POST_INIT );
02bb8761fcce Initial load
duke
parents:
diff changeset
   859
02bb8761fcce Initial load
duke
parents:
diff changeset
   860
        // Step through each initializer instantiation and call its post_init.
02bb8761fcce Initial load
duke
parents:
diff changeset
   861
        // Ignore any exceptions.
02bb8761fcce Initial load
duke
parents:
diff changeset
   862
        for( int i = 0; i < orb.getORBData().getORBInitializers().length;
02bb8761fcce Initial load
duke
parents:
diff changeset
   863
            i++ ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   864
            ORBInitializer init = orb.getORBData().getORBInitializers()[i];
02bb8761fcce Initial load
duke
parents:
diff changeset
   865
            if( init != null ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   866
                try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   867
                    init.post_init( info );
02bb8761fcce Initial load
duke
parents:
diff changeset
   868
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   869
                catch( Exception e ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   870
                    // As per orbos/99-12-02, section 9.3.1.2, "If there are
02bb8761fcce Initial load
duke
parents:
diff changeset
   871
                    // any exceptions, the ORB shall ignore them and proceed."
02bb8761fcce Initial load
duke
parents:
diff changeset
   872
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   873
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   874
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   875
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   876
02bb8761fcce Initial load
duke
parents:
diff changeset
   877
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   878
     * Creates the ORBInitInfo object to be passed to ORB intializers'
02bb8761fcce Initial load
duke
parents:
diff changeset
   879
     * pre_init and post_init methods
02bb8761fcce Initial load
duke
parents:
diff changeset
   880
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   881
    private ORBInitInfoImpl createORBInitInfo() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   882
        ORBInitInfoImpl result = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   883
02bb8761fcce Initial load
duke
parents:
diff changeset
   884
        // arguments comes from set_parameters.  May be null.
02bb8761fcce Initial load
duke
parents:
diff changeset
   885
02bb8761fcce Initial load
duke
parents:
diff changeset
   886
        // _REVISIT_ The spec does not specify which ID this is to be.
02bb8761fcce Initial load
duke
parents:
diff changeset
   887
        // We currently get this from the corba.ORB, which reads it from
02bb8761fcce Initial load
duke
parents:
diff changeset
   888
        // the ORB_ID_PROPERTY property.
02bb8761fcce Initial load
duke
parents:
diff changeset
   889
        String orbId = orb.getORBData().getORBId() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   890
02bb8761fcce Initial load
duke
parents:
diff changeset
   891
        result = new ORBInitInfoImpl( orb, arguments, orbId, codecFactory );
02bb8761fcce Initial load
duke
parents:
diff changeset
   892
02bb8761fcce Initial load
duke
parents:
diff changeset
   893
        return result;
02bb8761fcce Initial load
duke
parents:
diff changeset
   894
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   895
02bb8761fcce Initial load
duke
parents:
diff changeset
   896
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   897
     * Called by ORBInitInfo when an interceptor needs to be registered.
02bb8761fcce Initial load
duke
parents:
diff changeset
   898
     * The type is one of:
02bb8761fcce Initial load
duke
parents:
diff changeset
   899
     * <ul>
02bb8761fcce Initial load
duke
parents:
diff changeset
   900
     *   <li>INTERCEPTOR_TYPE_CLIENT - ClientRequestInterceptor
02bb8761fcce Initial load
duke
parents:
diff changeset
   901
     *   <li>INTERCEPTOR_TYPE_SERVER - ServerRequestInterceptor
02bb8761fcce Initial load
duke
parents:
diff changeset
   902
     *   <li>INTERCEPTOR_TYPE_IOR - IORInterceptor
02bb8761fcce Initial load
duke
parents:
diff changeset
   903
     * </ul>
02bb8761fcce Initial load
duke
parents:
diff changeset
   904
     *
02bb8761fcce Initial load
duke
parents:
diff changeset
   905
     * @exception DuplicateName Thrown if an interceptor of the given
02bb8761fcce Initial load
duke
parents:
diff changeset
   906
     *     name already exists for the given type.
02bb8761fcce Initial load
duke
parents:
diff changeset
   907
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   908
    public void register_interceptor( Interceptor interceptor, int type )
02bb8761fcce Initial load
duke
parents:
diff changeset
   909
        throws DuplicateName
02bb8761fcce Initial load
duke
parents:
diff changeset
   910
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   911
        // We will assume interceptor is not null, since it is called
02bb8761fcce Initial load
duke
parents:
diff changeset
   912
        // internally.
02bb8761fcce Initial load
duke
parents:
diff changeset
   913
        if( (type >= InterceptorList.NUM_INTERCEPTOR_TYPES) || (type < 0) ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   914
            throw wrapper.typeOutOfRange( new Integer( type ) ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   915
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   916
02bb8761fcce Initial load
duke
parents:
diff changeset
   917
        String interceptorName = interceptor.name();
02bb8761fcce Initial load
duke
parents:
diff changeset
   918
02bb8761fcce Initial load
duke
parents:
diff changeset
   919
        if( interceptorName == null ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   920
            throw wrapper.nameNull() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   921
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   922
02bb8761fcce Initial load
duke
parents:
diff changeset
   923
        // Register with interceptor list:
02bb8761fcce Initial load
duke
parents:
diff changeset
   924
        interceptorList.register_interceptor( interceptor, type );
02bb8761fcce Initial load
duke
parents:
diff changeset
   925
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   926
02bb8761fcce Initial load
duke
parents:
diff changeset
   927
    public Current getPICurrent( ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   928
        return current;
02bb8761fcce Initial load
duke
parents:
diff changeset
   929
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   930
02bb8761fcce Initial load
duke
parents:
diff changeset
   931
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   932
     * Called when an invalid null parameter was passed.  Throws a
02bb8761fcce Initial load
duke
parents:
diff changeset
   933
     * BAD_PARAM with a minor code of 1
02bb8761fcce Initial load
duke
parents:
diff changeset
   934
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   935
    private void nullParam()
02bb8761fcce Initial load
duke
parents:
diff changeset
   936
        throws BAD_PARAM
02bb8761fcce Initial load
duke
parents:
diff changeset
   937
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   938
        throw orbutilWrapper.nullParam() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   939
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   940
02bb8761fcce Initial load
duke
parents:
diff changeset
   941
    /** This is the implementation of standard API defined in org.omg.CORBA.ORB
02bb8761fcce Initial load
duke
parents:
diff changeset
   942
     *  class. This method finds the Policy Factory for the given Policy Type
02bb8761fcce Initial load
duke
parents:
diff changeset
   943
     *  and instantiates the Policy object from the Factory. It will throw
02bb8761fcce Initial load
duke
parents:
diff changeset
   944
     *  PolicyError exception, If the PolicyFactory for the given type is
02bb8761fcce Initial load
duke
parents:
diff changeset
   945
     *  not registered.
02bb8761fcce Initial load
duke
parents:
diff changeset
   946
     *  _REVISIT_, Once Policy Framework work is completed, Reorganize
02bb8761fcce Initial load
duke
parents:
diff changeset
   947
     *  this method to com.sun.corba.se.spi.orb.ORB.
02bb8761fcce Initial load
duke
parents:
diff changeset
   948
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   949
    public org.omg.CORBA.Policy create_policy(int type, org.omg.CORBA.Any val)
02bb8761fcce Initial load
duke
parents:
diff changeset
   950
        throws org.omg.CORBA.PolicyError
02bb8761fcce Initial load
duke
parents:
diff changeset
   951
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   952
        if( val == null ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   953
            nullParam( );
02bb8761fcce Initial load
duke
parents:
diff changeset
   954
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   955
        if( policyFactoryTable == null ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   956
            throw new org.omg.CORBA.PolicyError(
02bb8761fcce Initial load
duke
parents:
diff changeset
   957
                "There is no PolicyFactory Registered for type " + type,
02bb8761fcce Initial load
duke
parents:
diff changeset
   958
                BAD_POLICY.value );
02bb8761fcce Initial load
duke
parents:
diff changeset
   959
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   960
        PolicyFactory factory = (PolicyFactory)policyFactoryTable.get(
02bb8761fcce Initial load
duke
parents:
diff changeset
   961
            new Integer(type) );
02bb8761fcce Initial load
duke
parents:
diff changeset
   962
        if( factory == null ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   963
            throw new org.omg.CORBA.PolicyError(
02bb8761fcce Initial load
duke
parents:
diff changeset
   964
                " Could Not Find PolicyFactory for the Type " + type,
02bb8761fcce Initial load
duke
parents:
diff changeset
   965
                BAD_POLICY.value);
02bb8761fcce Initial load
duke
parents:
diff changeset
   966
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   967
        org.omg.CORBA.Policy policy = factory.create_policy( type, val );
02bb8761fcce Initial load
duke
parents:
diff changeset
   968
        return policy;
02bb8761fcce Initial load
duke
parents:
diff changeset
   969
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   970
02bb8761fcce Initial load
duke
parents:
diff changeset
   971
    /** This method registers the Policy Factory in the policyFactoryTable,
02bb8761fcce Initial load
duke
parents:
diff changeset
   972
     *  which is a HashMap. This method is made package private, because
02bb8761fcce Initial load
duke
parents:
diff changeset
   973
     *  it is used internally by the  Interceptors.
02bb8761fcce Initial load
duke
parents:
diff changeset
   974
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   975
    public void registerPolicyFactory( int type, PolicyFactory factory ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   976
        if( policyFactoryTable == null ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   977
            policyFactoryTable = new HashMap();
02bb8761fcce Initial load
duke
parents:
diff changeset
   978
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   979
        Integer key = new Integer( type );
02bb8761fcce Initial load
duke
parents:
diff changeset
   980
        java.lang.Object val = policyFactoryTable.get( key );
02bb8761fcce Initial load
duke
parents:
diff changeset
   981
        if( val == null ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   982
            policyFactoryTable.put( key, factory );
02bb8761fcce Initial load
duke
parents:
diff changeset
   983
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   984
        else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   985
            throw omgWrapper.policyFactoryRegFailed( new Integer( type ) ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   986
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   987
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   988
02bb8761fcce Initial load
duke
parents:
diff changeset
   989
    public synchronized int allocateServerRequestId ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   990
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   991
        return serverRequestIdCounter++;
02bb8761fcce Initial load
duke
parents:
diff changeset
   992
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   993
}