src/java.rmi/share/classes/sun/rmi/transport/StreamRemoteCall.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 45984 jdk/src/java.rmi/share/classes/sun/rmi/transport/StreamRemoteCall.java@75fef64e21fa
child 58635 06d7236d6ef6
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
45984
75fef64e21fa 8163958: Improved garbage collection
rriggs
parents: 25859
diff changeset
     2
 * Copyright (c) 1996, 2017, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.rmi.transport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.DataInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.DataOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.ObjectInput;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.io.ObjectOutput;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.io.StreamCorruptedException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.rmi.RemoteException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.rmi.MarshalException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.rmi.UnmarshalException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.rmi.server.ObjID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.rmi.server.RemoteCall;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import sun.rmi.runtime.Log;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import sun.rmi.server.UnicastRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import sun.rmi.transport.tcp.TCPEndpoint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * Stream-based implementation of the RemoteCall interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * @author Ann Wollrath
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 */
19211
32a04c562026 8022440: suppress deprecation warnings in sun.rmi
smarks
parents: 14342
diff changeset
    48
@SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
public class StreamRemoteCall implements RemoteCall {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    private ConnectionInputStream in = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private ConnectionOutputStream out = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    private Connection conn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    private boolean resultStarted = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    private Exception serverException = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    public StreamRemoteCall(Connection c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        conn = c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    public StreamRemoteCall(Connection c, ObjID id, int op, long hash)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        throws RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
            conn = c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            Transport.transportLog.log(Log.VERBOSE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
                "write remote call header...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            // write out remote call header info...
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            // call header, part 1 (read by Transport)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            conn.getOutputStream().write(TransportConstants.Call);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            getOutputStream();           // creates a MarshalOutputStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            id.write(out);               // object id (target of call)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            // call header, part 2 (read by Dispatcher)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            out.writeInt(op);            // method number (operation index)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            out.writeLong(hash);         // stub/skeleton hash
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            throw new MarshalException("Error marshaling call header", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * Return the connection associated with this call.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    public Connection getConnection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        return conn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * Return the output stream the stub/skeleton should put arguments/results
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * into.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    public ObjectOutput getOutputStream() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        return getOutputStream(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    private ObjectOutput getOutputStream(boolean resultStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        if (out == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            Transport.transportLog.log(Log.VERBOSE, "getting output stream");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            out = new ConnectionOutputStream(conn, resultStream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        return out;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * Release the outputStream  Currently, will not complain if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * output stream is released more than once.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    public void releaseOutputStream() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            if (out != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                    out.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                    out.done();         // always start DGC ack timer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            conn.releaseOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            out = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * Get the InputStream the stub/skeleton should get results/arguments
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * from.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    public ObjectInput getInputStream() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        if (in == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            Transport.transportLog.log(Log.VERBOSE, "getting input stream");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            in = new ConnectionInputStream(conn.getInputStream());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        return in;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * Release the input stream, this would allow some transports to release
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * the channel early.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    public void releaseInputStream() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        /* WARNING: Currently, the UnicastRef.java invoke methods rely
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
         * upon this method not throwing an IOException.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            if (in != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                // execute MarshalInputStream "done" callbacks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                    in.done();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                } catch (RuntimeException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                // add saved references to DGC table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                in.registerRefs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                /* WARNING: The connection being passed to done may have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                 * already been freed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                in.done(conn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            conn.releaseInputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            in = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    /**
45984
75fef64e21fa 8163958: Improved garbage collection
rriggs
parents: 25859
diff changeset
   171
     * Discard any post-processing of refs the InputStream.
75fef64e21fa 8163958: Improved garbage collection
rriggs
parents: 25859
diff changeset
   172
     */
75fef64e21fa 8163958: Improved garbage collection
rriggs
parents: 25859
diff changeset
   173
    public void discardPendingRefs() {
75fef64e21fa 8163958: Improved garbage collection
rriggs
parents: 25859
diff changeset
   174
        in.discardRefs();
75fef64e21fa 8163958: Improved garbage collection
rriggs
parents: 25859
diff changeset
   175
    }
75fef64e21fa 8163958: Improved garbage collection
rriggs
parents: 25859
diff changeset
   176
75fef64e21fa 8163958: Improved garbage collection
rriggs
parents: 25859
diff changeset
   177
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * Returns an output stream (may put out header information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * relating to the success of the call).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * @param success If true, indicates normal return, else indicates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * exceptional return.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * @exception StreamCorruptedException If result stream previously
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * acquired
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * @exception IOException For any other problem with I/O.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    public ObjectOutput getResultStream(boolean success) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        /* make sure result code only marshaled once. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        if (resultStarted)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            throw new StreamCorruptedException("result already in progress");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            resultStarted = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        // write out return header
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        // return header, part 1 (read by Transport)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        DataOutputStream wr = new DataOutputStream(conn.getOutputStream());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        wr.writeByte(TransportConstants.Return);// transport op
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        getOutputStream(true);  // creates a MarshalOutputStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        // return header, part 2 (read by client-side RemoteCall)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        if (success)            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            out.writeByte(TransportConstants.NormalReturn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            out.writeByte(TransportConstants.ExceptionalReturn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        out.writeID();          // write id for gcAck
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        return out;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * Do whatever it takes to execute the call.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     */
12040
558b0e0d5910 7146763: Warnings cleanup in the sun.rmi and related packages
khazra
parents: 5506
diff changeset
   210
    @SuppressWarnings("fallthrough")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    public void executeCall() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        byte returnType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        // read result header
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        DGCAckHandler ackHandler = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            if (out != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                ackHandler = out.getDGCAckHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            releaseOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            DataInputStream rd = new DataInputStream(conn.getInputStream());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            byte op = rd.readByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            if (op != TransportConstants.Return) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                if (Transport.transportLog.isLoggable(Log.BRIEF)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                    Transport.transportLog.log(Log.BRIEF,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                        "transport return code invalid: " + op);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                throw new UnmarshalException("Transport return code invalid");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            getInputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            returnType = in.readByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            in.readID();        // id for DGC acknowledgement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        } catch (UnmarshalException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            throw e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            throw new UnmarshalException("Error unmarshaling return header",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                                         e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            if (ackHandler != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                ackHandler.release();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        // read return value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        switch (returnType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        case TransportConstants.NormalReturn:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        case TransportConstants.ExceptionalReturn:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            Object ex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                ex = in.readObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                throw new UnmarshalException("Error unmarshaling return", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            // An exception should have been received,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            // if so throw it, else flag error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            if (ex instanceof Exception) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                exceptionReceivedFromServer((Exception) ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                throw new UnmarshalException("Return type not Exception");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            }
12040
558b0e0d5910 7146763: Warnings cleanup in the sun.rmi and related packages
khazra
parents: 5506
diff changeset
   264
            // Exception is thrown before fallthrough can occur
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            if (Transport.transportLog.isLoggable(Log.BRIEF)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                Transport.transportLog.log(Log.BRIEF,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                    "return code invalid: " + returnType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            throw new UnmarshalException("Return code invalid");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * Routine that causes the stack traces of remote exceptions to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * filled in with the current stack trace on the client.  Detail
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * exceptions are filled in iteratively.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    protected void exceptionReceivedFromServer(Exception ex) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        serverException = ex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        StackTraceElement[] serverTrace = ex.getStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        StackTraceElement[] clientTrace = (new Throwable()).getStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        StackTraceElement[] combinedTrace =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            new StackTraceElement[serverTrace.length + clientTrace.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        System.arraycopy(serverTrace, 0, combinedTrace, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                         serverTrace.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        System.arraycopy(clientTrace, 0, combinedTrace, serverTrace.length,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                         clientTrace.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        ex.setStackTrace(combinedTrace);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
         * Log the details of a server exception thrown as a result of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
         * remote method invocation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        if (UnicastRef.clientCallLog.isLoggable(Log.BRIEF)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            /* log call exception returned from server before it is rethrown */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            TCPEndpoint ep = (TCPEndpoint) conn.getChannel().getEndpoint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            UnicastRef.clientCallLog.log(Log.BRIEF, "outbound call " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                "received exception: [" + ep.getHost() + ":" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                ep.getPort() + "] exception: ", ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        throw ex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * method to retrieve possible server side exceptions (which will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * be throw from exceptionReceivedFromServer(...) )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    public Exception getServerException() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        return serverException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    public void done() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        /* WARNING: Currently, the UnicastRef.java invoke methods rely
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
         * upon this method not throwing an IOException.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        releaseInputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
}