src/java.rmi/share/classes/sun/rmi/server/UnicastRef.java
author rehn
Fri, 29 Nov 2019 12:09:25 +0100
changeset 59325 3636bab5e81e
parent 47216 71c04702a3d5
permissions -rw-r--r--
8234086: VM operation can be simplified Reviewed-by: kbarrett, dholmes, dcubed
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.server;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.ObjectInput;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.ObjectOutput;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.lang.reflect.Method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.rmi.MarshalException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.rmi.Remote;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.rmi.RemoteException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.rmi.UnmarshalException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.rmi.server.Operation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.rmi.server.RemoteCall;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.rmi.server.RemoteObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.rmi.server.RemoteRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.security.AccessController;
23333
b0af2c7c8c91 8035808: Eliminate dependency to GetPropertyAction and other sun.security.action convenient classes
mchung
parents: 19211
diff changeset
    41
import java.security.PrivilegedAction;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import sun.rmi.runtime.Log;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import sun.rmi.transport.Connection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import sun.rmi.transport.LiveRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import sun.rmi.transport.StreamRemoteCall;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * NOTE: There is a JDK-internal dependency on the existence of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * class's getLiveRef method (as it is inherited by UnicastRef2) in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * the implementation of javax.management.remote.rmi.RMIConnector.
19211
32a04c562026 8022440: suppress deprecation warnings in sun.rmi
smarks
parents: 14342
diff changeset
    51
 */
32a04c562026 8022440: suppress deprecation warnings in sun.rmi
smarks
parents: 14342
diff changeset
    52
@SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
public class UnicastRef implements RemoteRef {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * Client-side transport log.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    public static final Log clientRefLog =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        Log.getLog("sun.rmi.client.ref", "transport",  Util.logLevel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * Client-side call log.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    public static final Log clientCallLog =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        Log.getLog("sun.rmi.client.call", "RMI",
23333
b0af2c7c8c91 8035808: Eliminate dependency to GetPropertyAction and other sun.security.action convenient classes
mchung
parents: 19211
diff changeset
    66
                   AccessController.doPrivileged((PrivilegedAction<Boolean>) () ->
b0af2c7c8c91 8035808: Eliminate dependency to GetPropertyAction and other sun.security.action convenient classes
mchung
parents: 19211
diff changeset
    67
                       Boolean.getBoolean("sun.rmi.client.logCalls")));
12040
558b0e0d5910 7146763: Warnings cleanup in the sun.rmi and related packages
khazra
parents: 5506
diff changeset
    68
    private static final long serialVersionUID = 8258372400816541186L;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    protected LiveRef ref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * Create a new (empty) Unicast remote reference.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    public UnicastRef() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * Create a new Unicast RemoteRef.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    public UnicastRef(LiveRef liveRef) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        ref = liveRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * Returns the current value of this UnicastRef's underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * LiveRef.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * NOTE: There is a JDK-internal dependency on the existence of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * this method (as it is inherited by UnicastRef) in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * implementation of javax.management.remote.rmi.RMIConnector.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    public LiveRef getLiveRef() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        return ref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * Invoke a method. This form of delegating method invocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * to the reference allows the reference to take care of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * setting up the connection to the remote host, marshalling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * some representation for the method and parameters, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * communicating the method invocation to the remote host.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * This method either returns the result of a method invocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * on the remote object which resides on the remote host or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * throws a RemoteException if the call failed or an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * application-level exception if the remote invocation throws
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * an exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * @param obj the proxy for the remote object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * @param method the method to be invoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * @param params the parameter list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * @param opnum  a hash that may be used to represent the method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    public Object invoke(Remote obj,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                         Method method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                         Object[] params,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                         long opnum)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        throws Exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        if (clientRefLog.isLoggable(Log.VERBOSE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            clientRefLog.log(Log.VERBOSE, "method: " + method);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        if (clientCallLog.isLoggable(Log.VERBOSE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            logClientCall(obj, method);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        Connection conn = ref.getChannel().newConnection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        RemoteCall call = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        boolean reuse = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        /* If the call connection is "reused" early, remember not to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
         * reuse again.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        boolean alreadyFreed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            if (clientRefLog.isLoggable(Log.VERBOSE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                clientRefLog.log(Log.VERBOSE, "opnum = " + opnum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            // create call context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            call = new StreamRemoteCall(conn, ref.getObjID(), -1, opnum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            // marshal parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                ObjectOutput out = call.getOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                marshalCustomCallData(out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                Class<?>[] types = method.getParameterTypes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                for (int i = 0; i < types.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                    marshalValue(types[i], params[i], out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                clientRefLog.log(Log.BRIEF,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                    "IOException marshalling arguments: ", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                throw new MarshalException("error marshalling arguments", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            // unmarshal return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            call.executeCall();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                Class<?> rtype = method.getReturnType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                if (rtype == void.class)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                ObjectInput in = call.getInputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                /* StreamRemoteCall.done() does not actually make use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                 * of conn, therefore it is safe to reuse this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                 * connection before the dirty call is sent for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                 * registered refs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                Object returnValue = unmarshalValue(rtype, in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                /* we are freeing the connection now, do not free
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                 * again or reuse.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                alreadyFreed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                /* if we got to this point, reuse must have been true. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                clientRefLog.log(Log.BRIEF, "free connection (reuse = true)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                /* Free the call's connection early. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                ref.getChannel().free(conn, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                return returnValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
45984
75fef64e21fa 8163958: Improved garbage collection
rriggs
parents: 25859
diff changeset
   189
            } catch (IOException | ClassNotFoundException e) {
75fef64e21fa 8163958: Improved garbage collection
rriggs
parents: 25859
diff changeset
   190
                // disable saving any refs in the inputStream for GC
75fef64e21fa 8163958: Improved garbage collection
rriggs
parents: 25859
diff changeset
   191
                ((StreamRemoteCall)call).discardPendingRefs();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                clientRefLog.log(Log.BRIEF,
45984
75fef64e21fa 8163958: Improved garbage collection
rriggs
parents: 25859
diff changeset
   193
                                 e.getClass().getName() + " unmarshalling return: ", e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                throw new UnmarshalException("error unmarshalling return", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                    call.done();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                    /* WARNING: If the conn has been reused early,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                     * then it is too late to recover from thrown
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                     * IOExceptions caught here. This code is relying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                     * on StreamRemoteCall.done() not actually
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                     * throwing IOExceptions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                    reuse = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        } catch (RuntimeException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
             * Need to distinguish between client (generated by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
             * invoke method itself) and server RuntimeExceptions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
             * Client side RuntimeExceptions are likely to have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
             * corrupted the call connection and those from the server
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
             * are not likely to have done so.  If the exception came
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
             * from the server the call connection should be reused.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            if ((call == null) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                (((StreamRemoteCall) call).getServerException() != e))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                reuse = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            throw e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        } catch (RemoteException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
             * Some failure during call; assume connection cannot
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
             * be reused.  Must assume failure even if ServerException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
             * or ServerError occurs since these failures can happen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
             * during parameter deserialization which would leave
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
             * the connection in a corrupted state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            reuse = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            throw e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        } catch (Error e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            /* If errors occurred, the connection is most likely not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
             *  reusable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            reuse = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            throw e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            /* alreadyFreed ensures that we do not log a reuse that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
             * may have already happened.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            if (!alreadyFreed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                if (clientRefLog.isLoggable(Log.BRIEF)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                    clientRefLog.log(Log.BRIEF, "free connection (reuse = " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                                           reuse + ")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                ref.getChannel().free(conn, reuse);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    protected void marshalCustomCallData(ObjectOutput out) throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * Marshal value to an ObjectOutput sink using RMI's serialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * format for parameters or return values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    protected static void marshalValue(Class<?> type, Object value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                                       ObjectOutput out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        if (type.isPrimitive()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            if (type == int.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                out.writeInt(((Integer) value).intValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            } else if (type == boolean.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                out.writeBoolean(((Boolean) value).booleanValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            } else if (type == byte.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                out.writeByte(((Byte) value).byteValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            } else if (type == char.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                out.writeChar(((Character) value).charValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            } else if (type == short.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                out.writeShort(((Short) value).shortValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            } else if (type == long.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                out.writeLong(((Long) value).longValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            } else if (type == float.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                out.writeFloat(((Float) value).floatValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            } else if (type == double.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                out.writeDouble(((Double) value).doubleValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                throw new Error("Unrecognized primitive type: " + type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            out.writeObject(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * Unmarshal value from an ObjectInput source using RMI's serialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * format for parameters or return values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    protected static Object unmarshalValue(Class<?> type, ObjectInput in)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        throws IOException, ClassNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        if (type.isPrimitive()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            if (type == int.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                return Integer.valueOf(in.readInt());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            } else if (type == boolean.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                return Boolean.valueOf(in.readBoolean());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            } else if (type == byte.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                return Byte.valueOf(in.readByte());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            } else if (type == char.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                return Character.valueOf(in.readChar());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            } else if (type == short.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                return Short.valueOf(in.readShort());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            } else if (type == long.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                return Long.valueOf(in.readLong());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            } else if (type == float.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                return Float.valueOf(in.readFloat());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            } else if (type == double.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                return Double.valueOf(in.readDouble());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                throw new Error("Unrecognized primitive type: " + type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            return in.readObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * Create an appropriate call object for a new call on this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * Passing operation array and index, allows the stubs generator to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * assign the operation indexes and interpret them. The RemoteRef
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * may need the operation to encode in for the call.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    public RemoteCall newCall(RemoteObject obj, Operation[] ops, int opnum,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                              long hash)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        throws RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        clientRefLog.log(Log.BRIEF, "get connection");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        Connection conn = ref.getChannel().newConnection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            clientRefLog.log(Log.VERBOSE, "create call context");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            /* log information about the outgoing call */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            if (clientCallLog.isLoggable(Log.VERBOSE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                logClientCall(obj, ops[opnum]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            RemoteCall call =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                new StreamRemoteCall(conn, ref.getObjID(), opnum, hash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                marshalCustomCallData(call.getOutputStream());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                throw new MarshalException("error marshaling " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                                           "custom call data");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            return call;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        } catch (RemoteException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            ref.getChannel().free(conn, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            throw e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * Invoke makes the remote call present in the RemoteCall object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * Invoke will raise any "user" exceptions which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * should pass through and not be caught by the stub.  If any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * exception is raised during the remote invocation, invoke should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * take care of cleaning up the connection before raising the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * "user" or remote exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    public void invoke(RemoteCall call) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            clientRefLog.log(Log.VERBOSE, "execute call");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            call.executeCall();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        } catch (RemoteException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
             * Call did not complete; connection can't be reused.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            clientRefLog.log(Log.BRIEF, "exception: ", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            free(call, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            throw e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        } catch (Error e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            /* If errors occurred, the connection is most likely not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
             *  reusable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            clientRefLog.log(Log.BRIEF, "error: ", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            free(call, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            throw e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        } catch (RuntimeException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
             * REMIND: Since runtime exceptions are no longer wrapped,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
             * we can't assue that the connection was left in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
             * a reusable state. Is this okay?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            clientRefLog.log(Log.BRIEF, "exception: ", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            free(call, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            throw e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
             * Assume that these other exceptions are user exceptions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
             * and leave the connection in a reusable state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            clientRefLog.log(Log.BRIEF, "exception: ", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            free(call, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            /* reraise user (and unknown) exceptions. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            throw e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
         * Don't free the connection if an exception did not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
         * occur because the stub needs to unmarshal the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
         * return value. The connection will be freed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
         * by a call to the "done" method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * Private method to free a connection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    private void free(RemoteCall call, boolean reuse) throws RemoteException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        Connection conn = ((StreamRemoteCall)call).getConnection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        ref.getChannel().free(conn, reuse);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     * Done should only be called if the invoke returns successfully
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * (non-exceptionally) to the stub. It allows the remote reference to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * clean up (or reuse) the connection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    public void done(RemoteCall call) throws RemoteException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        /* Done only uses the connection inside the call to obtain the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
         * channel the connection uses.  Once all information is read
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
         * from the connection, the connection may be freed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        clientRefLog.log(Log.BRIEF, "free connection (reuse = true)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        /* Free the call connection early. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        free(call, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            call.done();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            /* WARNING: If the conn has been reused early, then it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
             * too late to recover from thrown IOExceptions caught
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
             * here. This code is relying on StreamRemoteCall.done()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
             * not actually throwing IOExceptions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * Log the details of an outgoing call.  The method parameter is either of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * type java.lang.reflect.Method or java.rmi.server.Operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    void logClientCall(Object obj, Object method) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        clientCallLog.log(Log.VERBOSE, "outbound call: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            ref + " : " + obj.getClass().getName() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
            ref.getObjID().toString() + ": " + method);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * Returns the class of the ref type to be serialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    public String getRefClass(ObjectOutput out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        return "UnicastRef";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     * Write out external representation for remote ref.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    public void writeExternal(ObjectOutput out) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        ref.write(out, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * Read in external representation for remote ref.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * @exception ClassNotFoundException If the class for an object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * being restored cannot be found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    public void readExternal(ObjectInput in)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        throws IOException, ClassNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        ref = LiveRef.read(in, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    //----------------------------------------------------------------------;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     * Method from object, forward from RemoteObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    public String remoteToString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        return Util.getUnqualifiedName(getClass()) + " [liveRef: " + ref + "]";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * default implementation of hashCode for remote objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    public int remoteHashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        return ref.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    /** default implementation of equals for remote objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    public boolean remoteEquals(RemoteRef sub) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        if (sub instanceof UnicastRef)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
            return ref.remoteEquals(((UnicastRef)sub).ref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
}