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