jdk/src/java.rmi/share/classes/sun/rmi/server/UnicastServerRef.java
author chegar
Sun, 17 Aug 2014 15:54:13 +0100
changeset 25859 3317bb8137f4
parent 23333 jdk/src/share/classes/sun/rmi/server/UnicastServerRef.java@b0af2c7c8c91
child 37584 0cc00d7a0755
permissions -rw-r--r--
8054834: Modular Source Code Reviewed-by: alanb, chegar, ihse, mduigou Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, chris.hegarty@oracle.com, erik.joelsson@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, magnus.ihse.bursie@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, paul.sandoz@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
19211
32a04c562026 8022440: suppress deprecation warnings in sun.rmi
smarks
parents: 14342
diff changeset
     2
 * Copyright (c) 1996, 2013, 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.io.PrintStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.lang.reflect.InvocationTargetException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.lang.reflect.Method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.rmi.MarshalException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.rmi.Remote;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.rmi.RemoteException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.rmi.ServerError;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.rmi.ServerException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.rmi.UnmarshalException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.rmi.server.ExportException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.rmi.server.RemoteCall;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.rmi.server.RemoteRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.rmi.server.RemoteStub;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.rmi.server.ServerNotActiveException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.rmi.server.ServerRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.rmi.server.Skeleton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.rmi.server.SkeletonNotFoundException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import java.security.PrivilegedAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import java.util.Collections;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import java.util.Date;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import java.util.WeakHashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
import sun.rmi.runtime.Log;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
import sun.rmi.transport.LiveRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
import sun.rmi.transport.Target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
import sun.rmi.transport.tcp.TCPTransport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * UnicastServerRef implements the remote reference layer server-side
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * behavior for remote objects exported with the "UnicastRef" reference
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * @author  Ann Wollrath
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * @author  Roger Riggs
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * @author  Peter Jones
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 */
19211
32a04c562026 8022440: suppress deprecation warnings in sun.rmi
smarks
parents: 14342
diff changeset
    69
@SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
public class UnicastServerRef extends UnicastRef
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    implements ServerRef, Dispatcher
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    /** value of server call log property */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    public static final boolean logCalls = AccessController.doPrivileged(
23333
b0af2c7c8c91 8035808: Eliminate dependency to GetPropertyAction and other sun.security.action convenient classes
mchung
parents: 21655
diff changeset
    75
        (PrivilegedAction<Boolean>) () -> Boolean.getBoolean("java.rmi.server.logCalls"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    /** server call log */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    public static final Log callLog =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        Log.getLog("sun.rmi.server.call", "RMI", logCalls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    // use serialVersionUID from JDK 1.2.2 for interoperability
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    private static final long serialVersionUID = -7384275867073752268L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    /** flag to enable writing exceptions to System.err */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    private static final boolean wantExceptionLog =
23333
b0af2c7c8c91 8035808: Eliminate dependency to GetPropertyAction and other sun.security.action convenient classes
mchung
parents: 21655
diff changeset
    86
        AccessController.doPrivileged((PrivilegedAction<Boolean>) () ->
b0af2c7c8c91 8035808: Eliminate dependency to GetPropertyAction and other sun.security.action convenient classes
mchung
parents: 21655
diff changeset
    87
            Boolean.getBoolean("sun.rmi.server.exceptionTrace"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    private boolean forceStubUse = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * flag to remove server-side stack traces before marshalling
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * exceptions thrown by remote invocations to this VM
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    private static final boolean suppressStackTraces =
23333
b0af2c7c8c91 8035808: Eliminate dependency to GetPropertyAction and other sun.security.action convenient classes
mchung
parents: 21655
diff changeset
    96
        AccessController.doPrivileged((PrivilegedAction<Boolean>) () ->
b0af2c7c8c91 8035808: Eliminate dependency to GetPropertyAction and other sun.security.action convenient classes
mchung
parents: 21655
diff changeset
    97
            Boolean.getBoolean("sun.rmi.server.suppressStackTraces"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * skeleton to dispatch remote calls through, for 1.1 stub protocol
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * (may be null if stub class only uses 1.2 stub protocol)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    private transient Skeleton skel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    /** maps method hash to Method object for each remote method */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    private transient Map<Long,Method> hashToMethod_Map = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * A weak hash map, mapping classes to hash maps that map method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * hashes to method objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    private static final WeakClassHashMap<Map<Long,Method>> hashToMethod_Maps =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        new HashToMethod_Maps();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    /** cache of impl classes that have no corresponding skeleton class */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    private static final Map<Class<?>,?> withoutSkeletons =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        Collections.synchronizedMap(new WeakHashMap<Class<?>,Void>());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * Create a new (empty) Unicast server remote reference.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    public UnicastServerRef() {
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
     * Construct a Unicast server remote reference for a specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * liveRef.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    public UnicastServerRef(LiveRef ref) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        super(ref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * Construct a Unicast server remote reference to be exported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * on the specified port.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    public UnicastServerRef(int port) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        super(new LiveRef(port));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * Constructs a UnicastServerRef to be exported on an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * anonymous port (i.e., 0) and that uses a pregenerated stub class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * (NOT a dynamic proxy instance) if 'forceStubUse' is 'true'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * This constructor is only called by the method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * UnicastRemoteObject.exportObject(Remote) passing 'true' for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * 'forceStubUse'.  The UnicastRemoteObject.exportObject(Remote) method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * returns RemoteStub, so it must ensure that the stub for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * exported object is an instance of a pregenerated stub class that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * extends RemoteStub (instead of an instance of a dynamic proxy class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * which is not an instance of RemoteStub).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    public UnicastServerRef(boolean forceStubUse) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        this(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        this.forceStubUse = forceStubUse;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * With the addition of support for dynamic proxies as stubs, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * method is obsolete because it returns RemoteStub instead of the more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * general Remote.  It should not be called.  It sets the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * 'forceStubUse' flag to true so that the stub for the exported object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * is forced to be an instance of the pregenerated stub class, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * extends RemoteStub.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * Export this object, create the skeleton and stubs for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * dispatcher.  Create a stub based on the type of the impl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * initialize it with the appropriate remote reference. Create the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * target defined by the impl, dispatcher (this) and stub.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * Export that target via the Ref.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    public RemoteStub exportObject(Remote impl, Object data)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        throws RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        forceStubUse = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        return (RemoteStub) exportObject(impl, data, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * Export this object, create the skeleton and stubs for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * dispatcher.  Create a stub based on the type of the impl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * initialize it with the appropriate remote reference. Create the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * target defined by the impl, dispatcher (this) and stub.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * Export that target via the Ref.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    public Remote exportObject(Remote impl, Object data,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                               boolean permanent)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        throws RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    {
12040
558b0e0d5910 7146763: Warnings cleanup in the sun.rmi and related packages
khazra
parents: 10912
diff changeset
   191
        Class<?> implClass = impl.getClass();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        Remote stub;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            stub = Util.createProxy(implClass, getClientRef(), forceStubUse);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        } catch (IllegalArgumentException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            throw new ExportException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                "remote object implements illegal remote interface", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        if (stub instanceof RemoteStub) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            setSkeleton(impl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        Target target =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            new Target(impl, this, stub, ref.getObjID(), permanent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        ref.exportObject(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        hashToMethod_Map = hashToMethod_Maps.get(implClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        return stub;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * Return the hostname of the current client.  When called from a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * thread actively handling a remote method invocation the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * hostname of the client is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * @exception ServerNotActiveException If called outside of servicing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * a remote method invocation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    public String getClientHost() throws ServerNotActiveException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        return TCPTransport.getClientHost();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * Discovers and sets the appropriate skeleton for the impl.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    public void setSkeleton(Remote impl) throws RemoteException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        if (!withoutSkeletons.containsKey(impl.getClass())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                skel = Util.createSkeleton(impl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            } catch (SkeletonNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                 * Ignore exception for skeleton class not found, because a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                 * skeleton class is not necessary with the 1.2 stub protocol.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                 * Remember that this impl's class does not have a skeleton
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                 * class so we don't waste time searching for it again.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                withoutSkeletons.put(impl.getClass(), null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * Call to dispatch to the remote object (on the server side).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * The up-call to the server and the marshalling of return result
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * (or exception) should be handled before returning from this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * @param obj the target remote object for the call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * @param call the "remote call" from which operation and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * method arguments can be obtained.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * @exception IOException If unable to marshal return result or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * release input or output streams
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    public void dispatch(Remote obj, RemoteCall call) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        // positive operation number in 1.1 stubs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        // negative version number in 1.2 stubs and beyond...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        int num;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        long op;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            // read remote call header
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            ObjectInput in;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                in = call.getInputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                num = in.readInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                if (num >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                    if (skel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                        oldDispatch(obj, call, num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                        throw new UnmarshalException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                            "skeleton class not found but required " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                            "for client version");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                op = in.readLong();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            } catch (Exception readEx) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                throw new UnmarshalException("error unmarshalling call header",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                                             readEx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
             * Since only system classes (with null class loaders) will be on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
             * the execution stack during parameter unmarshalling for the 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
             * stub protocol, tell the MarshalInputStream not to bother trying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
             * to resolve classes using its superclasses's default method of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
             * consulting the first non-null class loader on the stack.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            MarshalInputStream marshalStream = (MarshalInputStream) in;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            marshalStream.skipDefaultResolveClass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            Method method = hashToMethod_Map.get(op);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            if (method == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                throw new UnmarshalException("unrecognized method hash: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                    "method not supported by remote object");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            // if calls are being logged, write out object id and operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            logCall(obj, method);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            // unmarshal parameters
21655
55f32ae4f920 8028229: Fix more raw types lint warning in core libraries
darcy
parents: 19211
diff changeset
   300
            Class<?>[] types = method.getParameterTypes();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            Object[] params = new Object[types.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                unmarshalCustomCallData(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                for (int i = 0; i < types.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                    params[i] = unmarshalValue(types[i], in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            } catch (java.io.IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                throw new UnmarshalException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                    "error unmarshalling arguments", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            } catch (ClassNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                throw new UnmarshalException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                    "error unmarshalling arguments", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                call.releaseInputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            // make upcall on remote object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            Object result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                result = method.invoke(obj, params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            } catch (InvocationTargetException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                throw e.getTargetException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            // marshal return value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                ObjectOutput out = call.getResultStream(true);
12040
558b0e0d5910 7146763: Warnings cleanup in the sun.rmi and related packages
khazra
parents: 10912
diff changeset
   329
                Class<?> rtype = method.getReturnType();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                if (rtype != void.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                    marshalValue(rtype, result, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            } catch (IOException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                throw new MarshalException("error marshalling return", ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                 * This throw is problematic because when it is caught below,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                 * we attempt to marshal it back to the client, but at this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                 * point, a "normal return" has already been indicated,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                 * so marshalling an exception will corrupt the stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                 * This was the case with skeletons as well; there is no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                 * immediately obvious solution without a protocol change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        } catch (Throwable e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            logCallException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            ObjectOutput out = call.getResultStream(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            if (e instanceof Error) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                e = new ServerError(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                    "Error occurred in server thread", (Error) e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            } else if (e instanceof RemoteException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                e = new ServerException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                    "RemoteException occurred in server thread",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                    (Exception) e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            if (suppressStackTraces) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                clearStackTraces(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            out.writeObject(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            call.releaseInputStream(); // in case skeleton doesn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            call.releaseOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    protected void unmarshalCustomCallData(ObjectInput in)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        throws IOException, ClassNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * Handle server-side dispatch using the RMI 1.1 stub/skeleton
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * protocol, given a non-negative operation number that has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * already been read from the call stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * @param obj the target remote object for the call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * @param call the "remote call" from which operation and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * method arguments can be obtained.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * @param op the operation number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * @exception IOException if unable to marshal return result or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * release input or output streams
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    public void oldDispatch(Remote obj, RemoteCall call, int op)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        long hash;              // hash for matching stub with skeleton
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            // read remote call header
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            ObjectInput in;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                in = call.getInputStream();
10912
4f21298dca19 7077466: fix for RMI DGC
smarks
parents: 5506
diff changeset
   392
                try {
4f21298dca19 7077466: fix for RMI DGC
smarks
parents: 5506
diff changeset
   393
                    Class<?> clazz = Class.forName("sun.rmi.transport.DGCImpl_Skel");
4f21298dca19 7077466: fix for RMI DGC
smarks
parents: 5506
diff changeset
   394
                    if (clazz.isAssignableFrom(skel.getClass())) {
4f21298dca19 7077466: fix for RMI DGC
smarks
parents: 5506
diff changeset
   395
                        ((MarshalInputStream)in).useCodebaseOnly();
4f21298dca19 7077466: fix for RMI DGC
smarks
parents: 5506
diff changeset
   396
                    }
4f21298dca19 7077466: fix for RMI DGC
smarks
parents: 5506
diff changeset
   397
                } catch (ClassNotFoundException ignore) { }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                hash = in.readLong();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            } catch (Exception readEx) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                throw new UnmarshalException("error unmarshalling call header",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                                             readEx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            // if calls are being logged, write out object id and operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            logCall(obj, skel.getOperations()[op]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            unmarshalCustomCallData(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            // dispatch to skeleton for remote object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            skel.dispatch(obj, call, op, hash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        } catch (Throwable e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            logCallException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            ObjectOutput out = call.getResultStream(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            if (e instanceof Error) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                e = new ServerError(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                    "Error occurred in server thread", (Error) e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            } else if (e instanceof RemoteException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                e = new ServerException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                    "RemoteException occurred in server thread",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                    (Exception) e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            if (suppressStackTraces) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                clearStackTraces(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            out.writeObject(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            call.releaseInputStream(); // in case skeleton doesn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            call.releaseOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * Clear the stack trace of the given Throwable by replacing it with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * an empty StackTraceElement array, and do the same for all of its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * chained causative exceptions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    public static void clearStackTraces(Throwable t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        StackTraceElement[] empty = new StackTraceElement[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        while (t != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            t.setStackTrace(empty);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            t = t.getCause();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * Log the details of an incoming call.  The method parameter is either of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * type java.lang.reflect.Method or java.rmi.server.Operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    private void logCall(Remote obj, Object method) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        if (callLog.isLoggable(Log.VERBOSE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            String clientHost;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                clientHost = getClientHost();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            } catch (ServerNotActiveException snae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                clientHost = "(local)"; // shouldn't happen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            callLog.log(Log.VERBOSE, "[" + clientHost + ": " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                              obj.getClass().getName() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                              ref.getObjID().toString() + ": " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                              method + "]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * Log the exception detail of an incoming call.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    private void logCallException(Throwable e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        // if calls are being logged, log them
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        if (callLog.isLoggable(Log.BRIEF)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            String clientHost = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                clientHost = "[" + getClientHost() + "] ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            } catch (ServerNotActiveException snae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            callLog.log(Log.BRIEF, clientHost + "exception: ", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        // write exceptions (only) to System.err if desired
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        if (wantExceptionLog) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            java.io.PrintStream log = System.err;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            synchronized (log) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                log.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                log.println("Exception dispatching call to " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                            ref.getObjID() + " in thread \"" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                            Thread.currentThread().getName() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                            "\" at " + (new Date()) + ":");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                e.printStackTrace(log);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        }
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
     * Returns the class of the ref type to be serialized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    public String getRefClass(ObjectOutput out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        return "UnicastServerRef";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * Return the client remote reference for this remoteRef.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * In the case of a client RemoteRef "this" is the answer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * For a server remote reference, a client side one will have to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * found or created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    protected RemoteRef getClientRef() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        return new UnicastRef(ref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * Write out external representation for remote ref.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    public void writeExternal(ObjectOutput out) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * Read in external representation for remote ref.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * @exception ClassNotFoundException If the class for an object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * being restored cannot be found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
    public void readExternal(ObjectInput in)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        throws IOException, ClassNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        // object is re-exported elsewhere (e.g., by UnicastRemoteObject)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        ref = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        skel = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     * A weak hash map, mapping classes to hash maps that map method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * hashes to method objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    private static class HashToMethod_Maps
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        extends WeakClassHashMap<Map<Long,Method>>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        HashToMethod_Maps() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        protected Map<Long,Method> computeValue(Class<?> remoteClass) {
12040
558b0e0d5910 7146763: Warnings cleanup in the sun.rmi and related packages
khazra
parents: 10912
diff changeset
   539
            Map<Long,Method> map = new HashMap<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            for (Class<?> cl = remoteClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                 cl != null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                 cl = cl.getSuperclass())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                for (Class<?> intf : cl.getInterfaces()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                    if (Remote.class.isAssignableFrom(intf)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                        for (Method method : intf.getMethods()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                            final Method m = method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                             * Set this Method object to override language
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                             * access checks so that the dispatcher can invoke
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                             * methods from non-public remote interfaces.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                            AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                                new PrivilegedAction<Void>() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                                public Void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                                    m.setAccessible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                            map.put(Util.computeMethodHash(m), m);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
            return map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
}