corba/src/share/classes/com/sun/corba/se/impl/protocol/CorbaMessageMediatorImpl.java
author coffeys
Wed, 27 Jun 2012 21:09:29 +0100
changeset 13171 1ac5e9a54a6e
parent 5555 b2b5ed3f0d0d
child 18307 8bf60b58675b
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: 5555
diff changeset
     2
 * Copyright (c) 2001, 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
02bb8761fcce Initial load
duke
parents:
diff changeset
    26
package com.sun.corba.se.impl.protocol;
02bb8761fcce Initial load
duke
parents:
diff changeset
    27
02bb8761fcce Initial load
duke
parents:
diff changeset
    28
import java.io.ByteArrayOutputStream;
02bb8761fcce Initial load
duke
parents:
diff changeset
    29
import java.io.IOException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    30
import java.io.PrintWriter;
02bb8761fcce Initial load
duke
parents:
diff changeset
    31
import java.nio.ByteBuffer;
02bb8761fcce Initial load
duke
parents:
diff changeset
    32
import java.nio.channels.SelectionKey;
02bb8761fcce Initial load
duke
parents:
diff changeset
    33
import java.util.EmptyStackException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    34
import java.util.Iterator;
02bb8761fcce Initial load
duke
parents:
diff changeset
    35
02bb8761fcce Initial load
duke
parents:
diff changeset
    36
import org.omg.CORBA.Any;
02bb8761fcce Initial load
duke
parents:
diff changeset
    37
import org.omg.CORBA.CompletionStatus;
02bb8761fcce Initial load
duke
parents:
diff changeset
    38
import org.omg.CORBA.ExceptionList;
02bb8761fcce Initial load
duke
parents:
diff changeset
    39
import org.omg.CORBA.INTERNAL;
02bb8761fcce Initial load
duke
parents:
diff changeset
    40
import org.omg.CORBA.Principal;
02bb8761fcce Initial load
duke
parents:
diff changeset
    41
import org.omg.CORBA.SystemException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    42
import org.omg.CORBA.TypeCode;
02bb8761fcce Initial load
duke
parents:
diff changeset
    43
import org.omg.CORBA.UnknownUserException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    44
import org.omg.CORBA.UNKNOWN;
02bb8761fcce Initial load
duke
parents:
diff changeset
    45
import org.omg.CORBA.portable.ResponseHandler;
02bb8761fcce Initial load
duke
parents:
diff changeset
    46
import org.omg.CORBA.portable.UnknownException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    47
import org.omg.CORBA_2_3.portable.InputStream;
02bb8761fcce Initial load
duke
parents:
diff changeset
    48
import org.omg.CORBA_2_3.portable.OutputStream;
02bb8761fcce Initial load
duke
parents:
diff changeset
    49
import org.omg.IOP.ExceptionDetailMessage;
02bb8761fcce Initial load
duke
parents:
diff changeset
    50
import org.omg.IOP.TAG_RMI_CUSTOM_MAX_STREAM_FORMAT;
02bb8761fcce Initial load
duke
parents:
diff changeset
    51
02bb8761fcce Initial load
duke
parents:
diff changeset
    52
import com.sun.corba.se.pept.broker.Broker;
02bb8761fcce Initial load
duke
parents:
diff changeset
    53
import com.sun.corba.se.pept.encoding.InputObject;
02bb8761fcce Initial load
duke
parents:
diff changeset
    54
import com.sun.corba.se.pept.encoding.OutputObject;
02bb8761fcce Initial load
duke
parents:
diff changeset
    55
import com.sun.corba.se.pept.protocol.MessageMediator;
02bb8761fcce Initial load
duke
parents:
diff changeset
    56
import com.sun.corba.se.pept.protocol.ProtocolHandler;
02bb8761fcce Initial load
duke
parents:
diff changeset
    57
import com.sun.corba.se.pept.transport.ByteBufferPool;
02bb8761fcce Initial load
duke
parents:
diff changeset
    58
import com.sun.corba.se.pept.transport.Connection;
02bb8761fcce Initial load
duke
parents:
diff changeset
    59
import com.sun.corba.se.pept.transport.ContactInfo;
02bb8761fcce Initial load
duke
parents:
diff changeset
    60
import com.sun.corba.se.pept.transport.EventHandler;
02bb8761fcce Initial load
duke
parents:
diff changeset
    61
02bb8761fcce Initial load
duke
parents:
diff changeset
    62
import com.sun.corba.se.spi.ior.IOR;
02bb8761fcce Initial load
duke
parents:
diff changeset
    63
import com.sun.corba.se.spi.ior.ObjectKey;
02bb8761fcce Initial load
duke
parents:
diff changeset
    64
import com.sun.corba.se.spi.ior.ObjectKeyTemplate;
02bb8761fcce Initial load
duke
parents:
diff changeset
    65
import com.sun.corba.se.spi.ior.iiop.GIOPVersion;
02bb8761fcce Initial load
duke
parents:
diff changeset
    66
import com.sun.corba.se.spi.ior.iiop.IIOPProfileTemplate;
02bb8761fcce Initial load
duke
parents:
diff changeset
    67
import com.sun.corba.se.spi.ior.iiop.IIOPProfile;
02bb8761fcce Initial load
duke
parents:
diff changeset
    68
import com.sun.corba.se.spi.ior.iiop.MaxStreamFormatVersionComponent;
02bb8761fcce Initial load
duke
parents:
diff changeset
    69
import com.sun.corba.se.spi.oa.OAInvocationInfo;
02bb8761fcce Initial load
duke
parents:
diff changeset
    70
import com.sun.corba.se.spi.oa.ObjectAdapter;
02bb8761fcce Initial load
duke
parents:
diff changeset
    71
import com.sun.corba.se.spi.orb.ORB;
02bb8761fcce Initial load
duke
parents:
diff changeset
    72
import com.sun.corba.se.spi.orb.ORBVersionFactory;
02bb8761fcce Initial load
duke
parents:
diff changeset
    73
import com.sun.corba.se.spi.protocol.CorbaMessageMediator;
02bb8761fcce Initial load
duke
parents:
diff changeset
    74
import com.sun.corba.se.spi.protocol.CorbaProtocolHandler;
02bb8761fcce Initial load
duke
parents:
diff changeset
    75
import com.sun.corba.se.spi.protocol.CorbaServerRequestDispatcher;
02bb8761fcce Initial load
duke
parents:
diff changeset
    76
import com.sun.corba.se.spi.protocol.ForwardException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    77
import com.sun.corba.se.spi.transport.CorbaConnection;
02bb8761fcce Initial load
duke
parents:
diff changeset
    78
import com.sun.corba.se.spi.transport.CorbaContactInfo;
02bb8761fcce Initial load
duke
parents:
diff changeset
    79
import com.sun.corba.se.spi.transport.CorbaResponseWaitingRoom;
02bb8761fcce Initial load
duke
parents:
diff changeset
    80
import com.sun.corba.se.spi.logging.CORBALogDomains;
02bb8761fcce Initial load
duke
parents:
diff changeset
    81
02bb8761fcce Initial load
duke
parents:
diff changeset
    82
import com.sun.corba.se.spi.servicecontext.ORBVersionServiceContext;
02bb8761fcce Initial load
duke
parents:
diff changeset
    83
import com.sun.corba.se.spi.servicecontext.ServiceContexts;
02bb8761fcce Initial load
duke
parents:
diff changeset
    84
import com.sun.corba.se.spi.servicecontext.UEInfoServiceContext;
02bb8761fcce Initial load
duke
parents:
diff changeset
    85
import com.sun.corba.se.spi.servicecontext.MaxStreamFormatVersionServiceContext;
02bb8761fcce Initial load
duke
parents:
diff changeset
    86
import com.sun.corba.se.spi.servicecontext.SendingContextServiceContext;
02bb8761fcce Initial load
duke
parents:
diff changeset
    87
import com.sun.corba.se.spi.servicecontext.UnknownServiceContext;
02bb8761fcce Initial load
duke
parents:
diff changeset
    88
02bb8761fcce Initial load
duke
parents:
diff changeset
    89
import com.sun.corba.se.impl.corba.RequestImpl;
02bb8761fcce Initial load
duke
parents:
diff changeset
    90
import com.sun.corba.se.impl.encoding.BufferManagerFactory;
02bb8761fcce Initial load
duke
parents:
diff changeset
    91
import com.sun.corba.se.impl.encoding.BufferManagerReadStream;
02bb8761fcce Initial load
duke
parents:
diff changeset
    92
import com.sun.corba.se.impl.encoding.CDRInputObject;
02bb8761fcce Initial load
duke
parents:
diff changeset
    93
import com.sun.corba.se.impl.encoding.CDROutputObject;
02bb8761fcce Initial load
duke
parents:
diff changeset
    94
import com.sun.corba.se.impl.encoding.EncapsOutputStream;
02bb8761fcce Initial load
duke
parents:
diff changeset
    95
import com.sun.corba.se.impl.logging.ORBUtilSystemException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    96
import com.sun.corba.se.impl.logging.InterceptorsSystemException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    97
import com.sun.corba.se.impl.orbutil.ORBConstants;
02bb8761fcce Initial load
duke
parents:
diff changeset
    98
import com.sun.corba.se.impl.orbutil.ORBUtility;
02bb8761fcce Initial load
duke
parents:
diff changeset
    99
import com.sun.corba.se.impl.ior.iiop.JavaSerializationComponent;
02bb8761fcce Initial load
duke
parents:
diff changeset
   100
import com.sun.corba.se.impl.protocol.AddressingDispositionException;
02bb8761fcce Initial load
duke
parents:
diff changeset
   101
import com.sun.corba.se.impl.protocol.RequestCanceledException;
02bb8761fcce Initial load
duke
parents:
diff changeset
   102
import com.sun.corba.se.impl.protocol.giopmsgheaders.AddressingDispositionHelper;
02bb8761fcce Initial load
duke
parents:
diff changeset
   103
import com.sun.corba.se.impl.protocol.giopmsgheaders.CancelRequestMessage;
02bb8761fcce Initial load
duke
parents:
diff changeset
   104
import com.sun.corba.se.impl.protocol.giopmsgheaders.FragmentMessage_1_1;
02bb8761fcce Initial load
duke
parents:
diff changeset
   105
import com.sun.corba.se.impl.protocol.giopmsgheaders.FragmentMessage_1_2;
02bb8761fcce Initial load
duke
parents:
diff changeset
   106
import com.sun.corba.se.impl.protocol.giopmsgheaders.LocateRequestMessage;
02bb8761fcce Initial load
duke
parents:
diff changeset
   107
import com.sun.corba.se.impl.protocol.giopmsgheaders.LocateRequestMessage_1_0;
02bb8761fcce Initial load
duke
parents:
diff changeset
   108
import com.sun.corba.se.impl.protocol.giopmsgheaders.LocateRequestMessage_1_1;
02bb8761fcce Initial load
duke
parents:
diff changeset
   109
import com.sun.corba.se.impl.protocol.giopmsgheaders.LocateRequestMessage_1_2;
02bb8761fcce Initial load
duke
parents:
diff changeset
   110
import com.sun.corba.se.impl.protocol.giopmsgheaders.LocateReplyOrReplyMessage;
02bb8761fcce Initial load
duke
parents:
diff changeset
   111
import com.sun.corba.se.impl.protocol.giopmsgheaders.LocateReplyMessage;
02bb8761fcce Initial load
duke
parents:
diff changeset
   112
import com.sun.corba.se.impl.protocol.giopmsgheaders.LocateReplyMessage_1_0;
02bb8761fcce Initial load
duke
parents:
diff changeset
   113
import com.sun.corba.se.impl.protocol.giopmsgheaders.LocateReplyMessage_1_1;
02bb8761fcce Initial load
duke
parents:
diff changeset
   114
import com.sun.corba.se.impl.protocol.giopmsgheaders.LocateReplyMessage_1_2;
02bb8761fcce Initial load
duke
parents:
diff changeset
   115
import com.sun.corba.se.impl.protocol.giopmsgheaders.Message;
02bb8761fcce Initial load
duke
parents:
diff changeset
   116
import com.sun.corba.se.impl.protocol.giopmsgheaders.MessageBase;
02bb8761fcce Initial load
duke
parents:
diff changeset
   117
import com.sun.corba.se.impl.protocol.giopmsgheaders.MessageHandler;
02bb8761fcce Initial load
duke
parents:
diff changeset
   118
import com.sun.corba.se.impl.protocol.giopmsgheaders.ReplyMessage;
02bb8761fcce Initial load
duke
parents:
diff changeset
   119
import com.sun.corba.se.impl.protocol.giopmsgheaders.ReplyMessage_1_0;
02bb8761fcce Initial load
duke
parents:
diff changeset
   120
import com.sun.corba.se.impl.protocol.giopmsgheaders.ReplyMessage_1_1;
02bb8761fcce Initial load
duke
parents:
diff changeset
   121
import com.sun.corba.se.impl.protocol.giopmsgheaders.ReplyMessage_1_2;
02bb8761fcce Initial load
duke
parents:
diff changeset
   122
import com.sun.corba.se.impl.protocol.giopmsgheaders.RequestMessage;
02bb8761fcce Initial load
duke
parents:
diff changeset
   123
import com.sun.corba.se.impl.protocol.giopmsgheaders.RequestMessage_1_0 ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   124
import com.sun.corba.se.impl.protocol.giopmsgheaders.RequestMessage_1_1 ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   125
import com.sun.corba.se.impl.protocol.giopmsgheaders.RequestMessage_1_2 ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   126
02bb8761fcce Initial load
duke
parents:
diff changeset
   127
// REVISIT: make sure no memory leaks in client/server request/reply maps.
02bb8761fcce Initial load
duke
parents:
diff changeset
   128
// REVISIT: normalize requestHeader, replyHeader, messageHeader.
02bb8761fcce Initial load
duke
parents:
diff changeset
   129
02bb8761fcce Initial load
duke
parents:
diff changeset
   130
/**
02bb8761fcce Initial load
duke
parents:
diff changeset
   131
 * @author Harold Carr
02bb8761fcce Initial load
duke
parents:
diff changeset
   132
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
   133
public class CorbaMessageMediatorImpl
02bb8761fcce Initial load
duke
parents:
diff changeset
   134
    implements
02bb8761fcce Initial load
duke
parents:
diff changeset
   135
        CorbaMessageMediator,
02bb8761fcce Initial load
duke
parents:
diff changeset
   136
        CorbaProtocolHandler,
02bb8761fcce Initial load
duke
parents:
diff changeset
   137
        MessageHandler
02bb8761fcce Initial load
duke
parents:
diff changeset
   138
{
02bb8761fcce Initial load
duke
parents:
diff changeset
   139
    protected ORB orb;
02bb8761fcce Initial load
duke
parents:
diff changeset
   140
    protected ORBUtilSystemException wrapper ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   141
    protected InterceptorsSystemException interceptorWrapper ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   142
    protected CorbaContactInfo contactInfo;
02bb8761fcce Initial load
duke
parents:
diff changeset
   143
    protected CorbaConnection connection;
02bb8761fcce Initial load
duke
parents:
diff changeset
   144
    protected short addrDisposition;
02bb8761fcce Initial load
duke
parents:
diff changeset
   145
    protected CDROutputObject outputObject;
02bb8761fcce Initial load
duke
parents:
diff changeset
   146
    protected CDRInputObject inputObject;
02bb8761fcce Initial load
duke
parents:
diff changeset
   147
    protected Message messageHeader;
02bb8761fcce Initial load
duke
parents:
diff changeset
   148
    protected RequestMessage requestHeader;
02bb8761fcce Initial load
duke
parents:
diff changeset
   149
    protected LocateReplyOrReplyMessage replyHeader;
02bb8761fcce Initial load
duke
parents:
diff changeset
   150
    protected String replyExceptionDetailMessage;
02bb8761fcce Initial load
duke
parents:
diff changeset
   151
    protected IOR replyIOR;
02bb8761fcce Initial load
duke
parents:
diff changeset
   152
    protected Integer requestIdInteger;
02bb8761fcce Initial load
duke
parents:
diff changeset
   153
    protected Message dispatchHeader;
02bb8761fcce Initial load
duke
parents:
diff changeset
   154
    protected ByteBuffer dispatchByteBuffer;
02bb8761fcce Initial load
duke
parents:
diff changeset
   155
    protected byte streamFormatVersion;
02bb8761fcce Initial load
duke
parents:
diff changeset
   156
    protected boolean streamFormatVersionSet = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   157
02bb8761fcce Initial load
duke
parents:
diff changeset
   158
    protected org.omg.CORBA.Request diiRequest;
02bb8761fcce Initial load
duke
parents:
diff changeset
   159
02bb8761fcce Initial load
duke
parents:
diff changeset
   160
    protected boolean cancelRequestAlreadySent = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   161
02bb8761fcce Initial load
duke
parents:
diff changeset
   162
    protected ProtocolHandler protocolHandler;
02bb8761fcce Initial load
duke
parents:
diff changeset
   163
    protected boolean _executeReturnServantInResponseConstructor = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   164
    protected boolean _executeRemoveThreadInfoInResponseConstructor = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   165
    protected boolean _executePIInResponseConstructor = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   166
02bb8761fcce Initial load
duke
parents:
diff changeset
   167
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   168
    // Client-side constructor.
02bb8761fcce Initial load
duke
parents:
diff changeset
   169
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   170
02bb8761fcce Initial load
duke
parents:
diff changeset
   171
    public CorbaMessageMediatorImpl(ORB orb,
02bb8761fcce Initial load
duke
parents:
diff changeset
   172
                                    ContactInfo contactInfo,
02bb8761fcce Initial load
duke
parents:
diff changeset
   173
                                    Connection connection,
02bb8761fcce Initial load
duke
parents:
diff changeset
   174
                                    GIOPVersion giopVersion,
02bb8761fcce Initial load
duke
parents:
diff changeset
   175
                                    IOR ior,
02bb8761fcce Initial load
duke
parents:
diff changeset
   176
                                    int requestId,
02bb8761fcce Initial load
duke
parents:
diff changeset
   177
                                    short addrDisposition,
02bb8761fcce Initial load
duke
parents:
diff changeset
   178
                                    String operationName,
02bb8761fcce Initial load
duke
parents:
diff changeset
   179
                                    boolean isOneWay)
02bb8761fcce Initial load
duke
parents:
diff changeset
   180
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   181
        this( orb, connection ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   182
02bb8761fcce Initial load
duke
parents:
diff changeset
   183
        this.contactInfo = (CorbaContactInfo) contactInfo;
02bb8761fcce Initial load
duke
parents:
diff changeset
   184
        this.addrDisposition = addrDisposition;
02bb8761fcce Initial load
duke
parents:
diff changeset
   185
02bb8761fcce Initial load
duke
parents:
diff changeset
   186
        streamFormatVersion =
02bb8761fcce Initial load
duke
parents:
diff changeset
   187
            getStreamFormatVersionForThisRequest(
02bb8761fcce Initial load
duke
parents:
diff changeset
   188
                ((CorbaContactInfo)this.contactInfo).getEffectiveTargetIOR(),
02bb8761fcce Initial load
duke
parents:
diff changeset
   189
                giopVersion);
02bb8761fcce Initial load
duke
parents:
diff changeset
   190
        streamFormatVersionSet = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   191
02bb8761fcce Initial load
duke
parents:
diff changeset
   192
        requestHeader = (RequestMessage) MessageBase.createRequest(
02bb8761fcce Initial load
duke
parents:
diff changeset
   193
            this.orb,
02bb8761fcce Initial load
duke
parents:
diff changeset
   194
            giopVersion,
02bb8761fcce Initial load
duke
parents:
diff changeset
   195
            ORBUtility.getEncodingVersion(orb, ior),
02bb8761fcce Initial load
duke
parents:
diff changeset
   196
            requestId,
02bb8761fcce Initial load
duke
parents:
diff changeset
   197
            !isOneWay,
02bb8761fcce Initial load
duke
parents:
diff changeset
   198
            ((CorbaContactInfo)this.contactInfo).getEffectiveTargetIOR(),
02bb8761fcce Initial load
duke
parents:
diff changeset
   199
            this.addrDisposition,
02bb8761fcce Initial load
duke
parents:
diff changeset
   200
            operationName,
02bb8761fcce Initial load
duke
parents:
diff changeset
   201
            new ServiceContexts(orb),
02bb8761fcce Initial load
duke
parents:
diff changeset
   202
            null);
02bb8761fcce Initial load
duke
parents:
diff changeset
   203
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   204
02bb8761fcce Initial load
duke
parents:
diff changeset
   205
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   206
    // Acceptor constructor.
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 CorbaMessageMediatorImpl(ORB orb,
02bb8761fcce Initial load
duke
parents:
diff changeset
   210
                                    Connection connection)
02bb8761fcce Initial load
duke
parents:
diff changeset
   211
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   212
        this.orb = orb;
02bb8761fcce Initial load
duke
parents:
diff changeset
   213
        this.connection = (CorbaConnection)connection;
02bb8761fcce Initial load
duke
parents:
diff changeset
   214
        this.wrapper = ORBUtilSystemException.get( orb,
02bb8761fcce Initial load
duke
parents:
diff changeset
   215
            CORBALogDomains.RPC_PROTOCOL ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   216
        this.interceptorWrapper = InterceptorsSystemException.get( orb,
02bb8761fcce Initial load
duke
parents:
diff changeset
   217
            CORBALogDomains.RPC_PROTOCOL ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   218
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   219
02bb8761fcce Initial load
duke
parents:
diff changeset
   220
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   221
    // Dispatcher constructor.
02bb8761fcce Initial load
duke
parents:
diff changeset
   222
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   223
02bb8761fcce Initial load
duke
parents:
diff changeset
   224
    // Note: in some cases (e.g., a reply message) this message
02bb8761fcce Initial load
duke
parents:
diff changeset
   225
    // mediator will only be used for dispatch.  Then the original
02bb8761fcce Initial load
duke
parents:
diff changeset
   226
    // request side mediator will take over.
02bb8761fcce Initial load
duke
parents:
diff changeset
   227
    public CorbaMessageMediatorImpl(ORB orb,
02bb8761fcce Initial load
duke
parents:
diff changeset
   228
                                    CorbaConnection connection,
02bb8761fcce Initial load
duke
parents:
diff changeset
   229
                                    Message dispatchHeader,
02bb8761fcce Initial load
duke
parents:
diff changeset
   230
                                    ByteBuffer byteBuffer)
02bb8761fcce Initial load
duke
parents:
diff changeset
   231
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   232
        this( orb, connection ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   233
        this.dispatchHeader = dispatchHeader;
02bb8761fcce Initial load
duke
parents:
diff changeset
   234
        this.dispatchByteBuffer = byteBuffer;
02bb8761fcce Initial load
duke
parents:
diff changeset
   235
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   236
02bb8761fcce Initial load
duke
parents:
diff changeset
   237
    ////////////////////////////////////////////////////
02bb8761fcce Initial load
duke
parents:
diff changeset
   238
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   239
    // MessageMediator
02bb8761fcce Initial load
duke
parents:
diff changeset
   240
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   241
02bb8761fcce Initial load
duke
parents:
diff changeset
   242
    public Broker getBroker()
02bb8761fcce Initial load
duke
parents:
diff changeset
   243
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   244
        return orb;
02bb8761fcce Initial load
duke
parents:
diff changeset
   245
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   246
02bb8761fcce Initial load
duke
parents:
diff changeset
   247
    public ContactInfo getContactInfo()
02bb8761fcce Initial load
duke
parents:
diff changeset
   248
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   249
        return contactInfo;
02bb8761fcce Initial load
duke
parents:
diff changeset
   250
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   251
02bb8761fcce Initial load
duke
parents:
diff changeset
   252
    public Connection getConnection()
02bb8761fcce Initial load
duke
parents:
diff changeset
   253
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   254
        return connection;
02bb8761fcce Initial load
duke
parents:
diff changeset
   255
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   256
02bb8761fcce Initial load
duke
parents:
diff changeset
   257
    public void initializeMessage()
02bb8761fcce Initial load
duke
parents:
diff changeset
   258
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   259
        getRequestHeader().write(outputObject);
02bb8761fcce Initial load
duke
parents:
diff changeset
   260
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   261
02bb8761fcce Initial load
duke
parents:
diff changeset
   262
    public void finishSendingRequest()
02bb8761fcce Initial load
duke
parents:
diff changeset
   263
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   264
        // REVISIT: probably move logic in outputObject to here.
02bb8761fcce Initial load
duke
parents:
diff changeset
   265
        outputObject.finishSendingMessage();
02bb8761fcce Initial load
duke
parents:
diff changeset
   266
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   267
02bb8761fcce Initial load
duke
parents:
diff changeset
   268
    public InputObject waitForResponse()
02bb8761fcce Initial load
duke
parents:
diff changeset
   269
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   270
        if (getRequestHeader().isResponseExpected()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   271
            return connection.waitForResponse(this);
02bb8761fcce Initial load
duke
parents:
diff changeset
   272
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   273
        return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   274
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   275
02bb8761fcce Initial load
duke
parents:
diff changeset
   276
    public void setOutputObject(OutputObject outputObject)
02bb8761fcce Initial load
duke
parents:
diff changeset
   277
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   278
        this.outputObject = (CDROutputObject) outputObject;
02bb8761fcce Initial load
duke
parents:
diff changeset
   279
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   280
02bb8761fcce Initial load
duke
parents:
diff changeset
   281
    public OutputObject getOutputObject()
02bb8761fcce Initial load
duke
parents:
diff changeset
   282
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   283
        return outputObject;
02bb8761fcce Initial load
duke
parents:
diff changeset
   284
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   285
02bb8761fcce Initial load
duke
parents:
diff changeset
   286
    public void setInputObject(InputObject inputObject)
02bb8761fcce Initial load
duke
parents:
diff changeset
   287
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   288
        this.inputObject = (CDRInputObject) inputObject;
02bb8761fcce Initial load
duke
parents:
diff changeset
   289
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   290
02bb8761fcce Initial load
duke
parents:
diff changeset
   291
    public InputObject getInputObject()
02bb8761fcce Initial load
duke
parents:
diff changeset
   292
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   293
        return inputObject;
02bb8761fcce Initial load
duke
parents:
diff changeset
   294
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   295
02bb8761fcce Initial load
duke
parents:
diff changeset
   296
    ////////////////////////////////////////////////////
02bb8761fcce Initial load
duke
parents:
diff changeset
   297
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   298
    // CorbaMessageMediator
02bb8761fcce Initial load
duke
parents:
diff changeset
   299
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   300
02bb8761fcce Initial load
duke
parents:
diff changeset
   301
    public void setReplyHeader(LocateReplyOrReplyMessage header)
02bb8761fcce Initial load
duke
parents:
diff changeset
   302
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   303
        this.replyHeader = header;
02bb8761fcce Initial load
duke
parents:
diff changeset
   304
        this.replyIOR = header.getIOR(); // REVISIT - need separate field?
02bb8761fcce Initial load
duke
parents:
diff changeset
   305
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   306
02bb8761fcce Initial load
duke
parents:
diff changeset
   307
    public LocateReplyMessage getLocateReplyHeader()
02bb8761fcce Initial load
duke
parents:
diff changeset
   308
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   309
        return (LocateReplyMessage) replyHeader;
02bb8761fcce Initial load
duke
parents:
diff changeset
   310
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   311
02bb8761fcce Initial load
duke
parents:
diff changeset
   312
    public ReplyMessage getReplyHeader()
02bb8761fcce Initial load
duke
parents:
diff changeset
   313
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   314
        return (ReplyMessage) replyHeader;
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 setReplyExceptionDetailMessage(String message)
02bb8761fcce Initial load
duke
parents:
diff changeset
   318
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   319
        replyExceptionDetailMessage = message;
02bb8761fcce Initial load
duke
parents:
diff changeset
   320
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   321
02bb8761fcce Initial load
duke
parents:
diff changeset
   322
    public RequestMessage getRequestHeader()
02bb8761fcce Initial load
duke
parents:
diff changeset
   323
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   324
        return requestHeader;
02bb8761fcce Initial load
duke
parents:
diff changeset
   325
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   326
02bb8761fcce Initial load
duke
parents:
diff changeset
   327
    public GIOPVersion getGIOPVersion()
02bb8761fcce Initial load
duke
parents:
diff changeset
   328
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   329
        if (messageHeader != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   330
            return messageHeader.getGIOPVersion();
02bb8761fcce Initial load
duke
parents:
diff changeset
   331
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   332
        return getRequestHeader().getGIOPVersion();
02bb8761fcce Initial load
duke
parents:
diff changeset
   333
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   334
02bb8761fcce Initial load
duke
parents:
diff changeset
   335
    public byte getEncodingVersion() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   336
        if (messageHeader != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   337
            return messageHeader.getEncodingVersion();
02bb8761fcce Initial load
duke
parents:
diff changeset
   338
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   339
        return getRequestHeader().getEncodingVersion();
02bb8761fcce Initial load
duke
parents:
diff changeset
   340
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   341
02bb8761fcce Initial load
duke
parents:
diff changeset
   342
    public int getRequestId()
02bb8761fcce Initial load
duke
parents:
diff changeset
   343
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   344
        return getRequestHeader().getRequestId();
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 Integer getRequestIdInteger()
02bb8761fcce Initial load
duke
parents:
diff changeset
   348
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   349
        if (requestIdInteger == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   350
            requestIdInteger = new Integer(getRequestHeader().getRequestId());
02bb8761fcce Initial load
duke
parents:
diff changeset
   351
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   352
        return requestIdInteger;
02bb8761fcce Initial load
duke
parents:
diff changeset
   353
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   354
02bb8761fcce Initial load
duke
parents:
diff changeset
   355
    public boolean isOneWay()
02bb8761fcce Initial load
duke
parents:
diff changeset
   356
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   357
        return ! getRequestHeader().isResponseExpected();
02bb8761fcce Initial load
duke
parents:
diff changeset
   358
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   359
02bb8761fcce Initial load
duke
parents:
diff changeset
   360
    public short getAddrDisposition()
02bb8761fcce Initial load
duke
parents:
diff changeset
   361
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   362
        return addrDisposition;
02bb8761fcce Initial load
duke
parents:
diff changeset
   363
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   364
02bb8761fcce Initial load
duke
parents:
diff changeset
   365
    public String getOperationName()
02bb8761fcce Initial load
duke
parents:
diff changeset
   366
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   367
        return getRequestHeader().getOperation();
02bb8761fcce Initial load
duke
parents:
diff changeset
   368
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   369
02bb8761fcce Initial load
duke
parents:
diff changeset
   370
    public ServiceContexts getRequestServiceContexts()
02bb8761fcce Initial load
duke
parents:
diff changeset
   371
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   372
        return getRequestHeader().getServiceContexts();
02bb8761fcce Initial load
duke
parents:
diff changeset
   373
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   374
02bb8761fcce Initial load
duke
parents:
diff changeset
   375
    public ServiceContexts getReplyServiceContexts()
02bb8761fcce Initial load
duke
parents:
diff changeset
   376
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   377
        return getReplyHeader().getServiceContexts();
02bb8761fcce Initial load
duke
parents:
diff changeset
   378
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   379
02bb8761fcce Initial load
duke
parents:
diff changeset
   380
    public void sendCancelRequestIfFinalFragmentNotSent()
02bb8761fcce Initial load
duke
parents:
diff changeset
   381
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   382
        if ((!sentFullMessage()) && sentFragment() &&
02bb8761fcce Initial load
duke
parents:
diff changeset
   383
            (!cancelRequestAlreadySent))
02bb8761fcce Initial load
duke
parents:
diff changeset
   384
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
   385
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   386
                if (orb.subcontractDebugFlag) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   387
                    dprint(".sendCancelRequestIfFinalFragmentNotSent->: "
02bb8761fcce Initial load
duke
parents:
diff changeset
   388
                           + opAndId(this));
02bb8761fcce Initial load
duke
parents:
diff changeset
   389
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   390
                connection.sendCancelRequestWithLock(getGIOPVersion(),
02bb8761fcce Initial load
duke
parents:
diff changeset
   391
                                                     getRequestId());
02bb8761fcce Initial load
duke
parents:
diff changeset
   392
                // Case: first a location forward, then a marshaling
02bb8761fcce Initial load
duke
parents:
diff changeset
   393
                // exception (e.g., non-serializable object).  Only
02bb8761fcce Initial load
duke
parents:
diff changeset
   394
                // send cancel once.
02bb8761fcce Initial load
duke
parents:
diff changeset
   395
                cancelRequestAlreadySent = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   396
            } catch (IOException e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   397
                if (orb.subcontractDebugFlag) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   398
                    dprint(".sendCancelRequestIfFinalFragmentNotSent: !ERROR : " + opAndId(this),
02bb8761fcce Initial load
duke
parents:
diff changeset
   399
                           e);
02bb8761fcce Initial load
duke
parents:
diff changeset
   400
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   401
02bb8761fcce Initial load
duke
parents:
diff changeset
   402
                // REVISIT: we could attempt to send a final incomplete
02bb8761fcce Initial load
duke
parents:
diff changeset
   403
                // fragment in this case.
02bb8761fcce Initial load
duke
parents:
diff changeset
   404
                throw interceptorWrapper.ioexceptionDuringCancelRequest(
02bb8761fcce Initial load
duke
parents:
diff changeset
   405
                    CompletionStatus.COMPLETED_MAYBE, e );
02bb8761fcce Initial load
duke
parents:
diff changeset
   406
            } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
   407
                if (orb.subcontractDebugFlag) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   408
                    dprint(".sendCancelRequestIfFinalFragmentNotSent<-: "
02bb8761fcce Initial load
duke
parents:
diff changeset
   409
                           + opAndId(this));
02bb8761fcce Initial load
duke
parents:
diff changeset
   410
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   411
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   412
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   413
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   414
02bb8761fcce Initial load
duke
parents:
diff changeset
   415
    public boolean sentFullMessage()
02bb8761fcce Initial load
duke
parents:
diff changeset
   416
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   417
        return outputObject.getBufferManager().sentFullMessage();
02bb8761fcce Initial load
duke
parents:
diff changeset
   418
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   419
02bb8761fcce Initial load
duke
parents:
diff changeset
   420
    public boolean sentFragment()
02bb8761fcce Initial load
duke
parents:
diff changeset
   421
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   422
        return outputObject.getBufferManager().sentFragment();
02bb8761fcce Initial load
duke
parents:
diff changeset
   423
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   424
02bb8761fcce Initial load
duke
parents:
diff changeset
   425
    public void setDIIInfo(org.omg.CORBA.Request diiRequest)
02bb8761fcce Initial load
duke
parents:
diff changeset
   426
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   427
        this.diiRequest = diiRequest;
02bb8761fcce Initial load
duke
parents:
diff changeset
   428
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   429
02bb8761fcce Initial load
duke
parents:
diff changeset
   430
    public boolean isDIIRequest()
02bb8761fcce Initial load
duke
parents:
diff changeset
   431
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   432
        return diiRequest != null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   433
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   434
02bb8761fcce Initial load
duke
parents:
diff changeset
   435
    public Exception unmarshalDIIUserException(String repoId, InputStream is)
02bb8761fcce Initial load
duke
parents:
diff changeset
   436
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   437
        if (! isDIIRequest()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   438
            return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   439
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   440
02bb8761fcce Initial load
duke
parents:
diff changeset
   441
        ExceptionList _exceptions = diiRequest.exceptions();
02bb8761fcce Initial load
duke
parents:
diff changeset
   442
02bb8761fcce Initial load
duke
parents:
diff changeset
   443
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   444
            // Find the typecode for the exception
02bb8761fcce Initial load
duke
parents:
diff changeset
   445
            for (int i=0; i<_exceptions.count() ; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   446
                TypeCode tc = _exceptions.item(i);
02bb8761fcce Initial load
duke
parents:
diff changeset
   447
                if ( tc.id().equals(repoId) ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   448
                    // Since we dont have the actual user exception
02bb8761fcce Initial load
duke
parents:
diff changeset
   449
                    // class, the spec says we have to create an
02bb8761fcce Initial load
duke
parents:
diff changeset
   450
                    // UnknownUserException and put it in the
02bb8761fcce Initial load
duke
parents:
diff changeset
   451
                    // environment.
02bb8761fcce Initial load
duke
parents:
diff changeset
   452
                    Any eany = orb.create_any();
02bb8761fcce Initial load
duke
parents:
diff changeset
   453
                    eany.read_value(is, (TypeCode)tc);
02bb8761fcce Initial load
duke
parents:
diff changeset
   454
02bb8761fcce Initial load
duke
parents:
diff changeset
   455
                    return new UnknownUserException(eany);
02bb8761fcce Initial load
duke
parents:
diff changeset
   456
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   457
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   458
        } catch (Exception b) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   459
            throw wrapper.unexpectedDiiException(b);
02bb8761fcce Initial load
duke
parents:
diff changeset
   460
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   461
02bb8761fcce Initial load
duke
parents:
diff changeset
   462
        // must be a truly unknown exception
02bb8761fcce Initial load
duke
parents:
diff changeset
   463
        return wrapper.unknownCorbaExc( CompletionStatus.COMPLETED_MAYBE);
02bb8761fcce Initial load
duke
parents:
diff changeset
   464
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   465
02bb8761fcce Initial load
duke
parents:
diff changeset
   466
    public void setDIIException(Exception exception)
02bb8761fcce Initial load
duke
parents:
diff changeset
   467
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   468
        diiRequest.env().exception(exception);
02bb8761fcce Initial load
duke
parents:
diff changeset
   469
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   470
02bb8761fcce Initial load
duke
parents:
diff changeset
   471
    public void handleDIIReply(InputStream inputStream)
02bb8761fcce Initial load
duke
parents:
diff changeset
   472
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   473
        if (! isDIIRequest()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   474
            return;
02bb8761fcce Initial load
duke
parents:
diff changeset
   475
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   476
        ((RequestImpl)diiRequest).unmarshalReply(inputStream);
02bb8761fcce Initial load
duke
parents:
diff changeset
   477
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   478
02bb8761fcce Initial load
duke
parents:
diff changeset
   479
    public Message getDispatchHeader()
02bb8761fcce Initial load
duke
parents:
diff changeset
   480
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   481
        return dispatchHeader;
02bb8761fcce Initial load
duke
parents:
diff changeset
   482
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   483
02bb8761fcce Initial load
duke
parents:
diff changeset
   484
    public void setDispatchHeader(Message msg)
02bb8761fcce Initial load
duke
parents:
diff changeset
   485
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   486
        dispatchHeader = msg;
02bb8761fcce Initial load
duke
parents:
diff changeset
   487
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   488
02bb8761fcce Initial load
duke
parents:
diff changeset
   489
    public ByteBuffer getDispatchBuffer()
02bb8761fcce Initial load
duke
parents:
diff changeset
   490
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   491
        return dispatchByteBuffer;
02bb8761fcce Initial load
duke
parents:
diff changeset
   492
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   493
02bb8761fcce Initial load
duke
parents:
diff changeset
   494
    public void setDispatchBuffer(ByteBuffer byteBuffer)
02bb8761fcce Initial load
duke
parents:
diff changeset
   495
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   496
        dispatchByteBuffer = byteBuffer;
02bb8761fcce Initial load
duke
parents:
diff changeset
   497
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   498
02bb8761fcce Initial load
duke
parents:
diff changeset
   499
    public int getThreadPoolToUse() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   500
        int poolToUse = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
   501
        Message msg = getDispatchHeader();
02bb8761fcce Initial load
duke
parents:
diff changeset
   502
        // A null msg should never happen. But, we'll be
02bb8761fcce Initial load
duke
parents:
diff changeset
   503
        // defensive just in case.
02bb8761fcce Initial load
duke
parents:
diff changeset
   504
        if (msg != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   505
            poolToUse = msg.getThreadPoolToUse();
02bb8761fcce Initial load
duke
parents:
diff changeset
   506
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   507
        return poolToUse;
02bb8761fcce Initial load
duke
parents:
diff changeset
   508
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   509
02bb8761fcce Initial load
duke
parents:
diff changeset
   510
    public byte getStreamFormatVersion()
02bb8761fcce Initial load
duke
parents:
diff changeset
   511
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   512
        // REVISIT: ContactInfo/Acceptor output object factories
02bb8761fcce Initial load
duke
parents:
diff changeset
   513
        // just use this.  Maybe need to distinguish:
02bb8761fcce Initial load
duke
parents:
diff changeset
   514
        //    createOutputObjectForRequest
02bb8761fcce Initial load
duke
parents:
diff changeset
   515
        //    createOutputObjectForReply
02bb8761fcce Initial load
duke
parents:
diff changeset
   516
        // then do getStreamFormatVersionForRequest/ForReply here.
02bb8761fcce Initial load
duke
parents:
diff changeset
   517
        if (streamFormatVersionSet) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   518
            return streamFormatVersion;
02bb8761fcce Initial load
duke
parents:
diff changeset
   519
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   520
        return getStreamFormatVersionForReply();
02bb8761fcce Initial load
duke
parents:
diff changeset
   521
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   522
02bb8761fcce Initial load
duke
parents:
diff changeset
   523
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   524
     * If the RMI-IIOP maximum stream format version service context
02bb8761fcce Initial load
duke
parents:
diff changeset
   525
     * is present, it indicates the maximum stream format version we
02bb8761fcce Initial load
duke
parents:
diff changeset
   526
     * could use for the reply.  If it isn't present, the default is
02bb8761fcce Initial load
duke
parents:
diff changeset
   527
     * 2 for GIOP 1.3 or greater, 1 for lower.
02bb8761fcce Initial load
duke
parents:
diff changeset
   528
     *
02bb8761fcce Initial load
duke
parents:
diff changeset
   529
     * This is only sent on requests.  Clients can find out the
02bb8761fcce Initial load
duke
parents:
diff changeset
   530
     * server's maximum by looking for a tagged component in the IOR.
02bb8761fcce Initial load
duke
parents:
diff changeset
   531
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   532
    public byte getStreamFormatVersionForReply() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   533
02bb8761fcce Initial load
duke
parents:
diff changeset
   534
        // NOTE: The request service contexts may indicate the max.
02bb8761fcce Initial load
duke
parents:
diff changeset
   535
        ServiceContexts svc = getRequestServiceContexts();
02bb8761fcce Initial load
duke
parents:
diff changeset
   536
02bb8761fcce Initial load
duke
parents:
diff changeset
   537
        MaxStreamFormatVersionServiceContext msfvsc
02bb8761fcce Initial load
duke
parents:
diff changeset
   538
            = (MaxStreamFormatVersionServiceContext)svc.get(
02bb8761fcce Initial load
duke
parents:
diff changeset
   539
                MaxStreamFormatVersionServiceContext.SERVICE_CONTEXT_ID);
02bb8761fcce Initial load
duke
parents:
diff changeset
   540
02bb8761fcce Initial load
duke
parents:
diff changeset
   541
        if (msfvsc != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   542
            byte localMaxVersion = ORBUtility.getMaxStreamFormatVersion();
02bb8761fcce Initial load
duke
parents:
diff changeset
   543
            byte remoteMaxVersion = msfvsc.getMaximumStreamFormatVersion();
02bb8761fcce Initial load
duke
parents:
diff changeset
   544
02bb8761fcce Initial load
duke
parents:
diff changeset
   545
            return (byte)Math.min(localMaxVersion, remoteMaxVersion);
02bb8761fcce Initial load
duke
parents:
diff changeset
   546
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   547
            // Defaults to 1 for GIOP 1.2 or less, 2 for
02bb8761fcce Initial load
duke
parents:
diff changeset
   548
            // GIOP 1.3 or higher.
02bb8761fcce Initial load
duke
parents:
diff changeset
   549
            if (getGIOPVersion().lessThan(GIOPVersion.V1_3))
02bb8761fcce Initial load
duke
parents:
diff changeset
   550
                return ORBConstants.STREAM_FORMAT_VERSION_1;
02bb8761fcce Initial load
duke
parents:
diff changeset
   551
            else
02bb8761fcce Initial load
duke
parents:
diff changeset
   552
                return ORBConstants.STREAM_FORMAT_VERSION_2;
02bb8761fcce Initial load
duke
parents:
diff changeset
   553
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   554
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   555
02bb8761fcce Initial load
duke
parents:
diff changeset
   556
    public boolean isSystemExceptionReply()
02bb8761fcce Initial load
duke
parents:
diff changeset
   557
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   558
        return replyHeader.getReplyStatus() == ReplyMessage.SYSTEM_EXCEPTION;
02bb8761fcce Initial load
duke
parents:
diff changeset
   559
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   560
02bb8761fcce Initial load
duke
parents:
diff changeset
   561
    public boolean isUserExceptionReply()
02bb8761fcce Initial load
duke
parents:
diff changeset
   562
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   563
        return replyHeader.getReplyStatus() == ReplyMessage.USER_EXCEPTION;
02bb8761fcce Initial load
duke
parents:
diff changeset
   564
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   565
02bb8761fcce Initial load
duke
parents:
diff changeset
   566
    public boolean isLocationForwardReply()
02bb8761fcce Initial load
duke
parents:
diff changeset
   567
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   568
        return ( (replyHeader.getReplyStatus() == ReplyMessage.LOCATION_FORWARD) ||
02bb8761fcce Initial load
duke
parents:
diff changeset
   569
                 (replyHeader.getReplyStatus() == ReplyMessage.LOCATION_FORWARD_PERM) );
02bb8761fcce Initial load
duke
parents:
diff changeset
   570
        //return replyHeader.getReplyStatus() == ReplyMessage.LOCATION_FORWARD;
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 boolean isDifferentAddrDispositionRequestedReply()
02bb8761fcce Initial load
duke
parents:
diff changeset
   574
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   575
        return replyHeader.getReplyStatus() == ReplyMessage.NEEDS_ADDRESSING_MODE;
02bb8761fcce Initial load
duke
parents:
diff changeset
   576
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   577
02bb8761fcce Initial load
duke
parents:
diff changeset
   578
    public short getAddrDispositionReply()
02bb8761fcce Initial load
duke
parents:
diff changeset
   579
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   580
        return replyHeader.getAddrDisposition();
02bb8761fcce Initial load
duke
parents:
diff changeset
   581
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   582
02bb8761fcce Initial load
duke
parents:
diff changeset
   583
    public IOR getForwardedIOR()
02bb8761fcce Initial load
duke
parents:
diff changeset
   584
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   585
        return replyHeader.getIOR();
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 SystemException getSystemExceptionReply()
02bb8761fcce Initial load
duke
parents:
diff changeset
   589
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   590
        return replyHeader.getSystemException(replyExceptionDetailMessage);
02bb8761fcce Initial load
duke
parents:
diff changeset
   591
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   592
02bb8761fcce Initial load
duke
parents:
diff changeset
   593
    ////////////////////////////////////////////////////
02bb8761fcce Initial load
duke
parents:
diff changeset
   594
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   595
    // Used by server side.
02bb8761fcce Initial load
duke
parents:
diff changeset
   596
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   597
02bb8761fcce Initial load
duke
parents:
diff changeset
   598
    public ObjectKey getObjectKey()
02bb8761fcce Initial load
duke
parents:
diff changeset
   599
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   600
        return getRequestHeader().getObjectKey();
02bb8761fcce Initial load
duke
parents:
diff changeset
   601
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   602
02bb8761fcce Initial load
duke
parents:
diff changeset
   603
    public void setProtocolHandler(CorbaProtocolHandler protocolHandler)
02bb8761fcce Initial load
duke
parents:
diff changeset
   604
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   605
        throw wrapper.methodShouldNotBeCalled() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   606
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   607
02bb8761fcce Initial load
duke
parents:
diff changeset
   608
    public CorbaProtocolHandler getProtocolHandler()
02bb8761fcce Initial load
duke
parents:
diff changeset
   609
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   610
        // REVISIT: should look up in orb registry.
02bb8761fcce Initial load
duke
parents:
diff changeset
   611
        return this;
02bb8761fcce Initial load
duke
parents:
diff changeset
   612
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   613
02bb8761fcce Initial load
duke
parents:
diff changeset
   614
    ////////////////////////////////////////////////////
02bb8761fcce Initial load
duke
parents:
diff changeset
   615
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   616
    // ResponseHandler
02bb8761fcce Initial load
duke
parents:
diff changeset
   617
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   618
02bb8761fcce Initial load
duke
parents:
diff changeset
   619
    public org.omg.CORBA.portable.OutputStream createReply()
02bb8761fcce Initial load
duke
parents:
diff changeset
   620
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   621
        // Note: relies on side-effect of setting mediator output field.
02bb8761fcce Initial load
duke
parents:
diff changeset
   622
        // REVISIT - cast - need interface
02bb8761fcce Initial load
duke
parents:
diff changeset
   623
        getProtocolHandler().createResponse(this, (ServiceContexts) null);
02bb8761fcce Initial load
duke
parents:
diff changeset
   624
        return (OutputStream) getOutputObject();
02bb8761fcce Initial load
duke
parents:
diff changeset
   625
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   626
02bb8761fcce Initial load
duke
parents:
diff changeset
   627
    public org.omg.CORBA.portable.OutputStream createExceptionReply()
02bb8761fcce Initial load
duke
parents:
diff changeset
   628
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   629
        // Note: relies on side-effect of setting mediator output field.
02bb8761fcce Initial load
duke
parents:
diff changeset
   630
        // REVISIT - cast - need interface
02bb8761fcce Initial load
duke
parents:
diff changeset
   631
        getProtocolHandler().createUserExceptionResponse(this, (ServiceContexts) null);
02bb8761fcce Initial load
duke
parents:
diff changeset
   632
        return (OutputStream) getOutputObject();
02bb8761fcce Initial load
duke
parents:
diff changeset
   633
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   634
02bb8761fcce Initial load
duke
parents:
diff changeset
   635
    public boolean executeReturnServantInResponseConstructor()
02bb8761fcce Initial load
duke
parents:
diff changeset
   636
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   637
        return _executeReturnServantInResponseConstructor;
02bb8761fcce Initial load
duke
parents:
diff changeset
   638
02bb8761fcce Initial load
duke
parents:
diff changeset
   639
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   640
02bb8761fcce Initial load
duke
parents:
diff changeset
   641
    public void setExecuteReturnServantInResponseConstructor(boolean b)
02bb8761fcce Initial load
duke
parents:
diff changeset
   642
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   643
        _executeReturnServantInResponseConstructor = b;
02bb8761fcce Initial load
duke
parents:
diff changeset
   644
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   645
02bb8761fcce Initial load
duke
parents:
diff changeset
   646
    public boolean executeRemoveThreadInfoInResponseConstructor()
02bb8761fcce Initial load
duke
parents:
diff changeset
   647
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   648
        return _executeRemoveThreadInfoInResponseConstructor;
02bb8761fcce Initial load
duke
parents:
diff changeset
   649
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   650
02bb8761fcce Initial load
duke
parents:
diff changeset
   651
    public void setExecuteRemoveThreadInfoInResponseConstructor(boolean b)
02bb8761fcce Initial load
duke
parents:
diff changeset
   652
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   653
        _executeRemoveThreadInfoInResponseConstructor = b;
02bb8761fcce Initial load
duke
parents:
diff changeset
   654
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   655
02bb8761fcce Initial load
duke
parents:
diff changeset
   656
    public boolean executePIInResponseConstructor()
02bb8761fcce Initial load
duke
parents:
diff changeset
   657
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   658
        return _executePIInResponseConstructor;
02bb8761fcce Initial load
duke
parents:
diff changeset
   659
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   660
02bb8761fcce Initial load
duke
parents:
diff changeset
   661
    public void setExecutePIInResponseConstructor( boolean b )
02bb8761fcce Initial load
duke
parents:
diff changeset
   662
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   663
        _executePIInResponseConstructor = b;
02bb8761fcce Initial load
duke
parents:
diff changeset
   664
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   665
02bb8761fcce Initial load
duke
parents:
diff changeset
   666
    private byte getStreamFormatVersionForThisRequest(IOR ior,
02bb8761fcce Initial load
duke
parents:
diff changeset
   667
                                                      GIOPVersion giopVersion)
02bb8761fcce Initial load
duke
parents:
diff changeset
   668
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   669
02bb8761fcce Initial load
duke
parents:
diff changeset
   670
        byte localMaxVersion
02bb8761fcce Initial load
duke
parents:
diff changeset
   671
            = ORBUtility.getMaxStreamFormatVersion();
02bb8761fcce Initial load
duke
parents:
diff changeset
   672
02bb8761fcce Initial load
duke
parents:
diff changeset
   673
        IOR effectiveTargetIOR =
02bb8761fcce Initial load
duke
parents:
diff changeset
   674
            ((CorbaContactInfo)this.contactInfo).getEffectiveTargetIOR();
02bb8761fcce Initial load
duke
parents:
diff changeset
   675
        IIOPProfileTemplate temp =
02bb8761fcce Initial load
duke
parents:
diff changeset
   676
            (IIOPProfileTemplate)effectiveTargetIOR.getProfile().getTaggedProfileTemplate();
02bb8761fcce Initial load
duke
parents:
diff changeset
   677
        Iterator iter = temp.iteratorById(TAG_RMI_CUSTOM_MAX_STREAM_FORMAT.value);
02bb8761fcce Initial load
duke
parents:
diff changeset
   678
        if (!iter.hasNext()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   679
            // Didn't have the max stream format version tagged
02bb8761fcce Initial load
duke
parents:
diff changeset
   680
            // component.
02bb8761fcce Initial load
duke
parents:
diff changeset
   681
            if (giopVersion.lessThan(GIOPVersion.V1_3))
02bb8761fcce Initial load
duke
parents:
diff changeset
   682
                return ORBConstants.STREAM_FORMAT_VERSION_1;
02bb8761fcce Initial load
duke
parents:
diff changeset
   683
            else
02bb8761fcce Initial load
duke
parents:
diff changeset
   684
                return ORBConstants.STREAM_FORMAT_VERSION_2;
02bb8761fcce Initial load
duke
parents:
diff changeset
   685
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   686
02bb8761fcce Initial load
duke
parents:
diff changeset
   687
        byte remoteMaxVersion
02bb8761fcce Initial load
duke
parents:
diff changeset
   688
            = ((MaxStreamFormatVersionComponent)iter.next()).getMaxStreamFormatVersion();
02bb8761fcce Initial load
duke
parents:
diff changeset
   689
02bb8761fcce Initial load
duke
parents:
diff changeset
   690
        return (byte)Math.min(localMaxVersion, remoteMaxVersion);
02bb8761fcce Initial load
duke
parents:
diff changeset
   691
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   692
02bb8761fcce Initial load
duke
parents:
diff changeset
   693
    ////////////////////////////////////////////////////////////////////////
02bb8761fcce Initial load
duke
parents:
diff changeset
   694
    ////////////////////////////////////////////////////////////////////////
02bb8761fcce Initial load
duke
parents:
diff changeset
   695
    ////////////////////////////////////////////////////////////////////////
02bb8761fcce Initial load
duke
parents:
diff changeset
   696
02bb8761fcce Initial load
duke
parents:
diff changeset
   697
    // REVISIT - This could be a separate implementation object looked
02bb8761fcce Initial load
duke
parents:
diff changeset
   698
    // up in a registry.  However it needs some state in the message
02bb8761fcce Initial load
duke
parents:
diff changeset
   699
    // mediator so combine for now.
02bb8761fcce Initial load
duke
parents:
diff changeset
   700
02bb8761fcce Initial load
duke
parents:
diff changeset
   701
02bb8761fcce Initial load
duke
parents:
diff changeset
   702
    protected boolean isThreadDone = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   703
02bb8761fcce Initial load
duke
parents:
diff changeset
   704
    ////////////////////////////////////////////////////
02bb8761fcce Initial load
duke
parents:
diff changeset
   705
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   706
    // pept.protocol.ProtocolHandler
02bb8761fcce Initial load
duke
parents:
diff changeset
   707
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   708
02bb8761fcce Initial load
duke
parents:
diff changeset
   709
    public boolean handleRequest(MessageMediator messageMediator)
02bb8761fcce Initial load
duke
parents:
diff changeset
   710
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   711
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   712
            dispatchHeader.callback(this);
02bb8761fcce Initial load
duke
parents:
diff changeset
   713
        } catch (IOException e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   714
            // REVISIT - this should be handled internally.
02bb8761fcce Initial load
duke
parents:
diff changeset
   715
            ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   716
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   717
        return isThreadDone;
02bb8761fcce Initial load
duke
parents:
diff changeset
   718
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   719
02bb8761fcce Initial load
duke
parents:
diff changeset
   720
    ////////////////////////////////////////////////////
02bb8761fcce Initial load
duke
parents:
diff changeset
   721
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   722
    // iiop.messages.MessageHandler
02bb8761fcce Initial load
duke
parents:
diff changeset
   723
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   724
02bb8761fcce Initial load
duke
parents:
diff changeset
   725
    private void setWorkThenPoolOrResumeSelect(Message header)
02bb8761fcce Initial load
duke
parents:
diff changeset
   726
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   727
        if (getConnection().getEventHandler().shouldUseSelectThreadToWait()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   728
            resumeSelect(header);
02bb8761fcce Initial load
duke
parents:
diff changeset
   729
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   730
            // Leader/Follower when using reader thread.
02bb8761fcce Initial load
duke
parents:
diff changeset
   731
            // When this thread is done working it will go back in pool.
02bb8761fcce Initial load
duke
parents:
diff changeset
   732
02bb8761fcce Initial load
duke
parents:
diff changeset
   733
            isThreadDone = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   734
02bb8761fcce Initial load
duke
parents:
diff changeset
   735
            // First unregister current registration.
02bb8761fcce Initial load
duke
parents:
diff changeset
   736
            orb.getTransportManager().getSelector(0)
02bb8761fcce Initial load
duke
parents:
diff changeset
   737
                .unregisterForEvent(getConnection().getEventHandler());
02bb8761fcce Initial load
duke
parents:
diff changeset
   738
            // Have another thread become the reader.
02bb8761fcce Initial load
duke
parents:
diff changeset
   739
            orb.getTransportManager().getSelector(0)
02bb8761fcce Initial load
duke
parents:
diff changeset
   740
                .registerForEvent(getConnection().getEventHandler());
02bb8761fcce Initial load
duke
parents:
diff changeset
   741
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   742
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   743
02bb8761fcce Initial load
duke
parents:
diff changeset
   744
    private void setWorkThenReadOrResumeSelect(Message header)
02bb8761fcce Initial load
duke
parents:
diff changeset
   745
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   746
        if (getConnection().getEventHandler().shouldUseSelectThreadToWait()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   747
            resumeSelect(header);
02bb8761fcce Initial load
duke
parents:
diff changeset
   748
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   749
            // When using reader thread then wen this thread is
02bb8761fcce Initial load
duke
parents:
diff changeset
   750
            // done working it will continue reading.
02bb8761fcce Initial load
duke
parents:
diff changeset
   751
            isThreadDone = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   752
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   753
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   754
02bb8761fcce Initial load
duke
parents:
diff changeset
   755
    private void resumeSelect(Message header)
02bb8761fcce Initial load
duke
parents:
diff changeset
   756
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   757
        // NOTE: VERY IMPORTANT:
02bb8761fcce Initial load
duke
parents:
diff changeset
   758
        // Only participate in select after getting to the point
02bb8761fcce Initial load
duke
parents:
diff changeset
   759
        // that proper serialization of fragments is ensured.
02bb8761fcce Initial load
duke
parents:
diff changeset
   760
02bb8761fcce Initial load
duke
parents:
diff changeset
   761
        if (transportDebug()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   762
            dprint(".resumeSelect:->");
02bb8761fcce Initial load
duke
parents:
diff changeset
   763
            // REVISIT: not-OO:
02bb8761fcce Initial load
duke
parents:
diff changeset
   764
            String requestId = "?";
02bb8761fcce Initial load
duke
parents:
diff changeset
   765
            if (header instanceof RequestMessage) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   766
                requestId =
02bb8761fcce Initial load
duke
parents:
diff changeset
   767
                    new Integer(((RequestMessage)header)
02bb8761fcce Initial load
duke
parents:
diff changeset
   768
                                .getRequestId()).toString();
02bb8761fcce Initial load
duke
parents:
diff changeset
   769
            } else if (header instanceof ReplyMessage) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   770
                requestId =
02bb8761fcce Initial load
duke
parents:
diff changeset
   771
                    new Integer(((ReplyMessage)header)
02bb8761fcce Initial load
duke
parents:
diff changeset
   772
                                .getRequestId()).toString();
02bb8761fcce Initial load
duke
parents:
diff changeset
   773
            } else if (header instanceof FragmentMessage_1_2) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   774
                requestId =
02bb8761fcce Initial load
duke
parents:
diff changeset
   775
                    new Integer(((FragmentMessage_1_2)header)
02bb8761fcce Initial load
duke
parents:
diff changeset
   776
                                .getRequestId()).toString();
02bb8761fcce Initial load
duke
parents:
diff changeset
   777
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   778
            dprint(".resumeSelect: id/"
02bb8761fcce Initial load
duke
parents:
diff changeset
   779
                   + requestId
02bb8761fcce Initial load
duke
parents:
diff changeset
   780
                   + " " + getConnection()
02bb8761fcce Initial load
duke
parents:
diff changeset
   781
                   );
02bb8761fcce Initial load
duke
parents:
diff changeset
   782
02bb8761fcce Initial load
duke
parents:
diff changeset
   783
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   784
02bb8761fcce Initial load
duke
parents:
diff changeset
   785
        // IMPORTANT: To avoid bug (4953599), we force the Thread that does the NIO select
02bb8761fcce Initial load
duke
parents:
diff changeset
   786
        // to also do the enable/disable of Ops using SelectionKey.interestOps(Ops of Interest).
02bb8761fcce Initial load
duke
parents:
diff changeset
   787
        // Otherwise, the SelectionKey.interestOps(Ops of Interest) may block indefinitely in
02bb8761fcce Initial load
duke
parents:
diff changeset
   788
        // this thread.
02bb8761fcce Initial load
duke
parents:
diff changeset
   789
        EventHandler eventHandler = getConnection().getEventHandler();
02bb8761fcce Initial load
duke
parents:
diff changeset
   790
        orb.getTransportManager().getSelector(0).registerInterestOps(eventHandler);
02bb8761fcce Initial load
duke
parents:
diff changeset
   791
02bb8761fcce Initial load
duke
parents:
diff changeset
   792
        if (transportDebug()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   793
            dprint(".resumeSelect:<-");
02bb8761fcce Initial load
duke
parents:
diff changeset
   794
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   795
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   796
02bb8761fcce Initial load
duke
parents:
diff changeset
   797
    private void setInputObject()
02bb8761fcce Initial load
duke
parents:
diff changeset
   798
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   799
        // REVISIT: refactor createInputObject (and createMessageMediator)
02bb8761fcce Initial load
duke
parents:
diff changeset
   800
        // into base PlugInFactory.  Get via connection (either ContactInfo
02bb8761fcce Initial load
duke
parents:
diff changeset
   801
        // or Acceptor).
02bb8761fcce Initial load
duke
parents:
diff changeset
   802
        if (getConnection().getContactInfo() != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   803
            inputObject = (CDRInputObject)
02bb8761fcce Initial load
duke
parents:
diff changeset
   804
                getConnection().getContactInfo()
02bb8761fcce Initial load
duke
parents:
diff changeset
   805
                .createInputObject(orb, this);
02bb8761fcce Initial load
duke
parents:
diff changeset
   806
        } else if (getConnection().getAcceptor() != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   807
            inputObject = (CDRInputObject)
02bb8761fcce Initial load
duke
parents:
diff changeset
   808
                getConnection().getAcceptor()
02bb8761fcce Initial load
duke
parents:
diff changeset
   809
                .createInputObject(orb, this);
02bb8761fcce Initial load
duke
parents:
diff changeset
   810
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   811
            throw new RuntimeException("CorbaMessageMediatorImpl.setInputObject");
02bb8761fcce Initial load
duke
parents:
diff changeset
   812
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   813
        inputObject.setMessageMediator(this);
02bb8761fcce Initial load
duke
parents:
diff changeset
   814
        setInputObject(inputObject);
02bb8761fcce Initial load
duke
parents:
diff changeset
   815
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   816
02bb8761fcce Initial load
duke
parents:
diff changeset
   817
    private void signalResponseReceived()
02bb8761fcce Initial load
duke
parents:
diff changeset
   818
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   819
        // This will end up using the MessageMediator associated with
02bb8761fcce Initial load
duke
parents:
diff changeset
   820
        // the original request instead of the current mediator (which
02bb8761fcce Initial load
duke
parents:
diff changeset
   821
        // need to be constructed to hold the dispatchBuffer and connection).
02bb8761fcce Initial load
duke
parents:
diff changeset
   822
        connection.getResponseWaitingRoom()
02bb8761fcce Initial load
duke
parents:
diff changeset
   823
            .responseReceived((InputObject)inputObject);
02bb8761fcce Initial load
duke
parents:
diff changeset
   824
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   825
02bb8761fcce Initial load
duke
parents:
diff changeset
   826
    // This handles message types for which we don't create classes.
02bb8761fcce Initial load
duke
parents:
diff changeset
   827
    public void handleInput(Message header) throws IOException
02bb8761fcce Initial load
duke
parents:
diff changeset
   828
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   829
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   830
            messageHeader = header;
02bb8761fcce Initial load
duke
parents:
diff changeset
   831
02bb8761fcce Initial load
duke
parents:
diff changeset
   832
            if (transportDebug())
02bb8761fcce Initial load
duke
parents:
diff changeset
   833
                dprint(".handleInput->: "
02bb8761fcce Initial load
duke
parents:
diff changeset
   834
                       + MessageBase.typeToString(header.getType()));
02bb8761fcce Initial load
duke
parents:
diff changeset
   835
02bb8761fcce Initial load
duke
parents:
diff changeset
   836
            setWorkThenReadOrResumeSelect(header);
02bb8761fcce Initial load
duke
parents:
diff changeset
   837
02bb8761fcce Initial load
duke
parents:
diff changeset
   838
            switch(header.getType())
02bb8761fcce Initial load
duke
parents:
diff changeset
   839
            {
02bb8761fcce Initial load
duke
parents:
diff changeset
   840
            case Message.GIOPCloseConnection:
02bb8761fcce Initial load
duke
parents:
diff changeset
   841
                if (transportDebug()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   842
                    dprint(".handleInput: CloseConnection: purging");
02bb8761fcce Initial load
duke
parents:
diff changeset
   843
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   844
                connection.purgeCalls(wrapper.connectionRebind(), true, false);
02bb8761fcce Initial load
duke
parents:
diff changeset
   845
                break;
02bb8761fcce Initial load
duke
parents:
diff changeset
   846
            case Message.GIOPMessageError:
02bb8761fcce Initial load
duke
parents:
diff changeset
   847
                if (transportDebug()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   848
                    dprint(".handleInput: MessageError: purging");
02bb8761fcce Initial load
duke
parents:
diff changeset
   849
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   850
                connection.purgeCalls(wrapper.recvMsgError(), true, false);
02bb8761fcce Initial load
duke
parents:
diff changeset
   851
                break;
02bb8761fcce Initial load
duke
parents:
diff changeset
   852
            default:
02bb8761fcce Initial load
duke
parents:
diff changeset
   853
                if (transportDebug()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   854
                    dprint(".handleInput: ERROR: "
02bb8761fcce Initial load
duke
parents:
diff changeset
   855
                           + MessageBase.typeToString(header.getType()));
02bb8761fcce Initial load
duke
parents:
diff changeset
   856
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   857
                throw wrapper.badGiopRequestType() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   858
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   859
            releaseByteBufferToPool();
02bb8761fcce Initial load
duke
parents:
diff changeset
   860
        } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
   861
            if (transportDebug()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   862
                dprint(".handleInput<-: "
02bb8761fcce Initial load
duke
parents:
diff changeset
   863
                       + MessageBase.typeToString(header.getType()));
02bb8761fcce Initial load
duke
parents:
diff changeset
   864
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   865
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   866
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   867
02bb8761fcce Initial load
duke
parents:
diff changeset
   868
    public void handleInput(RequestMessage_1_0 header) throws IOException
02bb8761fcce Initial load
duke
parents:
diff changeset
   869
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   870
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   871
            if (transportDebug()) dprint(".REQUEST 1.0->: " + header);
02bb8761fcce Initial load
duke
parents:
diff changeset
   872
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   873
                messageHeader = requestHeader = (RequestMessage) header;
02bb8761fcce Initial load
duke
parents:
diff changeset
   874
                setInputObject();
02bb8761fcce Initial load
duke
parents:
diff changeset
   875
            } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
   876
                setWorkThenPoolOrResumeSelect(header);
02bb8761fcce Initial load
duke
parents:
diff changeset
   877
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   878
            getProtocolHandler().handleRequest(header, this);
02bb8761fcce Initial load
duke
parents:
diff changeset
   879
        } catch (Throwable t) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   880
            if (transportDebug())
02bb8761fcce Initial load
duke
parents:
diff changeset
   881
                dprint(".REQUEST 1.0: !!ERROR!!: " + header, t);
02bb8761fcce Initial load
duke
parents:
diff changeset
   882
            // Mask the exception from thread.;
02bb8761fcce Initial load
duke
parents:
diff changeset
   883
        } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
   884
            if (transportDebug()) dprint(".REQUEST 1.0<-: " + header);
02bb8761fcce Initial load
duke
parents:
diff changeset
   885
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   886
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   887
02bb8761fcce Initial load
duke
parents:
diff changeset
   888
    public void handleInput(RequestMessage_1_1 header) throws IOException
02bb8761fcce Initial load
duke
parents:
diff changeset
   889
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   890
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   891
            if (transportDebug()) dprint(".REQUEST 1.1->: " + header);
02bb8761fcce Initial load
duke
parents:
diff changeset
   892
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   893
                messageHeader = requestHeader = (RequestMessage) header;
02bb8761fcce Initial load
duke
parents:
diff changeset
   894
                setInputObject();
02bb8761fcce Initial load
duke
parents:
diff changeset
   895
                connection.serverRequest_1_1_Put(this);
02bb8761fcce Initial load
duke
parents:
diff changeset
   896
            } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
   897
                setWorkThenPoolOrResumeSelect(header);
02bb8761fcce Initial load
duke
parents:
diff changeset
   898
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   899
            getProtocolHandler().handleRequest(header, this);
02bb8761fcce Initial load
duke
parents:
diff changeset
   900
        } catch (Throwable t) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   901
            if (transportDebug())
02bb8761fcce Initial load
duke
parents:
diff changeset
   902
                dprint(".REQUEST 1.1: !!ERROR!!: " + header, t);
02bb8761fcce Initial load
duke
parents:
diff changeset
   903
            // Mask the exception from thread.;
02bb8761fcce Initial load
duke
parents:
diff changeset
   904
        } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
   905
            if (transportDebug()) dprint(".REQUEST 1.1<-: " + header);
02bb8761fcce Initial load
duke
parents:
diff changeset
   906
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   907
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   908
02bb8761fcce Initial load
duke
parents:
diff changeset
   909
    // REVISIT: this is identical to 1_0 except for fragment part.
02bb8761fcce Initial load
duke
parents:
diff changeset
   910
    public void handleInput(RequestMessage_1_2 header) throws IOException
02bb8761fcce Initial load
duke
parents:
diff changeset
   911
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   912
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   913
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   914
02bb8761fcce Initial load
duke
parents:
diff changeset
   915
                messageHeader = requestHeader = (RequestMessage) header;
02bb8761fcce Initial load
duke
parents:
diff changeset
   916
02bb8761fcce Initial load
duke
parents:
diff changeset
   917
                header.unmarshalRequestID(dispatchByteBuffer);
02bb8761fcce Initial load
duke
parents:
diff changeset
   918
                setInputObject();
02bb8761fcce Initial load
duke
parents:
diff changeset
   919
02bb8761fcce Initial load
duke
parents:
diff changeset
   920
                if (transportDebug()) dprint(".REQUEST 1.2->: id/"
02bb8761fcce Initial load
duke
parents:
diff changeset
   921
                                             + header.getRequestId()
02bb8761fcce Initial load
duke
parents:
diff changeset
   922
                                             + ": "
02bb8761fcce Initial load
duke
parents:
diff changeset
   923
                                             + header);
02bb8761fcce Initial load
duke
parents:
diff changeset
   924
02bb8761fcce Initial load
duke
parents:
diff changeset
   925
                // NOTE: in the old code this used to be done conditionally:
02bb8761fcce Initial load
duke
parents:
diff changeset
   926
                // if (header.moreFragmentsToFollow()).
02bb8761fcce Initial load
duke
parents:
diff changeset
   927
                // Now we always put it in. We take it out when
02bb8761fcce Initial load
duke
parents:
diff changeset
   928
                // the response is done.
02bb8761fcce Initial load
duke
parents:
diff changeset
   929
                // This must happen now so if a header is fragmented the stream
02bb8761fcce Initial load
duke
parents:
diff changeset
   930
                // may be found.
02bb8761fcce Initial load
duke
parents:
diff changeset
   931
                connection.serverRequestMapPut(header.getRequestId(), this);
02bb8761fcce Initial load
duke
parents:
diff changeset
   932
            } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
   933
                // Leader/Follower.
02bb8761fcce Initial load
duke
parents:
diff changeset
   934
                // Note: This *MUST* come after putting stream in above map
02bb8761fcce Initial load
duke
parents:
diff changeset
   935
                // since the header may be fragmented and you do not want to
02bb8761fcce Initial load
duke
parents:
diff changeset
   936
                // start reading again until the map above is set.
02bb8761fcce Initial load
duke
parents:
diff changeset
   937
                setWorkThenPoolOrResumeSelect(header);
02bb8761fcce Initial load
duke
parents:
diff changeset
   938
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   939
            //inputObject.unmarshalHeader(); // done in subcontract.
02bb8761fcce Initial load
duke
parents:
diff changeset
   940
            getProtocolHandler().handleRequest(header, this);
02bb8761fcce Initial load
duke
parents:
diff changeset
   941
        } catch (Throwable t) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   942
            if (transportDebug()) dprint(".REQUEST 1.2: id/"
02bb8761fcce Initial load
duke
parents:
diff changeset
   943
                                         + header.getRequestId()
02bb8761fcce Initial load
duke
parents:
diff changeset
   944
                                         + ": !!ERROR!!: "
02bb8761fcce Initial load
duke
parents:
diff changeset
   945
                                         + header,
02bb8761fcce Initial load
duke
parents:
diff changeset
   946
                                         t);
02bb8761fcce Initial load
duke
parents:
diff changeset
   947
            // Mask the exception from thread.;
02bb8761fcce Initial load
duke
parents:
diff changeset
   948
        } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
   949
            connection.serverRequestMapRemove(header.getRequestId());
02bb8761fcce Initial load
duke
parents:
diff changeset
   950
02bb8761fcce Initial load
duke
parents:
diff changeset
   951
            if (transportDebug()) dprint(".REQUEST 1.2<-: id/"
02bb8761fcce Initial load
duke
parents:
diff changeset
   952
                                         + header.getRequestId()
02bb8761fcce Initial load
duke
parents:
diff changeset
   953
                                         + ": "
02bb8761fcce Initial load
duke
parents:
diff changeset
   954
                                         + header);
02bb8761fcce Initial load
duke
parents:
diff changeset
   955
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   956
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   957
02bb8761fcce Initial load
duke
parents:
diff changeset
   958
    public void handleInput(ReplyMessage_1_0 header) throws IOException
02bb8761fcce Initial load
duke
parents:
diff changeset
   959
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   960
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   961
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   962
                if (transportDebug()) dprint(".REPLY 1.0->: " + header);
02bb8761fcce Initial load
duke
parents:
diff changeset
   963
                messageHeader = replyHeader = (ReplyMessage) header;
02bb8761fcce Initial load
duke
parents:
diff changeset
   964
                setInputObject();
02bb8761fcce Initial load
duke
parents:
diff changeset
   965
02bb8761fcce Initial load
duke
parents:
diff changeset
   966
                // REVISIT: this should be done by waiting thread.
02bb8761fcce Initial load
duke
parents:
diff changeset
   967
                inputObject.unmarshalHeader();
02bb8761fcce Initial load
duke
parents:
diff changeset
   968
02bb8761fcce Initial load
duke
parents:
diff changeset
   969
                signalResponseReceived();
02bb8761fcce Initial load
duke
parents:
diff changeset
   970
            } finally{
02bb8761fcce Initial load
duke
parents:
diff changeset
   971
                setWorkThenReadOrResumeSelect(header);
02bb8761fcce Initial load
duke
parents:
diff changeset
   972
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   973
        } catch (Throwable t) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   974
            if (transportDebug())dprint(".REPLY 1.0: !!ERROR!!: " + header, t);
02bb8761fcce Initial load
duke
parents:
diff changeset
   975
            // Mask the exception from thread.;
02bb8761fcce Initial load
duke
parents:
diff changeset
   976
        } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
   977
            if (transportDebug()) dprint(".REPLY 1.0<-: " + header);
02bb8761fcce Initial load
duke
parents:
diff changeset
   978
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   979
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   980
02bb8761fcce Initial load
duke
parents:
diff changeset
   981
    public void handleInput(ReplyMessage_1_1 header) throws IOException
02bb8761fcce Initial load
duke
parents:
diff changeset
   982
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   983
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   984
            if (transportDebug()) dprint(".REPLY 1.1->: " + header);
02bb8761fcce Initial load
duke
parents:
diff changeset
   985
            messageHeader = replyHeader = (ReplyMessage) header;
02bb8761fcce Initial load
duke
parents:
diff changeset
   986
            setInputObject();
02bb8761fcce Initial load
duke
parents:
diff changeset
   987
02bb8761fcce Initial load
duke
parents:
diff changeset
   988
            if (header.moreFragmentsToFollow()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   989
02bb8761fcce Initial load
duke
parents:
diff changeset
   990
                // More fragments are coming to complete this reply, so keep
02bb8761fcce Initial load
duke
parents:
diff changeset
   991
                // a reference to the InputStream so we can add the fragments
02bb8761fcce Initial load
duke
parents:
diff changeset
   992
                connection.clientReply_1_1_Put(this);
02bb8761fcce Initial load
duke
parents:
diff changeset
   993
02bb8761fcce Initial load
duke
parents:
diff changeset
   994
                // In 1.1, we can't assume that we have the request ID in the
02bb8761fcce Initial load
duke
parents:
diff changeset
   995
                // first fragment.  Thus, another thread is used
02bb8761fcce Initial load
duke
parents:
diff changeset
   996
                // to be the reader while this thread unmarshals
02bb8761fcce Initial load
duke
parents:
diff changeset
   997
                // the extended header and wakes up the client thread.
02bb8761fcce Initial load
duke
parents:
diff changeset
   998
                setWorkThenPoolOrResumeSelect(header);
02bb8761fcce Initial load
duke
parents:
diff changeset
   999
02bb8761fcce Initial load
duke
parents:
diff changeset
  1000
                // REVISIT - error handling.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1001
                // This must be done now.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1002
                inputObject.unmarshalHeader();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1003
02bb8761fcce Initial load
duke
parents:
diff changeset
  1004
                signalResponseReceived();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1005
02bb8761fcce Initial load
duke
parents:
diff changeset
  1006
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1007
02bb8761fcce Initial load
duke
parents:
diff changeset
  1008
                // Not fragmented, therefore we know the request
02bb8761fcce Initial load
duke
parents:
diff changeset
  1009
                // ID is here.  Thus, we can unmarshal the extended header
02bb8761fcce Initial load
duke
parents:
diff changeset
  1010
                // and wake up the client thread without using a third
02bb8761fcce Initial load
duke
parents:
diff changeset
  1011
                // thread as above.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1012
02bb8761fcce Initial load
duke
parents:
diff changeset
  1013
                // REVISIT - error handling during unmarshal.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1014
                // This must be done now to get the request id.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1015
                inputObject.unmarshalHeader();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1016
02bb8761fcce Initial load
duke
parents:
diff changeset
  1017
                signalResponseReceived();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1018
02bb8761fcce Initial load
duke
parents:
diff changeset
  1019
                setWorkThenReadOrResumeSelect(header);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1020
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1021
        } catch (Throwable t) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1022
            if (transportDebug()) dprint(".REPLY 1.1: !!ERROR!!: " + header);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1023
            // Mask the exception from thread.;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1024
        } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1025
            if (transportDebug()) dprint(".REPLY 1.1<-: " + header);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1026
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1027
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1028
02bb8761fcce Initial load
duke
parents:
diff changeset
  1029
    public void handleInput(ReplyMessage_1_2 header) throws IOException
02bb8761fcce Initial load
duke
parents:
diff changeset
  1030
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1031
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1032
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1033
                messageHeader = replyHeader = (ReplyMessage) header;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1034
02bb8761fcce Initial load
duke
parents:
diff changeset
  1035
                // We know that the request ID is in the first fragment
02bb8761fcce Initial load
duke
parents:
diff changeset
  1036
                header.unmarshalRequestID(dispatchByteBuffer);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1037
02bb8761fcce Initial load
duke
parents:
diff changeset
  1038
                if (transportDebug()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1039
                    dprint(".REPLY 1.2->: id/"
02bb8761fcce Initial load
duke
parents:
diff changeset
  1040
                           + + header.getRequestId()
02bb8761fcce Initial load
duke
parents:
diff changeset
  1041
                           + ": more?: " + header.moreFragmentsToFollow()
02bb8761fcce Initial load
duke
parents:
diff changeset
  1042
                           + ": " + header);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1043
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1044
02bb8761fcce Initial load
duke
parents:
diff changeset
  1045
                setInputObject();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1046
02bb8761fcce Initial load
duke
parents:
diff changeset
  1047
                signalResponseReceived();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1048
            } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1049
                setWorkThenReadOrResumeSelect(header);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1050
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1051
        } catch (Throwable t) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1052
            if (transportDebug()) dprint(".REPLY 1.2: id/"
02bb8761fcce Initial load
duke
parents:
diff changeset
  1053
                                         + header.getRequestId()
02bb8761fcce Initial load
duke
parents:
diff changeset
  1054
                                         + ": !!ERROR!!: "
02bb8761fcce Initial load
duke
parents:
diff changeset
  1055
                                         + header, t);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1056
            // Mask the exception from thread.;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1057
        } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1058
            if (transportDebug()) dprint(".REPLY 1.2<-: id/"
02bb8761fcce Initial load
duke
parents:
diff changeset
  1059
                                         + header.getRequestId()
02bb8761fcce Initial load
duke
parents:
diff changeset
  1060
                                         + ": "
02bb8761fcce Initial load
duke
parents:
diff changeset
  1061
                                         + header);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1062
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1063
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1064
02bb8761fcce Initial load
duke
parents:
diff changeset
  1065
    public void handleInput(LocateRequestMessage_1_0 header) throws IOException
02bb8761fcce Initial load
duke
parents:
diff changeset
  1066
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1067
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1068
            if (transportDebug())
02bb8761fcce Initial load
duke
parents:
diff changeset
  1069
                dprint(".LOCATE_REQUEST 1.0->: " + header);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1070
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1071
                messageHeader = header;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1072
                setInputObject();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1073
            } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1074
                setWorkThenPoolOrResumeSelect(header);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1075
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1076
            getProtocolHandler().handleRequest(header, this);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1077
        } catch (Throwable t) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1078
            if (transportDebug())
02bb8761fcce Initial load
duke
parents:
diff changeset
  1079
                dprint(".LOCATE_REQUEST 1.0: !!ERROR!!: " + header, t);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1080
            // Mask the exception from thread.;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1081
        } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1082
            if (transportDebug())
02bb8761fcce Initial load
duke
parents:
diff changeset
  1083
                dprint(".LOCATE_REQUEST 1.0<-: " + header);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1084
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1085
02bb8761fcce Initial load
duke
parents:
diff changeset
  1086
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1087
02bb8761fcce Initial load
duke
parents:
diff changeset
  1088
    public void handleInput(LocateRequestMessage_1_1 header) throws IOException
02bb8761fcce Initial load
duke
parents:
diff changeset
  1089
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1090
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1091
            if (transportDebug())
02bb8761fcce Initial load
duke
parents:
diff changeset
  1092
                dprint(".LOCATE_REQUEST 1.1->: " + header);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1093
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1094
                messageHeader = header;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1095
                setInputObject();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1096
            } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1097
                setWorkThenPoolOrResumeSelect(header);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1098
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1099
            getProtocolHandler().handleRequest(header, this);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1100
        } catch (Throwable t) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1101
            if (transportDebug())
02bb8761fcce Initial load
duke
parents:
diff changeset
  1102
                dprint(".LOCATE_REQUEST 1.1: !!ERROR!!: " + header, t);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1103
            // Mask the exception from thread.;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1104
        } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1105
            if (transportDebug())
02bb8761fcce Initial load
duke
parents:
diff changeset
  1106
                dprint(".LOCATE_REQUEST 1.1<-:" + header);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1107
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1108
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1109
02bb8761fcce Initial load
duke
parents:
diff changeset
  1110
    public void handleInput(LocateRequestMessage_1_2 header) throws IOException
02bb8761fcce Initial load
duke
parents:
diff changeset
  1111
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1112
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1113
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1114
                messageHeader = header;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1115
02bb8761fcce Initial load
duke
parents:
diff changeset
  1116
                header.unmarshalRequestID(dispatchByteBuffer);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1117
                setInputObject();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1118
02bb8761fcce Initial load
duke
parents:
diff changeset
  1119
                if (transportDebug())
02bb8761fcce Initial load
duke
parents:
diff changeset
  1120
                    dprint(".LOCATE_REQUEST 1.2->: id/"
02bb8761fcce Initial load
duke
parents:
diff changeset
  1121
                           + header.getRequestId()
02bb8761fcce Initial load
duke
parents:
diff changeset
  1122
                           + ": "
02bb8761fcce Initial load
duke
parents:
diff changeset
  1123
                           + header);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1124
02bb8761fcce Initial load
duke
parents:
diff changeset
  1125
                if (header.moreFragmentsToFollow()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1126
                    connection.serverRequestMapPut(header.getRequestId(),this);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1127
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1128
            } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1129
                setWorkThenPoolOrResumeSelect(header);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1130
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1131
            getProtocolHandler().handleRequest(header, this);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1132
        } catch (Throwable t) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1133
            if (transportDebug())
02bb8761fcce Initial load
duke
parents:
diff changeset
  1134
                dprint(".LOCATE_REQUEST 1.2: id/"
02bb8761fcce Initial load
duke
parents:
diff changeset
  1135
                       + header.getRequestId()
02bb8761fcce Initial load
duke
parents:
diff changeset
  1136
                       + ": !!ERROR!!: "
02bb8761fcce Initial load
duke
parents:
diff changeset
  1137
                       + header, t);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1138
            // Mask the exception from thread.;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1139
        } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1140
            if (transportDebug())
02bb8761fcce Initial load
duke
parents:
diff changeset
  1141
                dprint(".LOCATE_REQUEST 1.2<-: id/"
02bb8761fcce Initial load
duke
parents:
diff changeset
  1142
                       + header.getRequestId()
02bb8761fcce Initial load
duke
parents:
diff changeset
  1143
                       + ": "
02bb8761fcce Initial load
duke
parents:
diff changeset
  1144
                       + header);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1145
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1146
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1147
02bb8761fcce Initial load
duke
parents:
diff changeset
  1148
    public void handleInput(LocateReplyMessage_1_0 header) throws IOException
02bb8761fcce Initial load
duke
parents:
diff changeset
  1149
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1150
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1151
            if (transportDebug())
02bb8761fcce Initial load
duke
parents:
diff changeset
  1152
                dprint(".LOCATE_REPLY 1.0->:" + header);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1153
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1154
                messageHeader = header;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1155
                setInputObject();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1156
                inputObject.unmarshalHeader(); // REVISIT Put in subcontract.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1157
                signalResponseReceived();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1158
            } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1159
                setWorkThenReadOrResumeSelect(header);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1160
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1161
        } catch (Throwable t) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1162
            if (transportDebug())
02bb8761fcce Initial load
duke
parents:
diff changeset
  1163
                dprint(".LOCATE_REPLY 1.0: !!ERROR!!: " + header, t);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1164
            // Mask the exception from thread.;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1165
        } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1166
            if (transportDebug())
02bb8761fcce Initial load
duke
parents:
diff changeset
  1167
                dprint(".LOCATE_REPLY 1.0<-: " + header);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1168
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1169
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1170
02bb8761fcce Initial load
duke
parents:
diff changeset
  1171
    public void handleInput(LocateReplyMessage_1_1 header) throws IOException
02bb8761fcce Initial load
duke
parents:
diff changeset
  1172
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1173
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1174
            if (transportDebug()) dprint(".LOCATE_REPLY 1.1->: " + header);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1175
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1176
                messageHeader = header;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1177
                setInputObject();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1178
                // Fragmented LocateReplies are not allowed in 1.1.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1179
                inputObject.unmarshalHeader();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1180
                signalResponseReceived();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1181
            } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1182
                setWorkThenReadOrResumeSelect(header);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1183
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1184
        } catch (Throwable t) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1185
            if (transportDebug())
02bb8761fcce Initial load
duke
parents:
diff changeset
  1186
                dprint(".LOCATE_REPLY 1.1: !!ERROR!!: " + header, t);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1187
            // Mask the exception from thread.;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1188
        } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1189
            if (transportDebug()) dprint(".LOCATE_REPLY 1.1<-: " + header);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1190
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1191
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1192
02bb8761fcce Initial load
duke
parents:
diff changeset
  1193
    public void handleInput(LocateReplyMessage_1_2 header) throws IOException
02bb8761fcce Initial load
duke
parents:
diff changeset
  1194
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1195
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1196
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1197
                messageHeader = header;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1198
02bb8761fcce Initial load
duke
parents:
diff changeset
  1199
                // No need to put in client reply map - already there.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1200
                header.unmarshalRequestID(dispatchByteBuffer);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1201
02bb8761fcce Initial load
duke
parents:
diff changeset
  1202
                setInputObject();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1203
02bb8761fcce Initial load
duke
parents:
diff changeset
  1204
                if (transportDebug()) dprint(".LOCATE_REPLY 1.2->: id/"
02bb8761fcce Initial load
duke
parents:
diff changeset
  1205
                                             + header.getRequestId()
02bb8761fcce Initial load
duke
parents:
diff changeset
  1206
                                             + ": "
02bb8761fcce Initial load
duke
parents:
diff changeset
  1207
                                             + header);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1208
02bb8761fcce Initial load
duke
parents:
diff changeset
  1209
                signalResponseReceived();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1210
            } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1211
                setWorkThenPoolOrResumeSelect(header); // REVISIT
02bb8761fcce Initial load
duke
parents:
diff changeset
  1212
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1213
        } catch (Throwable t) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1214
            if (transportDebug())
02bb8761fcce Initial load
duke
parents:
diff changeset
  1215
                dprint(".LOCATE_REPLY 1.2: id/"
02bb8761fcce Initial load
duke
parents:
diff changeset
  1216
                       + header.getRequestId()
02bb8761fcce Initial load
duke
parents:
diff changeset
  1217
                       + ": !!ERROR!!: "
02bb8761fcce Initial load
duke
parents:
diff changeset
  1218
                       + header, t);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1219
            // Mask the exception from thread.;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1220
        } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1221
            if (transportDebug()) dprint(".LOCATE_REPLY 1.2<-: id/"
02bb8761fcce Initial load
duke
parents:
diff changeset
  1222
                                         + header.getRequestId()
02bb8761fcce Initial load
duke
parents:
diff changeset
  1223
                                         + ": "
02bb8761fcce Initial load
duke
parents:
diff changeset
  1224
                                         + header);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1225
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1226
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1227
02bb8761fcce Initial load
duke
parents:
diff changeset
  1228
    public void handleInput(FragmentMessage_1_1 header) throws IOException
02bb8761fcce Initial load
duke
parents:
diff changeset
  1229
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1230
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1231
            if (transportDebug()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1232
                dprint(".FRAGMENT 1.1->: "
02bb8761fcce Initial load
duke
parents:
diff changeset
  1233
                       + "more?: " + header.moreFragmentsToFollow()
02bb8761fcce Initial load
duke
parents:
diff changeset
  1234
                       + ": " + header);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1235
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1236
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1237
                messageHeader = header;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1238
                MessageMediator mediator = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1239
                CDRInputObject inputObject = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1240
02bb8761fcce Initial load
duke
parents:
diff changeset
  1241
                if (connection.isServer()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1242
                    mediator = connection.serverRequest_1_1_Get();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1243
                } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1244
                    mediator = connection.clientReply_1_1_Get();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1245
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1246
                if (mediator != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1247
                    inputObject = (CDRInputObject) mediator.getInputObject();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1248
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1249
02bb8761fcce Initial load
duke
parents:
diff changeset
  1250
                // If no input stream available, then discard the fragment.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1251
                // This can happen:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1252
                // 1. if a fragment message is received prior to receiving
02bb8761fcce Initial load
duke
parents:
diff changeset
  1253
                //    the original request/reply message. Very unlikely.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1254
                // 2. if a fragment message is received after the
02bb8761fcce Initial load
duke
parents:
diff changeset
  1255
                //    reply has been sent (early replies)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1256
                // Note: In the case of early replies, the fragments received
02bb8761fcce Initial load
duke
parents:
diff changeset
  1257
                // during the request processing (which are never unmarshaled),
02bb8761fcce Initial load
duke
parents:
diff changeset
  1258
                // will eventually be discarded by the GC.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1259
                if (inputObject == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1260
                    if (transportDebug())
02bb8761fcce Initial load
duke
parents:
diff changeset
  1261
                        dprint(".FRAGMENT 1.1: ++++DISCARDING++++: " + header);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1262
                    // need to release dispatchByteBuffer to pool if
02bb8761fcce Initial load
duke
parents:
diff changeset
  1263
                    // we are discarding
02bb8761fcce Initial load
duke
parents:
diff changeset
  1264
                    releaseByteBufferToPool();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1265
                    return;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1266
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1267
02bb8761fcce Initial load
duke
parents:
diff changeset
  1268
                inputObject.getBufferManager()
02bb8761fcce Initial load
duke
parents:
diff changeset
  1269
                    .processFragment(dispatchByteBuffer, header);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1270
02bb8761fcce Initial load
duke
parents:
diff changeset
  1271
                if (! header.moreFragmentsToFollow()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1272
                    if (connection.isServer()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1273
                        connection.serverRequest_1_1_Remove();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1274
                    } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1275
                        connection.clientReply_1_1_Remove();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1276
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1277
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1278
            } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1279
                // NOTE: This *must* come after queing the fragment
02bb8761fcce Initial load
duke
parents:
diff changeset
  1280
                // when using the selector to ensure fragments stay in order.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1281
                setWorkThenReadOrResumeSelect(header);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1282
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1283
        } catch (Throwable t) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1284
            if (transportDebug())
02bb8761fcce Initial load
duke
parents:
diff changeset
  1285
                dprint(".FRAGMENT 1.1: !!ERROR!!: " + header, t);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1286
            // Mask the exception from thread.;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1287
        } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1288
            if (transportDebug()) dprint(".FRAGMENT 1.1<-: " + header);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1289
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1290
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1291
02bb8761fcce Initial load
duke
parents:
diff changeset
  1292
    public void handleInput(FragmentMessage_1_2 header) throws IOException
02bb8761fcce Initial load
duke
parents:
diff changeset
  1293
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1294
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1295
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1296
                messageHeader = header;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1297
02bb8761fcce Initial load
duke
parents:
diff changeset
  1298
                // Note:  We know it's a 1.2 fragment, we have the data, but
02bb8761fcce Initial load
duke
parents:
diff changeset
  1299
                // we need the IIOPInputStream instance to unmarshal the
02bb8761fcce Initial load
duke
parents:
diff changeset
  1300
                // request ID... but we need the request ID to get the
02bb8761fcce Initial load
duke
parents:
diff changeset
  1301
                // IIOPInputStream instance. So we peek at the raw bytes.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1302
02bb8761fcce Initial load
duke
parents:
diff changeset
  1303
                header.unmarshalRequestID(dispatchByteBuffer);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1304
02bb8761fcce Initial load
duke
parents:
diff changeset
  1305
                if (transportDebug()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1306
                    dprint(".FRAGMENT 1.2->: id/"
02bb8761fcce Initial load
duke
parents:
diff changeset
  1307
                           + header.getRequestId()
02bb8761fcce Initial load
duke
parents:
diff changeset
  1308
                           + ": more?: " + header.moreFragmentsToFollow()
02bb8761fcce Initial load
duke
parents:
diff changeset
  1309
                           + ": " + header);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1310
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1311
02bb8761fcce Initial load
duke
parents:
diff changeset
  1312
                MessageMediator mediator = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1313
                InputObject inputObject = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1314
02bb8761fcce Initial load
duke
parents:
diff changeset
  1315
                if (connection.isServer()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1316
                    mediator =
02bb8761fcce Initial load
duke
parents:
diff changeset
  1317
                        connection.serverRequestMapGet(header.getRequestId());
02bb8761fcce Initial load
duke
parents:
diff changeset
  1318
                } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1319
                    mediator =
02bb8761fcce Initial load
duke
parents:
diff changeset
  1320
                        connection.clientRequestMapGet(header.getRequestId());
02bb8761fcce Initial load
duke
parents:
diff changeset
  1321
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1322
                if (mediator != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1323
                    inputObject = mediator.getInputObject();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1324
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1325
                // See 1.1 comments.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1326
                if (inputObject == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1327
                    if (transportDebug()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1328
                        dprint(".FRAGMENT 1.2: id/"
02bb8761fcce Initial load
duke
parents:
diff changeset
  1329
                               + header.getRequestId()
02bb8761fcce Initial load
duke
parents:
diff changeset
  1330
                               + ": ++++DISCARDING++++: "
02bb8761fcce Initial load
duke
parents:
diff changeset
  1331
                               + header);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1332
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1333
                    // need to release dispatchByteBuffer to pool if
02bb8761fcce Initial load
duke
parents:
diff changeset
  1334
                    // we are discarding
02bb8761fcce Initial load
duke
parents:
diff changeset
  1335
                    releaseByteBufferToPool();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1336
                    return;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1337
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1338
                ((CDRInputObject)inputObject)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1339
                    .getBufferManager().processFragment(
02bb8761fcce Initial load
duke
parents:
diff changeset
  1340
                                     dispatchByteBuffer, header);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1341
02bb8761fcce Initial load
duke
parents:
diff changeset
  1342
                // REVISIT: but if it is a server don't you have to remove the
02bb8761fcce Initial load
duke
parents:
diff changeset
  1343
                // stream from the map?
02bb8761fcce Initial load
duke
parents:
diff changeset
  1344
                if (! connection.isServer()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1345
                    /* REVISIT
02bb8761fcce Initial load
duke
parents:
diff changeset
  1346
                     * No need to do anything.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1347
                     * Should we mark that last was received?
02bb8761fcce Initial load
duke
parents:
diff changeset
  1348
                     if (! header.moreFragmentsToFollow()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1349
                     // Last fragment.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1350
                     }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1351
                    */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1352
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1353
            } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1354
                // NOTE: This *must* come after queing the fragment
02bb8761fcce Initial load
duke
parents:
diff changeset
  1355
                // when using the selector to ensure fragments stay in order.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1356
                setWorkThenReadOrResumeSelect(header);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1357
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1358
        } catch (Throwable t) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1359
            if (transportDebug())
02bb8761fcce Initial load
duke
parents:
diff changeset
  1360
                dprint(".FRAGMENT 1.2: id/"
02bb8761fcce Initial load
duke
parents:
diff changeset
  1361
                       + header.getRequestId()
02bb8761fcce Initial load
duke
parents:
diff changeset
  1362
                       + ": !!ERROR!!: "
02bb8761fcce Initial load
duke
parents:
diff changeset
  1363
                       + header, t);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1364
            // Mask the exception from thread.;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1365
        } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1366
            if (transportDebug()) dprint(".FRAGMENT 1.2<-: id/"
02bb8761fcce Initial load
duke
parents:
diff changeset
  1367
                                         + header.getRequestId()
02bb8761fcce Initial load
duke
parents:
diff changeset
  1368
                                         + ": "
02bb8761fcce Initial load
duke
parents:
diff changeset
  1369
                                         + header);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1370
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1371
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1372
02bb8761fcce Initial load
duke
parents:
diff changeset
  1373
    public void handleInput(CancelRequestMessage header) throws IOException
02bb8761fcce Initial load
duke
parents:
diff changeset
  1374
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1375
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1376
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1377
                messageHeader = header;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1378
                setInputObject();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1379
02bb8761fcce Initial load
duke
parents:
diff changeset
  1380
                // REVISIT: Move these two to subcontract.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1381
                inputObject.unmarshalHeader();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1382
02bb8761fcce Initial load
duke
parents:
diff changeset
  1383
                if (transportDebug()) dprint(".CANCEL->: id/"
02bb8761fcce Initial load
duke
parents:
diff changeset
  1384
                                             + header.getRequestId() + ": "
02bb8761fcce Initial load
duke
parents:
diff changeset
  1385
                                             + header.getGIOPVersion() + ": "
02bb8761fcce Initial load
duke
parents:
diff changeset
  1386
                                             + header);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1387
02bb8761fcce Initial load
duke
parents:
diff changeset
  1388
                processCancelRequest(header.getRequestId());
02bb8761fcce Initial load
duke
parents:
diff changeset
  1389
                releaseByteBufferToPool();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1390
            } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1391
                setWorkThenReadOrResumeSelect(header);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1392
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1393
        } catch (Throwable t) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1394
            if (transportDebug()) dprint(".CANCEL: id/"
02bb8761fcce Initial load
duke
parents:
diff changeset
  1395
                                         + header.getRequestId()
02bb8761fcce Initial load
duke
parents:
diff changeset
  1396
                                         + ": !!ERROR!!: "
02bb8761fcce Initial load
duke
parents:
diff changeset
  1397
                                         + header, t);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1398
            // Mask the exception from thread.;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1399
        } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1400
            if (transportDebug()) dprint(".CANCEL<-: id/"
02bb8761fcce Initial load
duke
parents:
diff changeset
  1401
                                         + header.getRequestId() + ": "
02bb8761fcce Initial load
duke
parents:
diff changeset
  1402
                                         + header.getGIOPVersion() + ": "
02bb8761fcce Initial load
duke
parents:
diff changeset
  1403
                                         + header);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1404
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1405
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1406
02bb8761fcce Initial load
duke
parents:
diff changeset
  1407
    private void throwNotImplemented()
02bb8761fcce Initial load
duke
parents:
diff changeset
  1408
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1409
        isThreadDone = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1410
        throwNotImplemented("");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1411
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1412
02bb8761fcce Initial load
duke
parents:
diff changeset
  1413
    private void throwNotImplemented(String msg)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1414
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1415
        throw new RuntimeException("CorbaMessageMediatorImpl: not implemented " + msg);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1416
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1417
02bb8761fcce Initial load
duke
parents:
diff changeset
  1418
    private void dprint(String msg, Throwable t)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1419
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1420
        dprint(msg);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1421
        t.printStackTrace(System.out);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1422
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1423
02bb8761fcce Initial load
duke
parents:
diff changeset
  1424
    private void dprint(String msg)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1425
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1426
        ORBUtility.dprint("CorbaMessageMediatorImpl", msg);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1427
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1428
02bb8761fcce Initial load
duke
parents:
diff changeset
  1429
    protected String opAndId(CorbaMessageMediator mediator)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1430
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1431
        return ORBUtility.operationNameAndRequestId(mediator);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1432
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1433
02bb8761fcce Initial load
duke
parents:
diff changeset
  1434
    private boolean transportDebug()
02bb8761fcce Initial load
duke
parents:
diff changeset
  1435
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1436
        return orb.transportDebugFlag;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1437
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1438
02bb8761fcce Initial load
duke
parents:
diff changeset
  1439
    // REVISIT: move this to subcontract (but both client and server need it).
02bb8761fcce Initial load
duke
parents:
diff changeset
  1440
    private final void processCancelRequest(int cancelReqId) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1441
02bb8761fcce Initial load
duke
parents:
diff changeset
  1442
        // The GIOP version of CancelRequest does not matter, since
02bb8761fcce Initial load
duke
parents:
diff changeset
  1443
        // CancelRequest_1_0 could be sent to cancel a request which
02bb8761fcce Initial load
duke
parents:
diff changeset
  1444
        // has a different GIOP version.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1445
02bb8761fcce Initial load
duke
parents:
diff changeset
  1446
        /*
02bb8761fcce Initial load
duke
parents:
diff changeset
  1447
         * CancelRequest processing logic :
02bb8761fcce Initial load
duke
parents:
diff changeset
  1448
         *
02bb8761fcce Initial load
duke
parents:
diff changeset
  1449
         *  - find the request with matching requestId
02bb8761fcce Initial load
duke
parents:
diff changeset
  1450
         *
02bb8761fcce Initial load
duke
parents:
diff changeset
  1451
         *  - call cancelProcessing() in BufferManagerRead [BMR]
02bb8761fcce Initial load
duke
parents:
diff changeset
  1452
         *
02bb8761fcce Initial load
duke
parents:
diff changeset
  1453
         *  - the hope is that worker thread would call BMR.underflow()
02bb8761fcce Initial load
duke
parents:
diff changeset
  1454
         *    to wait for more fragments to come in. When BMR.underflow() is
02bb8761fcce Initial load
duke
parents:
diff changeset
  1455
         *    called, if a CancelRequest had already arrived,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1456
         *    the worker thread would throw ThreadDeath,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1457
         *    else the thread would wait to be notified of the
02bb8761fcce Initial load
duke
parents:
diff changeset
  1458
         *    arrival of a new fragment or CancelRequest. Upon notification,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1459
         *    the woken up thread would check to see if a CancelRequest had
02bb8761fcce Initial load
duke
parents:
diff changeset
  1460
         *    arrived and if so throw a ThreadDeath or it will continue to
02bb8761fcce Initial load
duke
parents:
diff changeset
  1461
         *    process the received fragment.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1462
         *
02bb8761fcce Initial load
duke
parents:
diff changeset
  1463
         *  - if all the fragments had been received prior to CancelRequest
02bb8761fcce Initial load
duke
parents:
diff changeset
  1464
         *    then the worker thread would never block in BMR.underflow().
02bb8761fcce Initial load
duke
parents:
diff changeset
  1465
         *    So, setting the abort flag in BMR has no effect. The request
02bb8761fcce Initial load
duke
parents:
diff changeset
  1466
         *    processing will complete normally.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1467
         *
02bb8761fcce Initial load
duke
parents:
diff changeset
  1468
         *  - in the case where the server has received enough fragments to
02bb8761fcce Initial load
duke
parents:
diff changeset
  1469
         *    start processing the request and the server sends out
02bb8761fcce Initial load
duke
parents:
diff changeset
  1470
         *    an early reply. In such a case if the CancelRequest arrives
02bb8761fcce Initial load
duke
parents:
diff changeset
  1471
         *    after the reply has been sent, it has no effect.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1472
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1473
02bb8761fcce Initial load
duke
parents:
diff changeset
  1474
        if (!connection.isServer()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1475
            return; // we do not support bi-directional giop yet, ignore.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1476
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1477
02bb8761fcce Initial load
duke
parents:
diff changeset
  1478
        // Try to get hold of the InputStream buffer.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1479
        // In the case of 1.0 requests there is no way to get hold of
02bb8761fcce Initial load
duke
parents:
diff changeset
  1480
        // InputStream. Try out the 1.1 and 1.2 cases.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1481
02bb8761fcce Initial load
duke
parents:
diff changeset
  1482
        // was the request 1.2 ?
02bb8761fcce Initial load
duke
parents:
diff changeset
  1483
        MessageMediator mediator = connection.serverRequestMapGet(cancelReqId);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1484
        int requestId ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1485
        if (mediator == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1486
            // was the request 1.1 ?
02bb8761fcce Initial load
duke
parents:
diff changeset
  1487
            mediator = connection.serverRequest_1_1_Get();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1488
            if (mediator == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1489
                // XXX log this!
02bb8761fcce Initial load
duke
parents:
diff changeset
  1490
                // either the request was 1.0
02bb8761fcce Initial load
duke
parents:
diff changeset
  1491
                // or an early reply has already been sent
02bb8761fcce Initial load
duke
parents:
diff changeset
  1492
                // or request processing is over
02bb8761fcce Initial load
duke
parents:
diff changeset
  1493
                // or its a spurious CancelRequest
02bb8761fcce Initial load
duke
parents:
diff changeset
  1494
                return; // do nothing.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1495
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1496
02bb8761fcce Initial load
duke
parents:
diff changeset
  1497
            requestId = ((CorbaMessageMediator) mediator).getRequestId();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1498
02bb8761fcce Initial load
duke
parents:
diff changeset
  1499
            if (requestId != cancelReqId) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1500
                // A spurious 1.1 CancelRequest has been received.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1501
                // XXX log this!
02bb8761fcce Initial load
duke
parents:
diff changeset
  1502
                return; // do nothing
02bb8761fcce Initial load
duke
parents:
diff changeset
  1503
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1504
02bb8761fcce Initial load
duke
parents:
diff changeset
  1505
            if (requestId == 0) { // special case
02bb8761fcce Initial load
duke
parents:
diff changeset
  1506
                // XXX log this
02bb8761fcce Initial load
duke
parents:
diff changeset
  1507
                // this means that
02bb8761fcce Initial load
duke
parents:
diff changeset
  1508
                // 1. the 1.1 requests' requestId has not been received
02bb8761fcce Initial load
duke
parents:
diff changeset
  1509
                //    i.e., a CancelRequest was received even before the
02bb8761fcce Initial load
duke
parents:
diff changeset
  1510
                //    1.1 request was received. The spec disallows this.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1511
                // 2. or the 1.1 request has a requestId 0.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1512
                //
02bb8761fcce Initial load
duke
parents:
diff changeset
  1513
                // It is a little tricky to distinguish these two. So, be
02bb8761fcce Initial load
duke
parents:
diff changeset
  1514
                // conservative and do not cancel the request. Downside is that
02bb8761fcce Initial load
duke
parents:
diff changeset
  1515
                // 1.1 requests with requestId of 0 will never be cancelled.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1516
                return; // do nothing
02bb8761fcce Initial load
duke
parents:
diff changeset
  1517
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1518
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1519
            requestId = ((CorbaMessageMediator) mediator).getRequestId();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1520
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1521
02bb8761fcce Initial load
duke
parents:
diff changeset
  1522
        Message msg = ((CorbaMessageMediator)mediator).getRequestHeader();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1523
        if (msg.getType() != Message.GIOPRequest) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1524
            // Any mediator obtained here should only ever be for a GIOP
02bb8761fcce Initial load
duke
parents:
diff changeset
  1525
            // request.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1526
            wrapper.badMessageTypeForCancel() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1527
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1528
02bb8761fcce Initial load
duke
parents:
diff changeset
  1529
        // At this point we have a valid message mediator that contains
02bb8761fcce Initial load
duke
parents:
diff changeset
  1530
        // a valid requestId.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1531
02bb8761fcce Initial load
duke
parents:
diff changeset
  1532
        // at this point we have chosen a request to be cancelled. But we
02bb8761fcce Initial load
duke
parents:
diff changeset
  1533
        // do not know if the target object's method has been invoked or not.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1534
        // Request input stream being available simply means that the request
02bb8761fcce Initial load
duke
parents:
diff changeset
  1535
        // processing is not over yet. simply set the abort flag in the
02bb8761fcce Initial load
duke
parents:
diff changeset
  1536
        // BMRS and hope that the worker thread would notice it (this can
02bb8761fcce Initial load
duke
parents:
diff changeset
  1537
        // happen only if the request stream is being unmarshalled and the
02bb8761fcce Initial load
duke
parents:
diff changeset
  1538
        // target's method has not been invoked yet). This guarantees
02bb8761fcce Initial load
duke
parents:
diff changeset
  1539
        // that the requests which have been dispatched to the
02bb8761fcce Initial load
duke
parents:
diff changeset
  1540
        // target's method will never be cancelled.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1541
02bb8761fcce Initial load
duke
parents:
diff changeset
  1542
        BufferManagerReadStream bufferManager = (BufferManagerReadStream)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1543
            ((CDRInputObject)mediator.getInputObject()).getBufferManager();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1544
        bufferManager.cancelProcessing(cancelReqId);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1545
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1546
02bb8761fcce Initial load
duke
parents:
diff changeset
  1547
    ////////////////////////////////////////////////////
02bb8761fcce Initial load
duke
parents:
diff changeset
  1548
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
  1549
    // spi.protocol.CorbaProtocolHandler
02bb8761fcce Initial load
duke
parents:
diff changeset
  1550
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
  1551
02bb8761fcce Initial load
duke
parents:
diff changeset
  1552
    public void handleRequest(RequestMessage msg,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1553
                              CorbaMessageMediator messageMediator)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1554
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1555
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1556
            beginRequest(messageMediator);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1557
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1558
                handleRequestRequest(messageMediator);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1559
                if (messageMediator.isOneWay()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1560
                    return;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1561
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1562
            } catch (Throwable t) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1563
                if (messageMediator.isOneWay()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1564
                    return;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1565
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1566
                handleThrowableDuringServerDispatch(
02bb8761fcce Initial load
duke
parents:
diff changeset
  1567
                    messageMediator, t, CompletionStatus.COMPLETED_MAYBE);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1568
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1569
            sendResponse(messageMediator);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1570
        } catch (Throwable t) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1571
            dispatchError(messageMediator, "RequestMessage", t);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1572
        } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1573
            endRequest(messageMediator);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1574
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1575
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1576
02bb8761fcce Initial load
duke
parents:
diff changeset
  1577
    public void handleRequest(LocateRequestMessage msg,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1578
                              CorbaMessageMediator messageMediator)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1579
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1580
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1581
            beginRequest(messageMediator);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1582
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1583
                handleLocateRequest(messageMediator);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1584
            } catch (Throwable t) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1585
                handleThrowableDuringServerDispatch(
02bb8761fcce Initial load
duke
parents:
diff changeset
  1586
                    messageMediator, t, CompletionStatus.COMPLETED_MAYBE);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1587
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1588
            sendResponse(messageMediator);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1589
        } catch (Throwable t) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1590
            dispatchError(messageMediator, "LocateRequestMessage", t);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1591
        } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1592
            endRequest(messageMediator);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1593
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1594
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1595
02bb8761fcce Initial load
duke
parents:
diff changeset
  1596
    private void beginRequest(CorbaMessageMediator messageMediator)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1597
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1598
        ORB orb = (ORB) messageMediator.getBroker();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1599
        if (orb.subcontractDebugFlag) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1600
            dprint(".handleRequest->:");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1601
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1602
        connection.serverRequestProcessingBegins();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1603
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1604
02bb8761fcce Initial load
duke
parents:
diff changeset
  1605
    private void dispatchError(CorbaMessageMediator messageMediator,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1606
                               String msg, Throwable t)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1607
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1608
        if (orb.subcontractDebugFlag) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1609
            dprint(".handleRequest: " + opAndId(messageMediator)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1610
                   + ": !!ERROR!!: "
02bb8761fcce Initial load
duke
parents:
diff changeset
  1611
                   + msg,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1612
                   t);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1613
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1614
        // REVISIT - this makes hcks sendTwoObjects fail
02bb8761fcce Initial load
duke
parents:
diff changeset
  1615
        // messageMediator.getConnection().close();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1616
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1617
02bb8761fcce Initial load
duke
parents:
diff changeset
  1618
    private void sendResponse(CorbaMessageMediator messageMediator)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1619
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1620
        if (orb.subcontractDebugFlag) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1621
            dprint(".handleRequest: " + opAndId(messageMediator)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1622
                   + ": sending response");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1623
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1624
        // REVISIT - type and location
02bb8761fcce Initial load
duke
parents:
diff changeset
  1625
        CDROutputObject outputObject = (CDROutputObject)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1626
            messageMediator.getOutputObject();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1627
        if (outputObject != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1628
            // REVISIT - can be null for TRANSIENT below.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1629
            outputObject.finishSendingMessage();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1630
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1631
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1632
02bb8761fcce Initial load
duke
parents:
diff changeset
  1633
    private void endRequest(CorbaMessageMediator messageMediator)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1634
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1635
        ORB orb = (ORB) messageMediator.getBroker();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1636
        if (orb.subcontractDebugFlag) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1637
            dprint(".handleRequest<-: " + opAndId(messageMediator));
02bb8761fcce Initial load
duke
parents:
diff changeset
  1638
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1639
02bb8761fcce Initial load
duke
parents:
diff changeset
  1640
        // release NIO ByteBuffers to ByteBufferPool
02bb8761fcce Initial load
duke
parents:
diff changeset
  1641
02bb8761fcce Initial load
duke
parents:
diff changeset
  1642
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1643
            OutputObject outputObj = messageMediator.getOutputObject();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1644
            if (outputObj != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1645
                outputObj.close();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1646
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1647
            InputObject inputObj = messageMediator.getInputObject();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1648
            if (inputObj != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1649
                inputObj.close();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1650
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1651
        } catch (IOException ex) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1652
            // Given what close() does, this catch shouldn't ever happen.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1653
            // See CDRInput/OutputObject.close() for more info.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1654
            // It also won't result in a Corba error if an IOException happens.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1655
            if (orb.subcontractDebugFlag) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1656
                dprint(".endRequest: IOException:" + ex.getMessage(), ex);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1657
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1658
        } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1659
            ((CorbaConnection)messageMediator.getConnection()).serverRequestProcessingEnds();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1660
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1661
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1662
02bb8761fcce Initial load
duke
parents:
diff changeset
  1663
    protected void handleRequestRequest(CorbaMessageMediator messageMediator)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1664
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1665
        // Does nothing if already unmarshaled.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1666
        ((CDRInputObject)messageMediator.getInputObject()).unmarshalHeader();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1667
02bb8761fcce Initial load
duke
parents:
diff changeset
  1668
        ORB orb = (ORB)messageMediator.getBroker();
13171
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
  1669
        synchronized (orb) {
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
  1670
            orb.checkShutdownState();
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
  1671
        }
4
02bb8761fcce Initial load
duke
parents:
diff changeset
  1672
02bb8761fcce Initial load
duke
parents:
diff changeset
  1673
        ObjectKey okey = messageMediator.getObjectKey();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1674
        if (orb.subcontractDebugFlag) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1675
            ObjectKeyTemplate oktemp = okey.getTemplate() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1676
            dprint( ".handleRequest: " + opAndId(messageMediator)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1677
                    + ": dispatching to scid: " + oktemp.getSubcontractId());
02bb8761fcce Initial load
duke
parents:
diff changeset
  1678
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1679
02bb8761fcce Initial load
duke
parents:
diff changeset
  1680
        CorbaServerRequestDispatcher sc = okey.getServerRequestDispatcher(orb);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1681
02bb8761fcce Initial load
duke
parents:
diff changeset
  1682
        if (orb.subcontractDebugFlag) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1683
            dprint(".handleRequest: " + opAndId(messageMediator)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1684
                   + ": dispatching to sc: " + sc);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1685
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1686
02bb8761fcce Initial load
duke
parents:
diff changeset
  1687
        if (sc == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1688
            throw wrapper.noServerScInDispatch() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1689
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1690
02bb8761fcce Initial load
duke
parents:
diff changeset
  1691
        // NOTE:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1692
        // This is necessary so mediator can act as ResponseHandler
02bb8761fcce Initial load
duke
parents:
diff changeset
  1693
        // and pass necessary info to response constructors located
02bb8761fcce Initial load
duke
parents:
diff changeset
  1694
        // in the subcontract.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1695
        // REVISIT - same class right now.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1696
        //messageMediator.setProtocolHandler(this);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1697
02bb8761fcce Initial load
duke
parents:
diff changeset
  1698
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1699
            orb.startingDispatch();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1700
            sc.dispatch(messageMediator);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1701
        } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1702
            orb.finishedDispatch();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1703
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1704
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1705
02bb8761fcce Initial load
duke
parents:
diff changeset
  1706
    protected void handleLocateRequest(CorbaMessageMediator messageMediator)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1707
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1708
        ORB orb = (ORB)messageMediator.getBroker();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1709
        LocateRequestMessage msg = (LocateRequestMessage)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1710
            messageMediator.getDispatchHeader();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1711
        IOR ior = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1712
        LocateReplyMessage reply = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1713
        short addrDisp = -1;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1714
02bb8761fcce Initial load
duke
parents:
diff changeset
  1715
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1716
            ((CDRInputObject)messageMediator.getInputObject()).unmarshalHeader();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1717
            CorbaServerRequestDispatcher sc =
02bb8761fcce Initial load
duke
parents:
diff changeset
  1718
                msg.getObjectKey().getServerRequestDispatcher( orb ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1719
            if (sc == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1720
                return;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1721
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1722
02bb8761fcce Initial load
duke
parents:
diff changeset
  1723
            ior = sc.locate(msg.getObjectKey());
02bb8761fcce Initial load
duke
parents:
diff changeset
  1724
02bb8761fcce Initial load
duke
parents:
diff changeset
  1725
            if ( ior == null ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1726
                reply = MessageBase.createLocateReply(
02bb8761fcce Initial load
duke
parents:
diff changeset
  1727
                            orb, msg.getGIOPVersion(),
02bb8761fcce Initial load
duke
parents:
diff changeset
  1728
                            msg.getEncodingVersion(),
02bb8761fcce Initial load
duke
parents:
diff changeset
  1729
                            msg.getRequestId(),
02bb8761fcce Initial load
duke
parents:
diff changeset
  1730
                            LocateReplyMessage.OBJECT_HERE, null);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1731
02bb8761fcce Initial load
duke
parents:
diff changeset
  1732
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1733
                reply = MessageBase.createLocateReply(
02bb8761fcce Initial load
duke
parents:
diff changeset
  1734
                            orb, msg.getGIOPVersion(),
02bb8761fcce Initial load
duke
parents:
diff changeset
  1735
                            msg.getEncodingVersion(),
02bb8761fcce Initial load
duke
parents:
diff changeset
  1736
                            msg.getRequestId(),
02bb8761fcce Initial load
duke
parents:
diff changeset
  1737
                            LocateReplyMessage.OBJECT_FORWARD, ior);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1738
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1739
            // REVISIT: Should we catch SystemExceptions?
02bb8761fcce Initial load
duke
parents:
diff changeset
  1740
02bb8761fcce Initial load
duke
parents:
diff changeset
  1741
        } catch (AddressingDispositionException ex) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1742
02bb8761fcce Initial load
duke
parents:
diff changeset
  1743
            // create a response containing the expected target
02bb8761fcce Initial load
duke
parents:
diff changeset
  1744
            // addressing disposition.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1745
02bb8761fcce Initial load
duke
parents:
diff changeset
  1746
            reply = MessageBase.createLocateReply(
02bb8761fcce Initial load
duke
parents:
diff changeset
  1747
                        orb, msg.getGIOPVersion(),
02bb8761fcce Initial load
duke
parents:
diff changeset
  1748
                        msg.getEncodingVersion(),
02bb8761fcce Initial load
duke
parents:
diff changeset
  1749
                        msg.getRequestId(),
02bb8761fcce Initial load
duke
parents:
diff changeset
  1750
                        LocateReplyMessage.LOC_NEEDS_ADDRESSING_MODE, null);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1751
02bb8761fcce Initial load
duke
parents:
diff changeset
  1752
            addrDisp = ex.expectedAddrDisp();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1753
02bb8761fcce Initial load
duke
parents:
diff changeset
  1754
        } catch (RequestCanceledException ex) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1755
02bb8761fcce Initial load
duke
parents:
diff changeset
  1756
            return; // no need to send reply
02bb8761fcce Initial load
duke
parents:
diff changeset
  1757
02bb8761fcce Initial load
duke
parents:
diff changeset
  1758
        } catch ( Exception ex ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1759
02bb8761fcce Initial load
duke
parents:
diff changeset
  1760
            // REVISIT If exception is not OBJECT_NOT_EXIST, it should
02bb8761fcce Initial load
duke
parents:
diff changeset
  1761
            // have a different reply
02bb8761fcce Initial load
duke
parents:
diff changeset
  1762
02bb8761fcce Initial load
duke
parents:
diff changeset
  1763
            // This handles OBJECT_NOT_EXIST exceptions thrown in
02bb8761fcce Initial load
duke
parents:
diff changeset
  1764
            // the subcontract or obj manager. Send back UNKNOWN_OBJECT.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1765
02bb8761fcce Initial load
duke
parents:
diff changeset
  1766
            reply = MessageBase.createLocateReply(
02bb8761fcce Initial load
duke
parents:
diff changeset
  1767
                        orb, msg.getGIOPVersion(),
02bb8761fcce Initial load
duke
parents:
diff changeset
  1768
                        msg.getEncodingVersion(),
02bb8761fcce Initial load
duke
parents:
diff changeset
  1769
                        msg.getRequestId(),
02bb8761fcce Initial load
duke
parents:
diff changeset
  1770
                        LocateReplyMessage.UNKNOWN_OBJECT, null);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1771
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1772
02bb8761fcce Initial load
duke
parents:
diff changeset
  1773
        CDROutputObject outputObject =
02bb8761fcce Initial load
duke
parents:
diff changeset
  1774
            createAppropriateOutputObject(messageMediator,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1775
                                          msg, reply);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1776
        messageMediator.setOutputObject(outputObject);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1777
        outputObject.setMessageMediator(messageMediator);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1778
02bb8761fcce Initial load
duke
parents:
diff changeset
  1779
        reply.write(outputObject);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1780
        // outputObject.setMessage(reply); // REVISIT - not necessary
02bb8761fcce Initial load
duke
parents:
diff changeset
  1781
        if (ior != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1782
            ior.write(outputObject);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1783
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1784
        if (addrDisp != -1) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1785
            AddressingDispositionHelper.write(outputObject, addrDisp);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1786
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1787
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1788
02bb8761fcce Initial load
duke
parents:
diff changeset
  1789
    private CDROutputObject createAppropriateOutputObject(
02bb8761fcce Initial load
duke
parents:
diff changeset
  1790
        CorbaMessageMediator messageMediator,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1791
        Message msg, LocateReplyMessage reply)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1792
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1793
        CDROutputObject outputObject;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1794
02bb8761fcce Initial load
duke
parents:
diff changeset
  1795
        if (msg.getGIOPVersion().lessThan(GIOPVersion.V1_2)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1796
            // locate msgs 1.0 & 1.1 :=> grow,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1797
            // REVISIT - build from factory
02bb8761fcce Initial load
duke
parents:
diff changeset
  1798
            outputObject = new CDROutputObject(
02bb8761fcce Initial load
duke
parents:
diff changeset
  1799
                             (ORB) messageMediator.getBroker(),
02bb8761fcce Initial load
duke
parents:
diff changeset
  1800
                             this,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1801
                             GIOPVersion.V1_0,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1802
                             (CorbaConnection) messageMediator.getConnection(),
02bb8761fcce Initial load
duke
parents:
diff changeset
  1803
                             reply,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1804
                             ORBConstants.STREAM_FORMAT_VERSION_1);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1805
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1806
            // 1.2 :=> stream
02bb8761fcce Initial load
duke
parents:
diff changeset
  1807
            // REVISIT - build from factory
02bb8761fcce Initial load
duke
parents:
diff changeset
  1808
            outputObject = new CDROutputObject(
02bb8761fcce Initial load
duke
parents:
diff changeset
  1809
                             (ORB) messageMediator.getBroker(),
02bb8761fcce Initial load
duke
parents:
diff changeset
  1810
                             messageMediator,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1811
                             reply,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1812
                             ORBConstants.STREAM_FORMAT_VERSION_1);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1813
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1814
        return outputObject;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1815
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1816
02bb8761fcce Initial load
duke
parents:
diff changeset
  1817
    public void handleThrowableDuringServerDispatch(
02bb8761fcce Initial load
duke
parents:
diff changeset
  1818
        CorbaMessageMediator messageMediator,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1819
        Throwable throwable,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1820
        CompletionStatus completionStatus)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1821
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1822
        if (((ORB)messageMediator.getBroker()).subcontractDebugFlag) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1823
            dprint(".handleThrowableDuringServerDispatch: "
02bb8761fcce Initial load
duke
parents:
diff changeset
  1824
                   + opAndId(messageMediator) + ": "
02bb8761fcce Initial load
duke
parents:
diff changeset
  1825
                   + throwable);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1826
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1827
02bb8761fcce Initial load
duke
parents:
diff changeset
  1828
        // If we haven't unmarshaled the header, we probably don't
02bb8761fcce Initial load
duke
parents:
diff changeset
  1829
        // have enough information to even send back a reply.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1830
02bb8761fcce Initial load
duke
parents:
diff changeset
  1831
        // REVISIT
02bb8761fcce Initial load
duke
parents:
diff changeset
  1832
        // Cannot do this check.  When target addressing disposition does
02bb8761fcce Initial load
duke
parents:
diff changeset
  1833
        // not match (during header unmarshaling) it throws an exception
02bb8761fcce Initial load
duke
parents:
diff changeset
  1834
        // to be handled here.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1835
        /*
02bb8761fcce Initial load
duke
parents:
diff changeset
  1836
        if (! ((CDRInputObject)messageMediator.getInputObject())
02bb8761fcce Initial load
duke
parents:
diff changeset
  1837
            .unmarshaledHeader()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1838
            return;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1839
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1840
        */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1841
        handleThrowableDuringServerDispatch(messageMediator,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1842
                                            throwable,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1843
                                            completionStatus,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1844
                                            1);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1845
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1846
02bb8761fcce Initial load
duke
parents:
diff changeset
  1847
02bb8761fcce Initial load
duke
parents:
diff changeset
  1848
    // REVISIT - catch and ignore RequestCanceledException.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1849
02bb8761fcce Initial load
duke
parents:
diff changeset
  1850
    protected void handleThrowableDuringServerDispatch(
02bb8761fcce Initial load
duke
parents:
diff changeset
  1851
        CorbaMessageMediator messageMediator,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1852
        Throwable throwable,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1853
        CompletionStatus completionStatus,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1854
        int iteration)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1855
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1856
        if (iteration > 10) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1857
            if (((ORB)messageMediator.getBroker()).subcontractDebugFlag) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1858
                dprint(".handleThrowableDuringServerDispatch: "
02bb8761fcce Initial load
duke
parents:
diff changeset
  1859
                       + opAndId(messageMediator)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1860
                       + ": cannot handle: "
02bb8761fcce Initial load
duke
parents:
diff changeset
  1861
                       + throwable);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1862
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1863
02bb8761fcce Initial load
duke
parents:
diff changeset
  1864
            // REVISIT - should we close connection?
02bb8761fcce Initial load
duke
parents:
diff changeset
  1865
            RuntimeException rte =
02bb8761fcce Initial load
duke
parents:
diff changeset
  1866
                new RuntimeException("handleThrowableDuringServerDispatch: " +
02bb8761fcce Initial load
duke
parents:
diff changeset
  1867
                                     "cannot create response.");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1868
            rte.initCause(throwable);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1869
            throw rte;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1870
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1871
02bb8761fcce Initial load
duke
parents:
diff changeset
  1872
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1873
            if (throwable instanceof ForwardException) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1874
                ForwardException fex = (ForwardException)throwable ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1875
                createLocationForward( messageMediator, fex.getIOR(), null ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1876
                return;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1877
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1878
02bb8761fcce Initial load
duke
parents:
diff changeset
  1879
            if (throwable instanceof AddressingDispositionException) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1880
                handleAddressingDisposition(
02bb8761fcce Initial load
duke
parents:
diff changeset
  1881
                    messageMediator,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1882
                    (AddressingDispositionException)throwable);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1883
                return;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1884
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1885
02bb8761fcce Initial load
duke
parents:
diff changeset
  1886
            // Else.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1887
02bb8761fcce Initial load
duke
parents:
diff changeset
  1888
            SystemException sex =
02bb8761fcce Initial load
duke
parents:
diff changeset
  1889
                convertThrowableToSystemException(throwable, completionStatus);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1890
02bb8761fcce Initial load
duke
parents:
diff changeset
  1891
            createSystemExceptionResponse(messageMediator, sex, null);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1892
            return;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1893
02bb8761fcce Initial load
duke
parents:
diff changeset
  1894
        } catch (Throwable throwable2) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1895
02bb8761fcce Initial load
duke
parents:
diff changeset
  1896
            // User code (e.g., postinvoke, interceptors) may change
02bb8761fcce Initial load
duke
parents:
diff changeset
  1897
            // the exception, so we end up back here.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1898
            // Report the changed exception.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1899
02bb8761fcce Initial load
duke
parents:
diff changeset
  1900
            handleThrowableDuringServerDispatch(messageMediator,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1901
                                                throwable2,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1902
                                                completionStatus,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1903
                                                iteration + 1);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1904
            return;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1905
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1906
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1907
02bb8761fcce Initial load
duke
parents:
diff changeset
  1908
    protected SystemException convertThrowableToSystemException(
02bb8761fcce Initial load
duke
parents:
diff changeset
  1909
        Throwable throwable,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1910
        CompletionStatus completionStatus)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1911
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1912
        if (throwable instanceof SystemException) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1913
            return (SystemException)throwable;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1914
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1915
02bb8761fcce Initial load
duke
parents:
diff changeset
  1916
        if (throwable instanceof RequestCanceledException) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1917
            // Reporting an exception response causes the
02bb8761fcce Initial load
duke
parents:
diff changeset
  1918
            // poa current stack, the interceptor stacks, etc.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1919
            // to be balanced.  It also notifies interceptors
02bb8761fcce Initial load
duke
parents:
diff changeset
  1920
            // that the request was cancelled.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1921
02bb8761fcce Initial load
duke
parents:
diff changeset
  1922
            return wrapper.requestCanceled( throwable ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1923
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1924
02bb8761fcce Initial load
duke
parents:
diff changeset
  1925
        // NOTE: We do not trap ThreadDeath above Throwable.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1926
        // There is no reason to stop the thread.  It is
02bb8761fcce Initial load
duke
parents:
diff changeset
  1927
        // just a worker thread.  The ORB never throws
02bb8761fcce Initial load
duke
parents:
diff changeset
  1928
        // ThreadDeath.  Client code may (e.g., in ServantManagers,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1929
        // interceptors, or servants) but that should not
02bb8761fcce Initial load
duke
parents:
diff changeset
  1930
        // effect the ORB threads.  So it is just handled
02bb8761fcce Initial load
duke
parents:
diff changeset
  1931
        // generically.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1932
02bb8761fcce Initial load
duke
parents:
diff changeset
  1933
        //
02bb8761fcce Initial load
duke
parents:
diff changeset
  1934
        // Last resort.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1935
        // If user code throws a non-SystemException report it generically.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1936
        //
02bb8761fcce Initial load
duke
parents:
diff changeset
  1937
02bb8761fcce Initial load
duke
parents:
diff changeset
  1938
        return wrapper.runtimeexception( CompletionStatus.COMPLETED_MAYBE, throwable ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1939
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1940
02bb8761fcce Initial load
duke
parents:
diff changeset
  1941
    protected void handleAddressingDisposition(
02bb8761fcce Initial load
duke
parents:
diff changeset
  1942
        CorbaMessageMediator messageMediator,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1943
        AddressingDispositionException ex)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1944
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1945
02bb8761fcce Initial load
duke
parents:
diff changeset
  1946
        short addrDisp = -1;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1947
02bb8761fcce Initial load
duke
parents:
diff changeset
  1948
        // from iiop.RequestProcessor.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1949
02bb8761fcce Initial load
duke
parents:
diff changeset
  1950
        // Respond with expected target addressing disposition.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1951
02bb8761fcce Initial load
duke
parents:
diff changeset
  1952
        switch (messageMediator.getRequestHeader().getType()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1953
        case Message.GIOPRequest :
02bb8761fcce Initial load
duke
parents:
diff changeset
  1954
            ReplyMessage replyHeader = MessageBase.createReply(
02bb8761fcce Initial load
duke
parents:
diff changeset
  1955
                          (ORB)messageMediator.getBroker(),
02bb8761fcce Initial load
duke
parents:
diff changeset
  1956
                          messageMediator.getGIOPVersion(),
02bb8761fcce Initial load
duke
parents:
diff changeset
  1957
                          messageMediator.getEncodingVersion(),
02bb8761fcce Initial load
duke
parents:
diff changeset
  1958
                          messageMediator.getRequestId(),
02bb8761fcce Initial load
duke
parents:
diff changeset
  1959
                          ReplyMessage.NEEDS_ADDRESSING_MODE,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1960
                          null, null);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1961
            // REVISIT: via acceptor factory.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1962
            CDROutputObject outputObject = new CDROutputObject(
02bb8761fcce Initial load
duke
parents:
diff changeset
  1963
                (ORB)messageMediator.getBroker(),
02bb8761fcce Initial load
duke
parents:
diff changeset
  1964
                this,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1965
                messageMediator.getGIOPVersion(),
02bb8761fcce Initial load
duke
parents:
diff changeset
  1966
                (CorbaConnection)messageMediator.getConnection(),
02bb8761fcce Initial load
duke
parents:
diff changeset
  1967
                replyHeader,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1968
                ORBConstants.STREAM_FORMAT_VERSION_1);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1969
            messageMediator.setOutputObject(outputObject);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1970
            outputObject.setMessageMediator(messageMediator);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1971
            replyHeader.write(outputObject);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1972
            AddressingDispositionHelper.write(outputObject,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1973
                                              ex.expectedAddrDisp());
02bb8761fcce Initial load
duke
parents:
diff changeset
  1974
            return;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1975
02bb8761fcce Initial load
duke
parents:
diff changeset
  1976
        case Message.GIOPLocateRequest :
02bb8761fcce Initial load
duke
parents:
diff changeset
  1977
            LocateReplyMessage locateReplyHeader = MessageBase.createLocateReply(
02bb8761fcce Initial load
duke
parents:
diff changeset
  1978
                (ORB)messageMediator.getBroker(),
02bb8761fcce Initial load
duke
parents:
diff changeset
  1979
                messageMediator.getGIOPVersion(),
02bb8761fcce Initial load
duke
parents:
diff changeset
  1980
                messageMediator.getEncodingVersion(),
02bb8761fcce Initial load
duke
parents:
diff changeset
  1981
                messageMediator.getRequestId(),
02bb8761fcce Initial load
duke
parents:
diff changeset
  1982
                LocateReplyMessage.LOC_NEEDS_ADDRESSING_MODE,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1983
                null);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1984
02bb8761fcce Initial load
duke
parents:
diff changeset
  1985
            addrDisp = ex.expectedAddrDisp();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1986
02bb8761fcce Initial load
duke
parents:
diff changeset
  1987
            // REVISIT: via acceptor factory.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1988
            outputObject =
02bb8761fcce Initial load
duke
parents:
diff changeset
  1989
                createAppropriateOutputObject(messageMediator,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1990
                                              messageMediator.getRequestHeader(),
02bb8761fcce Initial load
duke
parents:
diff changeset
  1991
                                              locateReplyHeader);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1992
            messageMediator.setOutputObject(outputObject);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1993
            outputObject.setMessageMediator(messageMediator);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1994
            locateReplyHeader.write(outputObject);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1995
            IOR ior = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1996
            if (ior != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1997
                ior.write(outputObject);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1998
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1999
            if (addrDisp != -1) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2000
                AddressingDispositionHelper.write(outputObject, addrDisp);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2001
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2002
            return;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2003
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2004
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2005
02bb8761fcce Initial load
duke
parents:
diff changeset
  2006
    public CorbaMessageMediator createResponse(
02bb8761fcce Initial load
duke
parents:
diff changeset
  2007
        CorbaMessageMediator messageMediator,
02bb8761fcce Initial load
duke
parents:
diff changeset
  2008
        ServiceContexts svc)
02bb8761fcce Initial load
duke
parents:
diff changeset
  2009
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2010
        // REVISIT: ignore service contexts during framework transition.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2011
        // They are set in SubcontractResponseHandler to the wrong connection.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2012
        // Then they would be set again here and a duplicate contexts
02bb8761fcce Initial load
duke
parents:
diff changeset
  2013
        // exception occurs.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2014
        return createResponseHelper(
02bb8761fcce Initial load
duke
parents:
diff changeset
  2015
            messageMediator,
02bb8761fcce Initial load
duke
parents:
diff changeset
  2016
            getServiceContextsForReply(messageMediator, null));
02bb8761fcce Initial load
duke
parents:
diff changeset
  2017
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2018
02bb8761fcce Initial load
duke
parents:
diff changeset
  2019
    public CorbaMessageMediator createUserExceptionResponse(
02bb8761fcce Initial load
duke
parents:
diff changeset
  2020
        CorbaMessageMediator messageMediator, ServiceContexts svc)
02bb8761fcce Initial load
duke
parents:
diff changeset
  2021
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2022
        // REVISIT - same as above
02bb8761fcce Initial load
duke
parents:
diff changeset
  2023
        return createResponseHelper(
02bb8761fcce Initial load
duke
parents:
diff changeset
  2024
            messageMediator,
02bb8761fcce Initial load
duke
parents:
diff changeset
  2025
            getServiceContextsForReply(messageMediator, null),
02bb8761fcce Initial load
duke
parents:
diff changeset
  2026
            true);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2027
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2028
02bb8761fcce Initial load
duke
parents:
diff changeset
  2029
    public CorbaMessageMediator createUnknownExceptionResponse(
02bb8761fcce Initial load
duke
parents:
diff changeset
  2030
        CorbaMessageMediator messageMediator, UnknownException ex)
02bb8761fcce Initial load
duke
parents:
diff changeset
  2031
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2032
        // NOTE: This service context container gets augmented in
02bb8761fcce Initial load
duke
parents:
diff changeset
  2033
        // tail call.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2034
        ServiceContexts contexts = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2035
        SystemException sys = new UNKNOWN( 0,
02bb8761fcce Initial load
duke
parents:
diff changeset
  2036
            CompletionStatus.COMPLETED_MAYBE);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2037
        contexts = new ServiceContexts( (ORB)messageMediator.getBroker() );
02bb8761fcce Initial load
duke
parents:
diff changeset
  2038
        UEInfoServiceContext uei = new UEInfoServiceContext(sys);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2039
        contexts.put( uei ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2040
        return createSystemExceptionResponse(messageMediator, sys, contexts);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2041
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2042
02bb8761fcce Initial load
duke
parents:
diff changeset
  2043
    public CorbaMessageMediator createSystemExceptionResponse(
02bb8761fcce Initial load
duke
parents:
diff changeset
  2044
        CorbaMessageMediator messageMediator,
02bb8761fcce Initial load
duke
parents:
diff changeset
  2045
        SystemException ex,
02bb8761fcce Initial load
duke
parents:
diff changeset
  2046
        ServiceContexts svc)
02bb8761fcce Initial load
duke
parents:
diff changeset
  2047
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2048
        if (messageMediator.getConnection() != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2049
            // It is possible that fragments of response have already been
02bb8761fcce Initial load
duke
parents:
diff changeset
  2050
            // sent.  Then an error may occur (e.g. marshaling error like
02bb8761fcce Initial load
duke
parents:
diff changeset
  2051
            // non serializable object).  In that case it is too late
02bb8761fcce Initial load
duke
parents:
diff changeset
  2052
            // to send the exception.  We just return the existing fragmented
02bb8761fcce Initial load
duke
parents:
diff changeset
  2053
            // stream here.  This will cause an incomplete last fragment
02bb8761fcce Initial load
duke
parents:
diff changeset
  2054
            // to be sent.  Then the other side will get a marshaling error
02bb8761fcce Initial load
duke
parents:
diff changeset
  2055
            // when attempting to unmarshal.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2056
02bb8761fcce Initial load
duke
parents:
diff changeset
  2057
            // REVISIT: Impl - make interface method to do the following.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2058
            CorbaMessageMediatorImpl mediator = (CorbaMessageMediatorImpl)
02bb8761fcce Initial load
duke
parents:
diff changeset
  2059
                ((CorbaConnection)messageMediator.getConnection())
02bb8761fcce Initial load
duke
parents:
diff changeset
  2060
                .serverRequestMapGet(messageMediator.getRequestId());
02bb8761fcce Initial load
duke
parents:
diff changeset
  2061
02bb8761fcce Initial load
duke
parents:
diff changeset
  2062
            OutputObject existingOutputObject = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2063
            if (mediator != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2064
                existingOutputObject = mediator.getOutputObject();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2065
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2066
02bb8761fcce Initial load
duke
parents:
diff changeset
  2067
            // REVISIT: need to think about messageMediator containing correct
02bb8761fcce Initial load
duke
parents:
diff changeset
  2068
            // pointer to output object.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2069
            if (existingOutputObject != null &&
02bb8761fcce Initial load
duke
parents:
diff changeset
  2070
                mediator.sentFragment() &&
02bb8761fcce Initial load
duke
parents:
diff changeset
  2071
                ! mediator.sentFullMessage())
02bb8761fcce Initial load
duke
parents:
diff changeset
  2072
            {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2073
                return mediator;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2074
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2075
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2076
02bb8761fcce Initial load
duke
parents:
diff changeset
  2077
        // Only do this if interceptors have been initialized on this request
02bb8761fcce Initial load
duke
parents:
diff changeset
  2078
        // and have not completed their lifecycle (otherwise the info stack
02bb8761fcce Initial load
duke
parents:
diff changeset
  2079
        // may be empty or have a different request's entry on top).
02bb8761fcce Initial load
duke
parents:
diff changeset
  2080
        if (messageMediator.executePIInResponseConstructor()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2081
            // REVISIT: not necessary in framework now?
02bb8761fcce Initial load
duke
parents:
diff changeset
  2082
            // Inform Portable Interceptors of the SystemException.  This is
02bb8761fcce Initial load
duke
parents:
diff changeset
  2083
            // required to be done here because the ending interception point
02bb8761fcce Initial load
duke
parents:
diff changeset
  2084
            // is called in the when creating the response below
02bb8761fcce Initial load
duke
parents:
diff changeset
  2085
            // but we do not currently write the SystemException into the
02bb8761fcce Initial load
duke
parents:
diff changeset
  2086
            // response until after the ending point is called.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2087
            ((ORB)messageMediator.getBroker()).getPIHandler().setServerPIInfo( ex );
02bb8761fcce Initial load
duke
parents:
diff changeset
  2088
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2089
02bb8761fcce Initial load
duke
parents:
diff changeset
  2090
        if (((ORB)messageMediator.getBroker()).subcontractDebugFlag &&
02bb8761fcce Initial load
duke
parents:
diff changeset
  2091
            ex != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
  2092
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2093
            dprint(".createSystemExceptionResponse: "
02bb8761fcce Initial load
duke
parents:
diff changeset
  2094
                   + opAndId(messageMediator),
02bb8761fcce Initial load
duke
parents:
diff changeset
  2095
                   ex);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2096
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2097
02bb8761fcce Initial load
duke
parents:
diff changeset
  2098
        ServiceContexts serviceContexts =
02bb8761fcce Initial load
duke
parents:
diff changeset
  2099
            getServiceContextsForReply(messageMediator, svc);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2100
02bb8761fcce Initial load
duke
parents:
diff changeset
  2101
        // NOTE: We MUST add the service context before creating
02bb8761fcce Initial load
duke
parents:
diff changeset
  2102
        // the response since service contexts are written to the
02bb8761fcce Initial load
duke
parents:
diff changeset
  2103
        // stream when the response object is created.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2104
02bb8761fcce Initial load
duke
parents:
diff changeset
  2105
        addExceptionDetailMessage(messageMediator, ex, serviceContexts);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2106
02bb8761fcce Initial load
duke
parents:
diff changeset
  2107
        CorbaMessageMediator response =
02bb8761fcce Initial load
duke
parents:
diff changeset
  2108
            createResponseHelper(messageMediator, serviceContexts, false);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2109
02bb8761fcce Initial load
duke
parents:
diff changeset
  2110
        // NOTE: From here on, it is too late to add more service contexts.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2111
        // They have already been serialized to the stream (and maybe fragments
02bb8761fcce Initial load
duke
parents:
diff changeset
  2112
        // sent).
02bb8761fcce Initial load
duke
parents:
diff changeset
  2113
02bb8761fcce Initial load
duke
parents:
diff changeset
  2114
        ORBUtility.writeSystemException(
02bb8761fcce Initial load
duke
parents:
diff changeset
  2115
            ex, (OutputStream)response.getOutputObject());
02bb8761fcce Initial load
duke
parents:
diff changeset
  2116
02bb8761fcce Initial load
duke
parents:
diff changeset
  2117
        return response;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2118
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2119
02bb8761fcce Initial load
duke
parents:
diff changeset
  2120
    private void addExceptionDetailMessage(CorbaMessageMediator mediator,
02bb8761fcce Initial load
duke
parents:
diff changeset
  2121
                                           SystemException ex,
02bb8761fcce Initial load
duke
parents:
diff changeset
  2122
                                           ServiceContexts serviceContexts)
02bb8761fcce Initial load
duke
parents:
diff changeset
  2123
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2124
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2125
        PrintWriter pw = new PrintWriter(baos);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2126
        ex.printStackTrace(pw);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2127
        pw.flush(); // NOTE: you must flush or baos will be empty.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2128
        EncapsOutputStream encapsOutputStream =
02bb8761fcce Initial load
duke
parents:
diff changeset
  2129
            new EncapsOutputStream((ORB)mediator.getBroker());
02bb8761fcce Initial load
duke
parents:
diff changeset
  2130
        encapsOutputStream.putEndian();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2131
        encapsOutputStream.write_wstring(baos.toString());
02bb8761fcce Initial load
duke
parents:
diff changeset
  2132
        UnknownServiceContext serviceContext =
02bb8761fcce Initial load
duke
parents:
diff changeset
  2133
            new UnknownServiceContext(ExceptionDetailMessage.value,
02bb8761fcce Initial load
duke
parents:
diff changeset
  2134
                                      encapsOutputStream.toByteArray());
02bb8761fcce Initial load
duke
parents:
diff changeset
  2135
        serviceContexts.put(serviceContext);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2136
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2137
02bb8761fcce Initial load
duke
parents:
diff changeset
  2138
    public CorbaMessageMediator createLocationForward(
02bb8761fcce Initial load
duke
parents:
diff changeset
  2139
        CorbaMessageMediator messageMediator, IOR ior, ServiceContexts svc)
02bb8761fcce Initial load
duke
parents:
diff changeset
  2140
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2141
        ReplyMessage reply
02bb8761fcce Initial load
duke
parents:
diff changeset
  2142
            = MessageBase.createReply(
02bb8761fcce Initial load
duke
parents:
diff changeset
  2143
                  (ORB)messageMediator.getBroker(),
02bb8761fcce Initial load
duke
parents:
diff changeset
  2144
                  messageMediator.getGIOPVersion(),
02bb8761fcce Initial load
duke
parents:
diff changeset
  2145
                  messageMediator.getEncodingVersion(),
02bb8761fcce Initial load
duke
parents:
diff changeset
  2146
                  messageMediator.getRequestId(),
02bb8761fcce Initial load
duke
parents:
diff changeset
  2147
                  ReplyMessage.LOCATION_FORWARD,
02bb8761fcce Initial load
duke
parents:
diff changeset
  2148
                  getServiceContextsForReply(messageMediator, svc),
02bb8761fcce Initial load
duke
parents:
diff changeset
  2149
                  ior);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2150
02bb8761fcce Initial load
duke
parents:
diff changeset
  2151
        return createResponseHelper(messageMediator, reply, ior);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2152
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2153
02bb8761fcce Initial load
duke
parents:
diff changeset
  2154
    protected CorbaMessageMediator createResponseHelper(
02bb8761fcce Initial load
duke
parents:
diff changeset
  2155
        CorbaMessageMediator messageMediator, ServiceContexts svc)
02bb8761fcce Initial load
duke
parents:
diff changeset
  2156
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2157
        ReplyMessage message =
02bb8761fcce Initial load
duke
parents:
diff changeset
  2158
            MessageBase.createReply(
02bb8761fcce Initial load
duke
parents:
diff changeset
  2159
                (ORB)messageMediator.getBroker(),
02bb8761fcce Initial load
duke
parents:
diff changeset
  2160
                messageMediator.getGIOPVersion(),
02bb8761fcce Initial load
duke
parents:
diff changeset
  2161
                messageMediator.getEncodingVersion(),
02bb8761fcce Initial load
duke
parents:
diff changeset
  2162
                messageMediator.getRequestId(),
02bb8761fcce Initial load
duke
parents:
diff changeset
  2163
                ReplyMessage.NO_EXCEPTION,
02bb8761fcce Initial load
duke
parents:
diff changeset
  2164
                svc,
02bb8761fcce Initial load
duke
parents:
diff changeset
  2165
                null);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2166
        return createResponseHelper(messageMediator, message, null);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2167
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2168
02bb8761fcce Initial load
duke
parents:
diff changeset
  2169
    protected CorbaMessageMediator createResponseHelper(
02bb8761fcce Initial load
duke
parents:
diff changeset
  2170
        CorbaMessageMediator messageMediator, ServiceContexts svc,boolean user)
02bb8761fcce Initial load
duke
parents:
diff changeset
  2171
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2172
        ReplyMessage message =
02bb8761fcce Initial load
duke
parents:
diff changeset
  2173
            MessageBase.createReply(
02bb8761fcce Initial load
duke
parents:
diff changeset
  2174
                (ORB)messageMediator.getBroker(),
02bb8761fcce Initial load
duke
parents:
diff changeset
  2175
                messageMediator.getGIOPVersion(),
02bb8761fcce Initial load
duke
parents:
diff changeset
  2176
                messageMediator.getEncodingVersion(),
02bb8761fcce Initial load
duke
parents:
diff changeset
  2177
                messageMediator.getRequestId(),
02bb8761fcce Initial load
duke
parents:
diff changeset
  2178
                user ? ReplyMessage.USER_EXCEPTION :
02bb8761fcce Initial load
duke
parents:
diff changeset
  2179
                       ReplyMessage.SYSTEM_EXCEPTION,
02bb8761fcce Initial load
duke
parents:
diff changeset
  2180
                svc,
02bb8761fcce Initial load
duke
parents:
diff changeset
  2181
                null);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2182
        return createResponseHelper(messageMediator, message, null);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2183
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2184
02bb8761fcce Initial load
duke
parents:
diff changeset
  2185
    // REVISIT - IOR arg is ignored.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2186
    protected CorbaMessageMediator createResponseHelper(
02bb8761fcce Initial load
duke
parents:
diff changeset
  2187
        CorbaMessageMediator messageMediator, ReplyMessage reply, IOR ior)
02bb8761fcce Initial load
duke
parents:
diff changeset
  2188
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2189
        // REVISIT - these should be invoked from subcontract.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2190
        runServantPostInvoke(messageMediator);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2191
        runInterceptors(messageMediator, reply);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2192
        runRemoveThreadInfo(messageMediator);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2193
02bb8761fcce Initial load
duke
parents:
diff changeset
  2194
        if (((ORB)messageMediator.getBroker()).subcontractDebugFlag) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2195
            dprint(".createResponseHelper: "
02bb8761fcce Initial load
duke
parents:
diff changeset
  2196
                   + opAndId(messageMediator) + ": "
02bb8761fcce Initial load
duke
parents:
diff changeset
  2197
                   + reply);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2198
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2199
02bb8761fcce Initial load
duke
parents:
diff changeset
  2200
        messageMediator.setReplyHeader(reply);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2201
02bb8761fcce Initial load
duke
parents:
diff changeset
  2202
        OutputObject replyOutputObject;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2203
        // REVISIT = do not use null.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2204
        //
02bb8761fcce Initial load
duke
parents:
diff changeset
  2205
        if (messageMediator.getConnection() == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2206
            // REVISIT - needs factory
02bb8761fcce Initial load
duke
parents:
diff changeset
  2207
            replyOutputObject =
02bb8761fcce Initial load
duke
parents:
diff changeset
  2208
                new CDROutputObject(orb, messageMediator,
02bb8761fcce Initial load
duke
parents:
diff changeset
  2209
                                    messageMediator.getReplyHeader(),
02bb8761fcce Initial load
duke
parents:
diff changeset
  2210
                                    messageMediator.getStreamFormatVersion(),
02bb8761fcce Initial load
duke
parents:
diff changeset
  2211
                                    BufferManagerFactory.GROW);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2212
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2213
            replyOutputObject = messageMediator.getConnection().getAcceptor()
02bb8761fcce Initial load
duke
parents:
diff changeset
  2214
             .createOutputObject(messageMediator.getBroker(), messageMediator);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2215
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2216
        messageMediator.setOutputObject(replyOutputObject);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2217
        messageMediator.getOutputObject().setMessageMediator(messageMediator);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2218
02bb8761fcce Initial load
duke
parents:
diff changeset
  2219
        reply.write((OutputStream) messageMediator.getOutputObject());
02bb8761fcce Initial load
duke
parents:
diff changeset
  2220
        if (reply.getIOR() != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2221
            reply.getIOR().write((OutputStream) messageMediator.getOutputObject());
02bb8761fcce Initial load
duke
parents:
diff changeset
  2222
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2223
        // REVISIT - not necessary?
02bb8761fcce Initial load
duke
parents:
diff changeset
  2224
        //messageMediator.this.replyIOR = reply.getIOR();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2225
02bb8761fcce Initial load
duke
parents:
diff changeset
  2226
        // NOTE: The mediator holds onto output object so return value
02bb8761fcce Initial load
duke
parents:
diff changeset
  2227
        // not really necessary.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2228
        return messageMediator;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2229
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2230
02bb8761fcce Initial load
duke
parents:
diff changeset
  2231
    protected void runServantPostInvoke(CorbaMessageMediator messageMediator)
02bb8761fcce Initial load
duke
parents:
diff changeset
  2232
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2233
        // Run ServantLocator::postinvoke.  This may cause a SystemException
02bb8761fcce Initial load
duke
parents:
diff changeset
  2234
        // which will throw out of the constructor and return later
02bb8761fcce Initial load
duke
parents:
diff changeset
  2235
        // to construct a reply for that exception.  The internal logic
02bb8761fcce Initial load
duke
parents:
diff changeset
  2236
        // of returnServant makes sure that postinvoke is only called once.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2237
        // REVISIT: instead of instanceof, put method on all orbs.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2238
        ORB orb = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2239
        // This flag is to deal with BootstrapServer use of reply streams,
02bb8761fcce Initial load
duke
parents:
diff changeset
  2240
        // with ServerRequestDispatcher's use of reply streams, etc.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2241
        if (messageMediator.executeReturnServantInResponseConstructor()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2242
            // It is possible to get marshaling errors in the skeleton after
02bb8761fcce Initial load
duke
parents:
diff changeset
  2243
            // postinvoke has completed.  We must set this to false so that
02bb8761fcce Initial load
duke
parents:
diff changeset
  2244
            // when the error exception reply is constructed we don't try
02bb8761fcce Initial load
duke
parents:
diff changeset
  2245
            // to incorrectly access poa current (which will be the wrong
02bb8761fcce Initial load
duke
parents:
diff changeset
  2246
            // one or an empty stack.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2247
            messageMediator.setExecuteReturnServantInResponseConstructor(false);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2248
            messageMediator.setExecuteRemoveThreadInfoInResponseConstructor(true);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2249
02bb8761fcce Initial load
duke
parents:
diff changeset
  2250
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2251
                orb = (ORB)messageMediator.getBroker();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2252
                OAInvocationInfo info = orb.peekInvocationInfo() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2253
                ObjectAdapter oa = info.oa();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2254
                try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2255
                    oa.returnServant() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2256
                } catch (Throwable thr) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2257
                    wrapper.unexpectedException( thr ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2258
02bb8761fcce Initial load
duke
parents:
diff changeset
  2259
                    if (thr instanceof Error)
02bb8761fcce Initial load
duke
parents:
diff changeset
  2260
                        throw (Error)thr ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2261
                    else if (thr instanceof RuntimeException)
02bb8761fcce Initial load
duke
parents:
diff changeset
  2262
                        throw (RuntimeException)thr ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2263
                } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2264
                    oa.exit();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2265
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2266
            } catch (EmptyStackException ese) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2267
                throw wrapper.emptyStackRunServantPostInvoke( ese ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2268
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2269
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2270
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2271
02bb8761fcce Initial load
duke
parents:
diff changeset
  2272
    protected void runInterceptors(CorbaMessageMediator messageMediator,
02bb8761fcce Initial load
duke
parents:
diff changeset
  2273
                                   ReplyMessage reply)
02bb8761fcce Initial load
duke
parents:
diff changeset
  2274
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2275
        if( messageMediator.executePIInResponseConstructor() ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2276
            // Invoke server request ending interception points (send_*):
02bb8761fcce Initial load
duke
parents:
diff changeset
  2277
            // Note: this may end up with a SystemException or an internal
02bb8761fcce Initial load
duke
parents:
diff changeset
  2278
            // Runtime ForwardRequest
02bb8761fcce Initial load
duke
parents:
diff changeset
  2279
            ((ORB)messageMediator.getBroker()).getPIHandler().
02bb8761fcce Initial load
duke
parents:
diff changeset
  2280
                invokeServerPIEndingPoint( reply );
02bb8761fcce Initial load
duke
parents:
diff changeset
  2281
02bb8761fcce Initial load
duke
parents:
diff changeset
  2282
            // Note this will be executed even if a ForwardRequest or
02bb8761fcce Initial load
duke
parents:
diff changeset
  2283
            // SystemException is thrown by a Portable Interceptors ending
02bb8761fcce Initial load
duke
parents:
diff changeset
  2284
            // point since we end up in this constructor again anyway.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2285
            ((ORB)messageMediator.getBroker()).getPIHandler().
02bb8761fcce Initial load
duke
parents:
diff changeset
  2286
                cleanupServerPIRequest();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2287
02bb8761fcce Initial load
duke
parents:
diff changeset
  2288
            // See createSystemExceptionResponse for why this is necesary.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2289
            messageMediator.setExecutePIInResponseConstructor(false);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2290
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2291
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2292
02bb8761fcce Initial load
duke
parents:
diff changeset
  2293
    protected void runRemoveThreadInfo(CorbaMessageMediator messageMediator)
02bb8761fcce Initial load
duke
parents:
diff changeset
  2294
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2295
        // Once you get here then the final reply is available (i.e.,
02bb8761fcce Initial load
duke
parents:
diff changeset
  2296
        // postinvoke and interceptors have completed.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2297
        if (messageMediator.executeRemoveThreadInfoInResponseConstructor()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2298
            messageMediator.setExecuteRemoveThreadInfoInResponseConstructor(false);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2299
            ((ORB)messageMediator.getBroker()).popInvocationInfo() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2300
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2301
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2302
02bb8761fcce Initial load
duke
parents:
diff changeset
  2303
    protected ServiceContexts getServiceContextsForReply(
02bb8761fcce Initial load
duke
parents:
diff changeset
  2304
        CorbaMessageMediator messageMediator, ServiceContexts contexts)
02bb8761fcce Initial load
duke
parents:
diff changeset
  2305
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2306
        CorbaConnection c = (CorbaConnection) messageMediator.getConnection();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2307
02bb8761fcce Initial load
duke
parents:
diff changeset
  2308
        if (((ORB)messageMediator.getBroker()).subcontractDebugFlag) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2309
            dprint(".getServiceContextsForReply: "
02bb8761fcce Initial load
duke
parents:
diff changeset
  2310
                   + opAndId(messageMediator)
02bb8761fcce Initial load
duke
parents:
diff changeset
  2311
                   + ": " + c);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2312
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2313
02bb8761fcce Initial load
duke
parents:
diff changeset
  2314
        if (contexts == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2315
            contexts = new ServiceContexts(((ORB)messageMediator.getBroker()));
02bb8761fcce Initial load
duke
parents:
diff changeset
  2316
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2317
02bb8761fcce Initial load
duke
parents:
diff changeset
  2318
        // NOTE : We only want to send the runtime context the first time
02bb8761fcce Initial load
duke
parents:
diff changeset
  2319
02bb8761fcce Initial load
duke
parents:
diff changeset
  2320
        if (c != null && !c.isPostInitialContexts()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2321
            c.setPostInitialContexts();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2322
            SendingContextServiceContext scsc =
02bb8761fcce Initial load
duke
parents:
diff changeset
  2323
                new SendingContextServiceContext(
02bb8761fcce Initial load
duke
parents:
diff changeset
  2324
                    ((ORB)messageMediator.getBroker()).getFVDCodeBaseIOR()) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2325
02bb8761fcce Initial load
duke
parents:
diff changeset
  2326
            if (contexts.get( scsc.getId() ) != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
  2327
                throw wrapper.duplicateSendingContextServiceContext() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2328
02bb8761fcce Initial load
duke
parents:
diff changeset
  2329
            contexts.put( scsc ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2330
02bb8761fcce Initial load
duke
parents:
diff changeset
  2331
            if ( ((ORB)messageMediator.getBroker()).subcontractDebugFlag)
02bb8761fcce Initial load
duke
parents:
diff changeset
  2332
                dprint(".getServiceContextsForReply: "
02bb8761fcce Initial load
duke
parents:
diff changeset
  2333
                       + opAndId(messageMediator)
02bb8761fcce Initial load
duke
parents:
diff changeset
  2334
                       + ": added SendingContextServiceContext" ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2335
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2336
02bb8761fcce Initial load
duke
parents:
diff changeset
  2337
        // send ORBVersion servicecontext as part of the Reply
02bb8761fcce Initial load
duke
parents:
diff changeset
  2338
02bb8761fcce Initial load
duke
parents:
diff changeset
  2339
        ORBVersionServiceContext ovsc
02bb8761fcce Initial load
duke
parents:
diff changeset
  2340
            = new ORBVersionServiceContext(ORBVersionFactory.getORBVersion());
02bb8761fcce Initial load
duke
parents:
diff changeset
  2341
02bb8761fcce Initial load
duke
parents:
diff changeset
  2342
        if (contexts.get( ovsc.getId() ) != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
  2343
            throw wrapper.duplicateOrbVersionServiceContext() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2344
02bb8761fcce Initial load
duke
parents:
diff changeset
  2345
        contexts.put( ovsc ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2346
02bb8761fcce Initial load
duke
parents:
diff changeset
  2347
        if ( ((ORB)messageMediator.getBroker()).subcontractDebugFlag)
02bb8761fcce Initial load
duke
parents:
diff changeset
  2348
            dprint(".getServiceContextsForReply: "
02bb8761fcce Initial load
duke
parents:
diff changeset
  2349
                   + opAndId(messageMediator)
02bb8761fcce Initial load
duke
parents:
diff changeset
  2350
                   + ": added ORB version service context");
02bb8761fcce Initial load
duke
parents:
diff changeset
  2351
02bb8761fcce Initial load
duke
parents:
diff changeset
  2352
        return contexts;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2353
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2354
02bb8761fcce Initial load
duke
parents:
diff changeset
  2355
    // REVISIT - this method should be migrated to orbutil.ORBUtility
02bb8761fcce Initial load
duke
parents:
diff changeset
  2356
    //           since all locations that release ByteBuffers use
02bb8761fcce Initial load
duke
parents:
diff changeset
  2357
    //           very similar logic and debug information.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2358
    private void releaseByteBufferToPool() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2359
        if (dispatchByteBuffer != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2360
            orb.getByteBufferPool().releaseByteBuffer(dispatchByteBuffer);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2361
            if (transportDebug()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2362
                int bbId = System.identityHashCode(dispatchByteBuffer);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2363
                StringBuffer sb = new StringBuffer();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2364
                sb.append(".handleInput: releasing ByteBuffer (" + bbId +
02bb8761fcce Initial load
duke
parents:
diff changeset
  2365
                          ") to ByteBufferPool");
02bb8761fcce Initial load
duke
parents:
diff changeset
  2366
                dprint(sb.toString());
02bb8761fcce Initial load
duke
parents:
diff changeset
  2367
             }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2368
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2369
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2370
}
02bb8761fcce Initial load
duke
parents:
diff changeset
  2371
02bb8761fcce Initial load
duke
parents:
diff changeset
  2372
// End of file.