src/java.rmi/share/classes/sun/rmi/server/ActivationGroupImpl.java
author darcy
Tue, 15 Oct 2019 13:25:57 -0700
changeset 58609 fbfc72ec8e6b
parent 51391 07ea887eee5f
permissions -rw-r--r--
8232234: Suppress warnings on non-serializable non-transient instance fields in java.rmi Reviewed-by: rriggs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
58609
fbfc72ec8e6b 8232234: Suppress warnings on non-serializable non-transient instance fields in java.rmi
darcy
parents: 51391
diff changeset
     2
 * Copyright (c) 1997, 2019, 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.lang.reflect.Constructor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.lang.reflect.InvocationTargetException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.net.ServerSocket;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.rmi.MarshalledObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.rmi.NoSuchObjectException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.rmi.Remote;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.rmi.RemoteException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.rmi.activation.Activatable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.rmi.activation.ActivationDesc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.rmi.activation.ActivationException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.rmi.activation.ActivationGroup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.rmi.activation.ActivationGroupID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.rmi.activation.ActivationID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.rmi.activation.UnknownObjectException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.rmi.server.RMIClassLoader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.rmi.server.RMIServerSocketFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.rmi.server.RMISocketFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.rmi.server.UnicastRemoteObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.security.PrivilegedActionException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import java.security.PrivilegedExceptionAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import java.util.Hashtable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import sun.rmi.registry.RegistryImpl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * The default activation group implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * @author      Ann Wollrath
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * @since       1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * @see         java.rmi.activation.ActivationGroup
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
public class ActivationGroupImpl extends ActivationGroup {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    // use serialVersionUID from JDK 1.2.2 for interoperability
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    private static final long serialVersionUID = 5758693559430427303L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    /** maps persistent IDs to activated remote objects */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    private final Hashtable<ActivationID,ActiveEntry> active =
12040
558b0e0d5910 7146763: Warnings cleanup in the sun.rmi and related packages
khazra
parents: 5506
diff changeset
    69
        new Hashtable<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    private boolean groupInactive = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    private final ActivationGroupID groupID;
58609
fbfc72ec8e6b 8232234: Suppress warnings on non-serializable non-transient instance fields in java.rmi
darcy
parents: 51391
diff changeset
    72
    @SuppressWarnings("serial")  // Conditionally serializable
12040
558b0e0d5910 7146763: Warnings cleanup in the sun.rmi and related packages
khazra
parents: 5506
diff changeset
    73
    private final List<ActivationID> lockedIDs = new ArrayList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * Creates a default activation group implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * @param id the group's identifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * @param data ignored
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    public ActivationGroupImpl(ActivationGroupID id, MarshalledObject<?> data)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        throws RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        super(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        groupID = id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
         * Unexport activation group impl and attempt to export it on
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
         * an unshared anonymous port.  See 4692286.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        unexportObject(this, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        RMIServerSocketFactory ssf = new ServerSocketFactoryImpl();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        UnicastRemoteObject.exportObject(this, 0, null, ssf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        if (System.getSecurityManager() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                // Provide a default security manager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                System.setSecurityManager(new SecurityManager());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                throw new RemoteException("unable to set security manager", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * Trivial server socket factory used to export the activation group
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * impl on an unshared port.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    private static class ServerSocketFactoryImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        implements RMIServerSocketFactory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        public ServerSocket createServerSocket(int port) throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            RMISocketFactory sf = RMISocketFactory.getSocketFactory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            if (sf == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                sf = RMISocketFactory.getDefaultSocketFactory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            return sf.createServerSocket(port);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * Obtains a lock on the ActivationID id before returning. Allows only one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * thread at a time to hold a lock on a particular id.  If the lock for id
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * is in use, all requests for an equivalent (in the Object.equals sense)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * id will wait for the id to be notified and use the supplied id as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * next lock. The caller of "acquireLock" must execute the "releaseLock"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * method" to release the lock and "notifyAll" waiters for the id lock
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * obtained from this method.  The typical usage pattern is as follows:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     *    acquireLock(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     *    // do stuff pertaining to id...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     *    releaseLock(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     *    checkInactiveGroup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    private void acquireLock(ActivationID id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        ActivationID waitForID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        for (;;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            synchronized (lockedIDs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                int index = lockedIDs.indexOf(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                if (index < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                    lockedIDs.add(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                    waitForID = lockedIDs.get(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            synchronized (waitForID) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                synchronized (lockedIDs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                    int index = lockedIDs.indexOf(waitForID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                    if (index < 0) continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                    ActivationID actualID = lockedIDs.get(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                    if (actualID != waitForID)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                         * don't wait on an id that won't be notified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                    waitForID.wait();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                } catch (InterruptedException ignore) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * Releases the id lock obtained via the "acquireLock" method and then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * notifies all threads waiting on the lock.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    private void releaseLock(ActivationID id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        synchronized (lockedIDs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            id = lockedIDs.remove(lockedIDs.indexOf(id));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        synchronized (id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            id.notifyAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * Creates a new instance of an activatable remote object. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * <code>Activator</code> calls this method to create an activatable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * object in this group. This method should be idempotent; a call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * activate an already active object should return the previously
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * activated object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * Note: this method assumes that the Activator will only invoke
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * newInstance for the same object in a serial fashion (i.e.,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * the activator will not allow the group to see concurrent requests
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * to activate the same object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * @param id the object's activation identifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * @param desc the object's activation descriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * @return a marshalled object containing the activated object's stub
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    public MarshalledObject<? extends Remote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                                      newInstance(final ActivationID id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                                                  final ActivationDesc desc)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        throws ActivationException, RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        RegistryImpl.checkAccess("ActivationInstantiator.newInstance");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        if (!groupID.equals(desc.getGroupID()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            throw new ActivationException("newInstance in wrong group");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            acquireLock(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                if (groupInactive == true)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                    throw new InactiveGroupException("group is inactive");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            ActiveEntry entry = active.get(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            if (entry != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                return entry.mobj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            String className = desc.getClassName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            final Class<? extends Remote> cl =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                RMIClassLoader.loadClass(desc.getLocation(), className)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                .asSubclass(Remote.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            Remote impl = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            final Thread t = Thread.currentThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            final ClassLoader savedCcl = t.getContextClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            ClassLoader objcl = cl.getClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            final ClassLoader ccl = covers(objcl, savedCcl) ? objcl : savedCcl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
             * Fix for 4164971: allow non-public activatable class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
             * and/or constructor, create the activatable object in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
             * privileged block
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                 * The code below is in a doPrivileged block to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                 * protect against user code which code might have set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                 * a global socket factory (in which case application
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                 * code would be on the stack).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                impl = AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                      new PrivilegedExceptionAction<Remote>() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                      public Remote run() throws InstantiationException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                          NoSuchMethodException, IllegalAccessException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                          InvocationTargetException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                          Constructor<? extends Remote> constructor =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                              cl.getDeclaredConstructor(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                                  ActivationID.class, MarshalledObject.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                          constructor.setAccessible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                          try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                              /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                               * Fix for 4289544: make sure to set the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                               * context class loader to be the class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                               * loader of the impl class before
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                               * constructing that class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                               */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                              t.setContextClassLoader(ccl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                              return constructor.newInstance(id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                                                             desc.getData());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                          } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                              t.setContextClassLoader(savedCcl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                  });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            } catch (PrivilegedActionException pae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                Throwable e = pae.getException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                // narrow the exception's type and rethrow it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                if (e instanceof InstantiationException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                    throw (InstantiationException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                } else if (e instanceof NoSuchMethodException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                    throw (NoSuchMethodException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                } else if (e instanceof IllegalAccessException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                    throw (IllegalAccessException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                } else if (e instanceof InvocationTargetException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                    throw (InvocationTargetException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                } else if (e instanceof RuntimeException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                    throw (RuntimeException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                } else if (e instanceof Error) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                    throw (Error) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            entry = new ActiveEntry(impl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            active.put(id, entry);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            return entry.mobj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
12040
558b0e0d5910 7146763: Warnings cleanup in the sun.rmi and related packages
khazra
parents: 5506
diff changeset
   300
        } catch (NoSuchMethodException | NoSuchMethodError e) {
558b0e0d5910 7146763: Warnings cleanup in the sun.rmi and related packages
khazra
parents: 5506
diff changeset
   301
            /* user forgot to provide activatable constructor?
558b0e0d5910 7146763: Warnings cleanup in the sun.rmi and related packages
khazra
parents: 5506
diff changeset
   302
             * or code recompiled and user forgot to provide
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
             *  activatable constructor?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            throw new ActivationException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                ("Activatable object must provide an activation"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                 " constructor", e );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        } catch (InvocationTargetException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            throw new ActivationException("exception in object constructor",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                                          e.getTargetException());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            throw new ActivationException("unable to activate object", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            releaseLock(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            checkInactiveGroup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    * The group's <code>inactiveObject</code> method is called
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    * indirectly via a call to the <code>Activatable.inactive</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    * method. A remote object implementation must call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    * <code>Activatable</code>'s <code>inactive</code> method when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    * that object deactivates (the object deems that it is no longer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    * active). If the object does not call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    * <code>Activatable.inactive</code> when it deactivates, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    * object will never be garbage collected since the group keeps
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    * strong references to the objects it creates. <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    * The group's <code>inactiveObject</code> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    * unexports the remote object from the RMI runtime so that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    * object can no longer receive incoming RMI calls. This call will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    * only succeed if the object has no pending/executing calls. If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    * the object does have pending/executing RMI calls, then false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    * will be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    * If the object has no pending/executing calls, the object is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    * removed from the RMI runtime and the group informs its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    * <code>ActivationMonitor</code> (via the monitor's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    * <code>inactiveObject</code> method) that the remote object is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    * not currently active so that the remote object will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    * re-activated by the activator upon a subsequent activation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    * request.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    * @param id the object's activation identifier
30655
d83f50188ca9 8080422: some docs cleanup for core libs
avstepan
parents: 25859
diff changeset
   349
    * @return true if the operation succeeds (the operation will
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    * succeed if the object in currently known to be active and is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    * either already unexported or is currently exported and has no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    * pending/executing calls); false is returned if the object has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    * pending/executing calls in which case it cannot be deactivated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    * @exception UnknownObjectException if object is unknown (may already
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    * be inactive)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    * @exception RemoteException if call informing monitor fails
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    public boolean inactiveObject(ActivationID id)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        throws ActivationException, UnknownObjectException, RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            acquireLock(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                if (groupInactive == true)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                    throw new ActivationException("group is inactive");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            ActiveEntry entry = active.get(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            if (entry == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                // REMIND: should this be silent?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                throw new UnknownObjectException("object not active");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                if (Activatable.unexportObject(entry.impl, false) == false)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            } catch (NoSuchObjectException allowUnexportedObjects) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                super.inactiveObject(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            } catch (UnknownObjectException allowUnregisteredObjects) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            active.remove(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            releaseLock(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            checkInactiveGroup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * Determines if the group has become inactive and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * marks it as such.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    private void checkInactiveGroup() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        boolean groupMarkedInactive = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            if (active.size() == 0 && lockedIDs.size() == 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                groupInactive == false)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                groupInactive = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                groupMarkedInactive = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        if (groupMarkedInactive) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                super.inactiveGroup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            } catch (Exception ignoreDeactivateFailure) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                UnicastRemoteObject.unexportObject(this, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
            } catch (NoSuchObjectException allowUnexportedGroup) {
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * The group's <code>activeObject</code> method is called when an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * object is exported (either by <code>Activatable</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * construction or an explicit call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     * <code>Activatable.exportObject</code>. The group must inform its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * <code>ActivationMonitor</code> that the object is active (via
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     * the monitor's <code>activeObject</code> method) if the group
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     * hasn't already done so.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * @param id the object's identifier
30655
d83f50188ca9 8080422: some docs cleanup for core libs
avstepan
parents: 25859
diff changeset
   434
     * @param impl the remote object implementation
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * @exception UnknownObjectException if object is not registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * @exception RemoteException if call informing monitor fails
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    public void activeObject(ActivationID id, Remote impl)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        throws ActivationException, UnknownObjectException, RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            acquireLock(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                if (groupInactive == true)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                    throw new ActivationException("group is inactive");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            }
51391
07ea887eee5f 8209382: [error-prone] HashtableContains in sun/rmi/server/ActivationGroupImpl.java
iignatyev
parents: 47216
diff changeset
   448
            if (!active.containsKey(id)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                ActiveEntry entry = new ActiveEntry(impl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                active.put(id, entry);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                // created new entry, so inform monitor of active object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                    super.activeObject(id, entry.mobj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                } catch (RemoteException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                    // daemon can still find it by calling newInstance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            releaseLock(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
            checkInactiveGroup();
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
     * Entry in table for active object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    private static class ActiveEntry {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        Remote impl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        MarshalledObject<Remote> mobj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        ActiveEntry(Remote impl) throws ActivationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
            this.impl =  impl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                this.mobj = new MarshalledObject<Remote>(impl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                throw new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                    ActivationException("failed to marshal remote object", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            }
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * Returns true if the first argument is either equal to, or is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * descendant of, the second argument.  Null is treated as the root of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * the tree.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    private static boolean covers(ClassLoader sub, ClassLoader sup) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        if (sup == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        } else if (sub == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            if (sub == sup) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            sub = sub.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        } while (sub != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
}