src/java.rmi/share/classes/sun/rmi/server/Activation.java
author rriggs
Fri, 07 Dec 2018 11:51:17 -0500
changeset 52902 e3398b2e1ab0
parent 47216 71c04702a3d5
child 58609 fbfc72ec8e6b
permissions -rw-r--r--
8214971: Replace use of string.equals("") with isEmpty() Reviewed-by: jlaskey, prappo, lancea, dfuchs, redestad
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
22619
28616839f0dd 8023541: Race condition in rmid initialization
smarks
parents: 21278
diff changeset
     2
 * Copyright (c) 1997, 2014, 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.ByteArrayOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.FileOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.io.InputStream;
45989
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 41751
diff changeset
    33
import java.io.ObjectInput;
9502
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
    34
import java.io.ObjectInputStream;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.io.OutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.io.PrintStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.io.PrintWriter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.lang.Process;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.lang.reflect.InvocationTargetException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.lang.reflect.Method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.net.InetAddress;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.net.ServerSocket;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.net.Socket;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.net.SocketAddress;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.net.SocketException;
13041
8477cb6992be 7143606: File.createTempFile should be improved for temporary files created by the platform.
robm
parents: 12040
diff changeset
    47
import java.nio.file.Files;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.nio.channels.Channel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import java.nio.channels.ServerSocketChannel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import java.rmi.AccessException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import java.rmi.AlreadyBoundException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import java.rmi.ConnectException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import java.rmi.ConnectIOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import java.rmi.MarshalledObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
import java.rmi.NoSuchObjectException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
import java.rmi.NotBoundException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
import java.rmi.Remote;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
import java.rmi.RemoteException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
import java.rmi.activation.ActivationDesc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
import java.rmi.activation.ActivationException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
import java.rmi.activation.ActivationGroupDesc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
import java.rmi.activation.ActivationGroup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
import java.rmi.activation.ActivationGroupID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
import java.rmi.activation.ActivationID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
import java.rmi.activation.ActivationInstantiator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
import java.rmi.activation.ActivationMonitor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
import java.rmi.activation.ActivationSystem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
import java.rmi.activation.Activator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
import java.rmi.activation.UnknownGroupException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
import java.rmi.activation.UnknownObjectException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
import java.rmi.registry.Registry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
import java.rmi.server.ObjID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
import java.rmi.server.RMIClassLoader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
import java.rmi.server.RMIClientSocketFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
import java.rmi.server.RMIServerSocketFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
import java.rmi.server.RemoteObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
import java.rmi.server.RemoteServer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
import java.rmi.server.UnicastRemoteObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
import java.security.AccessControlException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
import java.security.AllPermission;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
import java.security.CodeSource;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
import java.security.Permission;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
import java.security.PermissionCollection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
import java.security.Permissions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
import java.security.Policy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
import java.security.PrivilegedAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
import java.security.PrivilegedExceptionAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
import java.security.cert.Certificate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
import java.text.MessageFormat;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
import java.util.Arrays;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
import java.util.Date;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
import java.util.Enumeration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
import java.util.HashSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
import java.util.Iterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
import java.util.MissingResourceException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
import java.util.Properties;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
import java.util.ResourceBundle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
import java.util.Set;
9502
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   104
import java.util.concurrent.ConcurrentHashMap;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
import sun.rmi.log.LogHandler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
import sun.rmi.log.ReliableLog;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
import sun.rmi.registry.RegistryImpl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
import sun.rmi.runtime.NewThreadAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
import sun.rmi.transport.LiveRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
import sun.security.provider.PolicyFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
import com.sun.rmi.rmid.ExecPermission;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
import com.sun.rmi.rmid.ExecOptionPermission;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * The Activator facilitates remote object activation. A "faulting"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 * remote reference calls the activator's <code>activate</code> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 * to obtain a "live" reference to a activatable remote object. Upon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 * receiving a request for activation, the activator looks up the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 * activation descriptor for the activation identifier, id, determines
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 * the group in which the object should be activated and invokes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 * activate method on the object's activation group (described by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 * remote interface <code>ActivationInstantiator</code>). The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 * activator initiates the execution of activation groups as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 * necessary. For example, if an activation group for a specific group
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 * identifier is not already executing, the activator will spawn a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 * child process for the activation group. <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 * The activator is responsible for monitoring and detecting when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 * activation groups fail so that it can remove stale remote references
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 * from its internal tables. <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 * @author      Ann Wollrath
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 * @since       1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
public class Activation implements Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    /** indicate compatibility with JDK 1.2 version of class */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    private static final long serialVersionUID = 2921265612698155191L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    private static final byte MAJOR_VERSION = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    private static final byte MINOR_VERSION = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    /** exec policy object */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    private static Object execPolicy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    private static Method execPolicyMethod;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    private static boolean debugExec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    /** maps activation id to its respective group id */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    private Map<ActivationID,ActivationGroupID> idTable =
9502
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   149
        new ConcurrentHashMap<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    /** maps group id to its GroupEntry groups */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    private Map<ActivationGroupID,GroupEntry> groupTable =
9502
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   152
        new ConcurrentHashMap<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    private byte majorVersion = MAJOR_VERSION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    private byte minorVersion = MINOR_VERSION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    /** number of simultaneous group exec's */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    private transient int groupSemaphore;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    /** counter for numbering groups */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    private transient int groupCounter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    /** reliable log to hold descriptor table */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    private transient ReliableLog log;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    /** number of updates since last snapshot */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    private transient int numUpdates;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    /** the java command */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    // accessed by GroupEntry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    private transient String[] command;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    /** timeout on wait for child process to be created or destroyed */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    private static final long groupTimeout =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        getInt("sun.rmi.activation.groupTimeout", 60000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    /** take snapshot after this many updates */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    private static final int snapshotInterval =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        getInt("sun.rmi.activation.snapshotInterval", 200);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    /** timeout on wait for child process to be created */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    private static final long execTimeout =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        getInt("sun.rmi.activation.execTimeout", 30000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    private static final Object initLock = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    private static boolean initDone = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    // this should be a *private* method since it is privileged
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    private static int getInt(String name, int def) {
23333
b0af2c7c8c91 8035808: Eliminate dependency to GetPropertyAction and other sun.security.action convenient classes
mchung
parents: 22619
diff changeset
   184
        return AccessController.doPrivileged(
b0af2c7c8c91 8035808: Eliminate dependency to GetPropertyAction and other sun.security.action convenient classes
mchung
parents: 22619
diff changeset
   185
                (PrivilegedAction<Integer>) () -> Integer.getInteger(name, def));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    private transient Activator activator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    private transient Activator activatorStub;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    private transient ActivationSystem system;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    private transient ActivationSystem systemStub;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    private transient ActivationMonitor monitor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    private transient Registry registry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    private transient volatile boolean shuttingDown = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    private transient volatile Object startupLock;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    private transient Thread shutdownHook;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    private static ResourceBundle resources = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * Create an uninitialized instance of Activation that can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * populated with log data.  This is only called when the initial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * snapshot is taken during the first incarnation of rmid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    private Activation() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * Recover activation state from the reliable log and initialize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * activation services.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    private static void startActivation(int port,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                                        RMIServerSocketFactory ssf,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                                        String logName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                                        String[] childArgs)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        throws Exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        ReliableLog log = new ReliableLog(logName, new ActLogHandler());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        Activation state = (Activation) log.recover();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        state.init(port, ssf, log, childArgs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * Initialize the Activation instantiation; start activation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * services.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    private void init(int port,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                      RMIServerSocketFactory ssf,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                      ReliableLog log,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                      String[] childArgs)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        throws Exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        // initialize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        this.log = log;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        numUpdates = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        shutdownHook =  new ShutdownHook();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        groupSemaphore = getInt("sun.rmi.activation.groupThrottle", 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        groupCounter = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        Runtime.getRuntime().addShutdownHook(shutdownHook);
9502
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   239
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   240
        // Use array size of 0, since the value from calling size()
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   241
        // may be out of date by the time toArray() is called.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        ActivationGroupID[] gids =
9502
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   243
            groupTable.keySet().toArray(new ActivationGroupID[0]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        synchronized (startupLock = new Object()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            // all the remote methods briefly synchronize on startupLock
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            // (via checkShutdown) to make sure they don't happen in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            // middle of this block.  This block must not cause any such
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            // incoming remote calls to happen, or deadlock would result!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            activator = new ActivatorImpl(port, ssf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            activatorStub = (Activator) RemoteObject.toStub(activator);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            system = new ActivationSystemImpl(port, ssf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            systemStub = (ActivationSystem) RemoteObject.toStub(system);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            monitor = new ActivationMonitorImpl(port, ssf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            initCommand(childArgs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            registry = new SystemRegistryImpl(port, null, ssf, systemStub);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            if (ssf != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                synchronized (initLock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                    initDone = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                    initLock.notifyAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        startupLock = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        // restart services
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        for (int i = gids.length; --i >= 0; ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                getGroupEntry(gids[i]).restartServices();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            } catch (UnknownGroupException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                System.err.println(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                    getTextResource("rmid.restart.group.warning"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
9502
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   279
    /**
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   280
     * Previous versions used HashMap instead of ConcurrentHashMap.
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   281
     * Replace any HashMaps found during deserialization with
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   282
     * ConcurrentHashMaps.
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   283
     */
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   284
    private void readObject(ObjectInputStream ois)
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   285
        throws IOException, ClassNotFoundException
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   286
    {
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   287
        ois.defaultReadObject();
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   288
        if (! (groupTable instanceof ConcurrentHashMap)) {
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   289
            groupTable = new ConcurrentHashMap<>(groupTable);
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   290
        }
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   291
        if (! (idTable instanceof ConcurrentHashMap)) {
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   292
            idTable = new ConcurrentHashMap<>(idTable);
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   293
        }
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   294
    }
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   295
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    private static class SystemRegistryImpl extends RegistryImpl {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        private static final String NAME = ActivationSystem.class.getName();
12040
558b0e0d5910 7146763: Warnings cleanup in the sun.rmi and related packages
khazra
parents: 9502
diff changeset
   299
        private static final long serialVersionUID = 4877330021609408794L;
22619
28616839f0dd 8023541: Race condition in rmid initialization
smarks
parents: 21278
diff changeset
   300
        private ActivationSystem systemStub = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        SystemRegistryImpl(int port,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                           RMIClientSocketFactory csf,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                           RMIServerSocketFactory ssf,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                           ActivationSystem systemStub)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            throws RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            super(port, csf, ssf);
22619
28616839f0dd 8023541: Race condition in rmid initialization
smarks
parents: 21278
diff changeset
   309
            assert systemStub != null;
28616839f0dd 8023541: Race condition in rmid initialization
smarks
parents: 21278
diff changeset
   310
            synchronized (this) {
28616839f0dd 8023541: Race condition in rmid initialization
smarks
parents: 21278
diff changeset
   311
                this.systemStub = systemStub;
28616839f0dd 8023541: Race condition in rmid initialization
smarks
parents: 21278
diff changeset
   312
                notifyAll();
28616839f0dd 8023541: Race condition in rmid initialization
smarks
parents: 21278
diff changeset
   313
            }
28616839f0dd 8023541: Race condition in rmid initialization
smarks
parents: 21278
diff changeset
   314
        }
28616839f0dd 8023541: Race condition in rmid initialization
smarks
parents: 21278
diff changeset
   315
28616839f0dd 8023541: Race condition in rmid initialization
smarks
parents: 21278
diff changeset
   316
        /**
28616839f0dd 8023541: Race condition in rmid initialization
smarks
parents: 21278
diff changeset
   317
         * Waits for systemStub to be initialized and returns its
28616839f0dd 8023541: Race condition in rmid initialization
smarks
parents: 21278
diff changeset
   318
         * initialized value. Any remote call that uses systemStub must
28616839f0dd 8023541: Race condition in rmid initialization
smarks
parents: 21278
diff changeset
   319
         * call this method to get it instead of using direct field
28616839f0dd 8023541: Race condition in rmid initialization
smarks
parents: 21278
diff changeset
   320
         * access. This is necessary because the super() call in the
28616839f0dd 8023541: Race condition in rmid initialization
smarks
parents: 21278
diff changeset
   321
         * constructor exports this object before systemStub is initialized
28616839f0dd 8023541: Race condition in rmid initialization
smarks
parents: 21278
diff changeset
   322
         * (see JDK-8023541), allowing remote calls to come in during this
28616839f0dd 8023541: Race condition in rmid initialization
smarks
parents: 21278
diff changeset
   323
         * time. We can't use checkShutdown() like other nested classes
28616839f0dd 8023541: Race condition in rmid initialization
smarks
parents: 21278
diff changeset
   324
         * because this is a static class.
28616839f0dd 8023541: Race condition in rmid initialization
smarks
parents: 21278
diff changeset
   325
         */
28616839f0dd 8023541: Race condition in rmid initialization
smarks
parents: 21278
diff changeset
   326
        private synchronized ActivationSystem getSystemStub() {
28616839f0dd 8023541: Race condition in rmid initialization
smarks
parents: 21278
diff changeset
   327
            boolean interrupted = false;
28616839f0dd 8023541: Race condition in rmid initialization
smarks
parents: 21278
diff changeset
   328
28616839f0dd 8023541: Race condition in rmid initialization
smarks
parents: 21278
diff changeset
   329
            while (systemStub == null) {
28616839f0dd 8023541: Race condition in rmid initialization
smarks
parents: 21278
diff changeset
   330
                try {
28616839f0dd 8023541: Race condition in rmid initialization
smarks
parents: 21278
diff changeset
   331
                    wait();
28616839f0dd 8023541: Race condition in rmid initialization
smarks
parents: 21278
diff changeset
   332
                } catch (InterruptedException ie) {
28616839f0dd 8023541: Race condition in rmid initialization
smarks
parents: 21278
diff changeset
   333
                    interrupted = true;
28616839f0dd 8023541: Race condition in rmid initialization
smarks
parents: 21278
diff changeset
   334
                }
28616839f0dd 8023541: Race condition in rmid initialization
smarks
parents: 21278
diff changeset
   335
            }
28616839f0dd 8023541: Race condition in rmid initialization
smarks
parents: 21278
diff changeset
   336
28616839f0dd 8023541: Race condition in rmid initialization
smarks
parents: 21278
diff changeset
   337
            if (interrupted) {
28616839f0dd 8023541: Race condition in rmid initialization
smarks
parents: 21278
diff changeset
   338
                Thread.currentThread().interrupt();
28616839f0dd 8023541: Race condition in rmid initialization
smarks
parents: 21278
diff changeset
   339
            }
28616839f0dd 8023541: Race condition in rmid initialization
smarks
parents: 21278
diff changeset
   340
28616839f0dd 8023541: Race condition in rmid initialization
smarks
parents: 21278
diff changeset
   341
            return systemStub;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
         * Returns the activation system stub if the specified name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
         * matches the activation system's class name, otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
         * returns the result of invoking super.lookup with the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
         * name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        public Remote lookup(String name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            throws RemoteException, NotBoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            if (name.equals(NAME)) {
22619
28616839f0dd 8023541: Race condition in rmid initialization
smarks
parents: 21278
diff changeset
   354
                return getSystemStub();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                return super.lookup(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        public String[] list() throws RemoteException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            String[] list1 = super.list();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            int length = list1.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            String[] list2 = new String[length + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            if (length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                System.arraycopy(list1, 0, list2, 0, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            list2[length] = NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            return list2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        public void bind(String name, Remote obj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
            throws RemoteException, AlreadyBoundException, AccessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            if (name.equals(NAME)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                throw new AccessException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                    "binding ActivationSystem is disallowed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            } else {
45989
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 41751
diff changeset
   378
                RegistryImpl.checkAccess("ActivationSystem.bind");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                super.bind(name, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        public void unbind(String name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            throws RemoteException, NotBoundException, AccessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            if (name.equals(NAME)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                throw new AccessException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                    "unbinding ActivationSystem is disallowed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            } else {
45989
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 41751
diff changeset
   390
                RegistryImpl.checkAccess("ActivationSystem.unbind");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                super.unbind(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        public void rebind(String name, Remote obj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            throws RemoteException, AccessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            if (name.equals(NAME)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                throw new AccessException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                    "binding ActivationSystem is disallowed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            } else {
45989
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 41751
diff changeset
   403
                RegistryImpl.checkAccess("ActivationSystem.rebind");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                super.rebind(name, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    class ActivatorImpl extends RemoteServer implements Activator {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        // Because ActivatorImpl has a fixed ObjID, it can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        // called by clients holding stale remote references.  Each of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        // its remote methods, then, must check startupLock (calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        // checkShutdown() is easiest).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        private static final long serialVersionUID = -3654244726254566136L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
         * Construct a new Activator on a specified port.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        ActivatorImpl(int port, RMIServerSocketFactory ssf)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            throws RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            /* Server ref must be created and assigned before remote object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
             * 'this' can be exported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            LiveRef lref =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                new LiveRef(new ObjID(ObjID.ACTIVATOR_ID), port, null, ssf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
            UnicastServerRef uref = new UnicastServerRef(lref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
            ref = uref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            uref.exportObject(this, null, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        public MarshalledObject<? extends Remote> activate(ActivationID id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                                                           boolean force)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            throws ActivationException, UnknownObjectException, RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            checkShutdown();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            return getGroupEntry(id).activate(id, force);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    class ActivationMonitorImpl extends UnicastRemoteObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        implements ActivationMonitor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        private static final long serialVersionUID = -6214940464757948867L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        ActivationMonitorImpl(int port, RMIServerSocketFactory ssf)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            throws RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            super(port, null, ssf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        public void inactiveObject(ActivationID id)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
            throws UnknownObjectException, RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                checkShutdown();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            } catch (ActivationException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
            RegistryImpl.checkAccess("Activator.inactiveObject");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            getGroupEntry(id).inactiveObject(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        public void activeObject(ActivationID id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                                 MarshalledObject<? extends Remote> mobj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            throws UnknownObjectException, RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                checkShutdown();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
            } catch (ActivationException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            RegistryImpl.checkAccess("ActivationSystem.activeObject");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            getGroupEntry(id).activeObject(id, mobj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        public void inactiveGroup(ActivationGroupID id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                                  long incarnation)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            throws UnknownGroupException, RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                checkShutdown();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            } catch (ActivationException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            RegistryImpl.checkAccess("ActivationMonitor.inactiveGroup");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
            getGroupEntry(id).inactiveGroup(incarnation, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
45989
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 41751
diff changeset
   494
    /**
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 41751
diff changeset
   495
     * SameHostOnlyServerRef checks that access is from a local client
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 41751
diff changeset
   496
     * before the parameters are deserialized.  The unmarshalCustomCallData
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 41751
diff changeset
   497
     * hook is used to check the network address of the caller
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 41751
diff changeset
   498
     * with RegistryImpl.checkAccess().
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 41751
diff changeset
   499
     * The kind of access is retained for an exception if one is thrown.
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 41751
diff changeset
   500
     */
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 41751
diff changeset
   501
    static class SameHostOnlyServerRef extends UnicastServerRef {
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 41751
diff changeset
   502
        private static final long serialVersionUID = 1234L;
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 41751
diff changeset
   503
        private String accessKind;      // an exception message
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 41751
diff changeset
   504
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 41751
diff changeset
   505
        /**
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 41751
diff changeset
   506
         * Construct a new SameHostOnlyServerRef from a LiveRef.
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 41751
diff changeset
   507
         * @param lref a LiveRef
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 41751
diff changeset
   508
         */
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 41751
diff changeset
   509
        SameHostOnlyServerRef(LiveRef lref, String accessKind) {
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 41751
diff changeset
   510
            super(lref);
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 41751
diff changeset
   511
            this.accessKind = accessKind;
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 41751
diff changeset
   512
        }
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 41751
diff changeset
   513
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 41751
diff changeset
   514
        @Override
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 41751
diff changeset
   515
        protected void unmarshalCustomCallData(ObjectInput in) throws IOException, ClassNotFoundException {
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 41751
diff changeset
   516
            RegistryImpl.checkAccess(accessKind);
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 41751
diff changeset
   517
            super.unmarshalCustomCallData(in);
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 41751
diff changeset
   518
        }
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 41751
diff changeset
   519
    }
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 41751
diff changeset
   520
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    class ActivationSystemImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        extends RemoteServer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        implements ActivationSystem
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        private static final long serialVersionUID = 9100152600327688967L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        // Because ActivationSystemImpl has a fixed ObjID, it can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        // called by clients holding stale remote references.  Each of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        // its remote methods, then, must check startupLock (calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        // checkShutdown() is easiest).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        ActivationSystemImpl(int port, RMIServerSocketFactory ssf)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
            throws RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
            /* Server ref must be created and assigned before remote object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
             * 'this' can be exported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
            LiveRef lref = new LiveRef(new ObjID(4), port, null, ssf);
45989
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 41751
diff changeset
   538
            UnicastServerRef uref = new SameHostOnlyServerRef(lref,
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 41751
diff changeset
   539
                    "ActivationSystem.nonLocalAccess");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            ref = uref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
            uref.exportObject(this, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        public ActivationID registerObject(ActivationDesc desc)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
            throws ActivationException, UnknownGroupException, RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
            checkShutdown();
45989
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 41751
diff changeset
   548
            // RegistryImpl.checkAccess() is done in the SameHostOnlyServerRef
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 41751
diff changeset
   549
            // during unmarshallCustomData and is not applicable to local access.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            ActivationGroupID groupID = desc.getGroupID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
            ActivationID id = new ActivationID(activatorStub);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
            getGroupEntry(groupID).registerObject(id, desc, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
            return id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        public void unregisterObject(ActivationID id)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
            throws ActivationException, UnknownObjectException, RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
            checkShutdown();
45989
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 41751
diff changeset
   560
            // RegistryImpl.checkAccess() is done in the SameHostOnlyServerRef
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 41751
diff changeset
   561
            // during unmarshallCustomData and is not applicable to local access.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
            getGroupEntry(id).unregisterObject(id, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        public ActivationGroupID registerGroup(ActivationGroupDesc desc)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
            throws ActivationException, RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
            checkShutdown();
45989
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 41751
diff changeset
   569
            // RegistryImpl.checkAccess() is done in the SameHostOnlyServerRef
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 41751
diff changeset
   570
            // during unmarshallCustomData and is not applicable to local access.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
            checkArgs(desc, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
            ActivationGroupID id = new ActivationGroupID(systemStub);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
            GroupEntry entry = new GroupEntry(id, desc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
            // table insertion must take place before log update
9502
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   576
            groupTable.put(id, entry);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
            addLogRecord(new LogRegisterGroup(id, desc));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
            return id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        public ActivationMonitor activeGroup(ActivationGroupID id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                                             ActivationInstantiator group,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                                             long incarnation)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
            throws ActivationException, UnknownGroupException, RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
            checkShutdown();
45989
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 41751
diff changeset
   587
            // RegistryImpl.checkAccess() is done in the SameHostOnlyServerRef
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 41751
diff changeset
   588
            // during unmarshallCustomData and is not applicable to local access.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
            getGroupEntry(id).activeGroup(group, incarnation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
            return monitor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        public void unregisterGroup(ActivationGroupID id)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
            throws ActivationException, UnknownGroupException, RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
            checkShutdown();
45989
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 41751
diff changeset
   598
            // RegistryImpl.checkAccess() is done in the SameHostOnlyServerRef
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 41751
diff changeset
   599
            // during unmarshallCustomData and is not applicable to local access.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
            // remove entry before unregister so state is updated before
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
            // logged
9502
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   603
            removeGroupEntry(id).unregisterGroup(true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        public ActivationDesc setActivationDesc(ActivationID id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                                                ActivationDesc desc)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
            throws ActivationException, UnknownObjectException, RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            checkShutdown();
45989
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 41751
diff changeset
   611
            // RegistryImpl.checkAccess() is done in the SameHostOnlyServerRef
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 41751
diff changeset
   612
            // during unmarshallCustomData and is not applicable to local access.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
            if (!getGroupID(id).equals(desc.getGroupID())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                throw new ActivationException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
                    "ActivationDesc contains wrong group");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            return getGroupEntry(id).setActivationDesc(id, desc, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        public ActivationGroupDesc setActivationGroupDesc(ActivationGroupID id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
                                                          ActivationGroupDesc desc)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
            throws ActivationException, UnknownGroupException, RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
            checkShutdown();
45989
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 41751
diff changeset
   626
            // RegistryImpl.checkAccess() is done in the SameHostOnlyServerRef
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 41751
diff changeset
   627
            // during unmarshallCustomData and is not applicable to local access.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
            checkArgs(desc, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
            return getGroupEntry(id).setActivationGroupDesc(id, desc, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        public ActivationDesc getActivationDesc(ActivationID id)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
            throws ActivationException, UnknownObjectException, RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
            checkShutdown();
45989
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 41751
diff changeset
   637
            // RegistryImpl.checkAccess() is done in the SameHostOnlyServerRef
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 41751
diff changeset
   638
            // during unmarshallCustomData and is not applicable to local access.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
            return getGroupEntry(id).getActivationDesc(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        public ActivationGroupDesc getActivationGroupDesc(ActivationGroupID id)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
            throws ActivationException, UnknownGroupException, RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
            checkShutdown();
45989
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 41751
diff changeset
   647
            // RegistryImpl.checkAccess() is done in the SameHostOnlyServerRef
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 41751
diff changeset
   648
            // during unmarshallCustomData and is not applicable to local access.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
            return getGroupEntry(id).desc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
         * Shutdown the activation system. Destroys all groups spawned by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
         * the activation daemon and exits the activation daemon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        public void shutdown() throws AccessException {
45989
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 41751
diff changeset
   658
            // RegistryImpl.checkAccess() is done in the SameHostOnlyServerRef
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 41751
diff changeset
   659
            // during unmarshallCustomData and is not applicable to local access.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
            Object lock = startupLock;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
            if (lock != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
                synchronized (lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
                    // nothing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
            synchronized (Activation.this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
                if (!shuttingDown) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
                    shuttingDown = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
                    (new Shutdown()).start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
    private void checkShutdown() throws ActivationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        // if the startup critical section is running, wait until it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        // completes/fails before continuing with the remote call.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
        Object lock = startupLock;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        if (lock != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
            synchronized (lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
                // nothing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        if (shuttingDown == true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
            throw new ActivationException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
                "activation system shutting down");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
    private static void unexport(Remote obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
        for (;;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
                if (UnicastRemoteObject.unexportObject(obj, false) == true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
                    Thread.sleep(100);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     * Thread to shutdown rmid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
    private class Shutdown extends Thread {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        Shutdown() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
            super("rmid Shutdown");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
        public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
                 * Unexport activation system services
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
                unexport(activator);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
                unexport(system);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
                // destroy all child processes (groups)
9502
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   724
                for (GroupEntry groupEntry : groupTable.values()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
                    groupEntry.shutdown();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
                Runtime.getRuntime().removeShutdownHook(shutdownHook);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
                 * Unexport monitor safely since all processes are destroyed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
                unexport(monitor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
                 * Close log file, fix for 4243264: rmid shutdown thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
                 * interferes with remote calls in progress.  Make sure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
                 * the log file is only closed when it is impossible for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
                 * its closure to interfere with any pending remote calls.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
                 * We close the log when all objects in the rmid VM are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
                 * unexported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
                    synchronized (log) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
                        log.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
                } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
                 * Now exit... A System.exit should only be done if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
                 * the RMI activation system daemon was started up
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
                 * by the main method below (in which should always
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 18212
diff changeset
   755
                 * be the case since the Activation constructor is private).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
                System.err.println(getTextResource("rmid.daemon.shutdown"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
                System.exit(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
    /** Thread to destroy children in the event of abnormal termination. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
    private class ShutdownHook extends Thread {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
        ShutdownHook() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
            super("rmid ShutdownHook");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
        public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
            synchronized (Activation.this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
                shuttingDown = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
            // destroy all child processes (groups) quickly
9502
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   775
            for (GroupEntry groupEntry : groupTable.values()) {
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   776
                groupEntry.shutdownFast();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
     * Returns the groupID for a given id of an object in the group.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
     * Throws UnknownObjectException if the object is not registered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
    private ActivationGroupID getGroupID(ActivationID id)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
        throws UnknownObjectException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
    {
9502
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   788
        ActivationGroupID groupID = idTable.get(id);
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   789
        if (groupID != null) {
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   790
            return groupID;
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   791
        }
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   792
        throw new UnknownObjectException("unknown object: " + id);
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   793
    }
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   794
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   795
    /**
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   796
     * Returns the group entry for the group id, optionally removing it.
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   797
     * Throws UnknownGroupException if the group is not registered.
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   798
     */
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   799
    private GroupEntry getGroupEntry(ActivationGroupID id, boolean rm)
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   800
        throws UnknownGroupException
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   801
    {
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   802
        if (id.getClass() == ActivationGroupID.class) {
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   803
            GroupEntry entry;
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   804
            if (rm) {
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   805
                entry = groupTable.remove(id);
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   806
            } else {
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   807
                entry = groupTable.get(id);
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   808
            }
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   809
            if (entry != null && !entry.removed) {
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   810
                return entry;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
        }
9502
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   813
        throw new UnknownGroupException("group unknown");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
     * Returns the group entry for the group id. Throws
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
     * UnknownGroupException if the group is not registered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
    private GroupEntry getGroupEntry(ActivationGroupID id)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
        throws UnknownGroupException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
    {
9502
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   823
        return getGroupEntry(id, false);
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   824
    }
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   825
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   826
    /**
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   827
     * Removes and returns the group entry for the group id. Throws
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   828
     * UnknownGroupException if the group is not registered.
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   829
     */
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   830
    private GroupEntry removeGroupEntry(ActivationGroupID id)
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   831
        throws UnknownGroupException
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   832
    {
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   833
        return getGroupEntry(id, true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
     * Returns the group entry for the object's id. Throws
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
     * UnknownObjectException if the object is not registered or the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
     * object's group is not registered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
    private GroupEntry getGroupEntry(ActivationID id)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
        throws UnknownObjectException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
        ActivationGroupID gid = getGroupID(id);
9502
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   845
        GroupEntry entry = groupTable.get(gid);
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   846
        if (entry != null && !entry.removed) {
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   847
            return entry;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
        throw new UnknownObjectException("object's group removed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
     * Container for group information: group's descriptor, group's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
     * instantiator, flag to indicate pending group creation, and
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 18212
diff changeset
   855
     * table of the objects that are activated in the group.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
     * WARNING: GroupEntry objects should not be written into log file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
     * updates.  GroupEntrys are inner classes of Activation and they
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
     * can not be serialized independent of this class.  If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
     * complete Activation system is written out as a log update, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
     * point of having updates is nullified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
    private class GroupEntry implements Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        /** indicate compatibility with JDK 1.2 version of class */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
        private static final long serialVersionUID = 7222464070032993304L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
        private static final int MAX_TRIES = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
        private static final int NORMAL = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
        private static final int CREATING = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        private static final int TERMINATE = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
        private static final int TERMINATING = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
        ActivationGroupDesc desc = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
        ActivationGroupID groupID = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
        long incarnation = 0;
12040
558b0e0d5910 7146763: Warnings cleanup in the sun.rmi and related packages
khazra
parents: 9502
diff changeset
   876
        Map<ActivationID,ObjectEntry> objects = new HashMap<>();
558b0e0d5910 7146763: Warnings cleanup in the sun.rmi and related packages
khazra
parents: 9502
diff changeset
   877
        Set<ActivationID> restartSet = new HashSet<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
        transient ActivationInstantiator group = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
        transient int status = NORMAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
        transient long waitTime = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
        transient String groupName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
        transient Process child = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
        transient boolean removed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
        transient Watchdog watchdog = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
        GroupEntry(ActivationGroupID groupID, ActivationGroupDesc desc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
            this.groupID = groupID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
            this.desc = desc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
        void restartServices() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
            Iterator<ActivationID> iter = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
            synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
                if (restartSet.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
                 * Clone the restartSet so the set does not have to be locked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
                 * during iteration. Locking the restartSet could cause
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
                 * deadlock if an object we are restarting caused another
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
                 * object in this group to be activated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
                iter = (new HashSet<ActivationID>(restartSet)).iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
            while (iter.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
                ActivationID id = iter.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
                    activate(id, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
                } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
                    if (shuttingDown) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
                    System.err.println(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
                        getTextResource("rmid.restart.service.warning"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
                    e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
        synchronized void activeGroup(ActivationInstantiator inst,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
                                      long instIncarnation)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
            throws ActivationException, UnknownGroupException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
            if (incarnation != instIncarnation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
                throw new ActivationException("invalid incarnation");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
            if (group != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
                if (group.equals(inst)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
                    throw new ActivationException("group already active");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
            if (child != null && status != CREATING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
                throw new ActivationException("group not being created");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
            group = inst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
            status = NORMAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
            notifyAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
        private void checkRemoved() throws UnknownGroupException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
            if (removed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
                throw new UnknownGroupException("group removed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
        private ObjectEntry getObjectEntry(ActivationID id)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
            throws UnknownObjectException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
            if (removed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
                throw new UnknownObjectException("object's group removed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
            ObjectEntry objEntry = objects.get(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
            if (objEntry == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
                throw new UnknownObjectException("object unknown");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
            return objEntry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
        synchronized void registerObject(ActivationID id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
                                         ActivationDesc desc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
                                         boolean addRecord)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
            throws UnknownGroupException, ActivationException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
            checkRemoved();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
            objects.put(id, new ObjectEntry(desc));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
            if (desc.getRestartMode() == true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
                restartSet.add(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
            // table insertion must take place before log update
9502
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   980
            idTable.put(id, groupID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
            if (addRecord) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
                addLogRecord(new LogRegisterObject(id, desc));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
        synchronized void unregisterObject(ActivationID id, boolean addRecord)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
            throws UnknownGroupException, ActivationException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
            ObjectEntry objEntry = getObjectEntry(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
            objEntry.removed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
            objects.remove(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
            if (objEntry.desc.getRestartMode() == true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
                restartSet.remove(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
9502
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   997
            // table removal must take place before log update
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
   998
            idTable.remove(id);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
            if (addRecord) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
                addLogRecord(new LogUnregisterObject(id));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
        synchronized void unregisterGroup(boolean addRecord)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
           throws UnknownGroupException, ActivationException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
            checkRemoved();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
            removed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
            for (Map.Entry<ActivationID,ObjectEntry> entry :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
                     objects.entrySet())
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
                ActivationID id = entry.getKey();
9502
de183d393b77 6896297: (rmi) fix ConcurrentModificationException causing TCK failure
smarks
parents: 5506
diff changeset
  1013
                idTable.remove(id);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
                ObjectEntry objEntry = entry.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
                objEntry.removed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
            objects.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
            restartSet.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
            reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
            childGone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
            // removal should be recorded before log update
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
            if (addRecord) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
                addLogRecord(new LogUnregisterGroup(groupID));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
        synchronized ActivationDesc setActivationDesc(ActivationID id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
                                                      ActivationDesc desc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
                                                      boolean addRecord)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
            throws UnknownObjectException, UnknownGroupException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
                   ActivationException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
            ObjectEntry objEntry = getObjectEntry(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
            ActivationDesc oldDesc = objEntry.desc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
            objEntry.desc = desc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
            if (desc.getRestartMode() == true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
                restartSet.add(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
                restartSet.remove(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
            // restart information should be recorded before log update
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
            if (addRecord) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
                addLogRecord(new LogUpdateDesc(id, desc));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
            return oldDesc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
        synchronized ActivationDesc getActivationDesc(ActivationID id)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
            throws UnknownObjectException, UnknownGroupException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
            return getObjectEntry(id).desc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
        synchronized ActivationGroupDesc setActivationGroupDesc(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
                ActivationGroupID id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
                ActivationGroupDesc desc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
                boolean addRecord)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
            throws UnknownGroupException, ActivationException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
            checkRemoved();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
            ActivationGroupDesc oldDesc = this.desc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
            this.desc = desc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
            // state update should occur before log update
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
            if (addRecord) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
                addLogRecord(new LogUpdateGroupDesc(id, desc));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
            return oldDesc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
        synchronized void inactiveGroup(long incarnation, boolean failure)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
            throws UnknownGroupException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
            checkRemoved();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
            if (this.incarnation != incarnation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
                throw new UnknownGroupException("invalid incarnation");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
            reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
            if (failure) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
                terminate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
            } else if (child != null && status == NORMAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
                status = TERMINATE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
                watchdog.noRestart();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
        synchronized void activeObject(ActivationID id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
                                       MarshalledObject<? extends Remote> mobj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
                throws UnknownObjectException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
            getObjectEntry(id).stub = mobj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
        synchronized void inactiveObject(ActivationID id)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
            throws UnknownObjectException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
            getObjectEntry(id).reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
        private synchronized void reset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
            group = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
            for (ObjectEntry objectEntry : objects.values()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
                objectEntry.reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
        private void childGone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
            if (child != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
                child = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
                watchdog.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
                watchdog = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
                status = NORMAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
                notifyAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
        private void terminate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
            if (child != null && status != TERMINATING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
                child.destroy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
                status = TERMINATING;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
                waitTime = System.currentTimeMillis() + groupTimeout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
                notifyAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
12040
558b0e0d5910 7146763: Warnings cleanup in the sun.rmi and related packages
khazra
parents: 9502
diff changeset
  1128
       /*
558b0e0d5910 7146763: Warnings cleanup in the sun.rmi and related packages
khazra
parents: 9502
diff changeset
  1129
        * Fallthrough from TERMINATE to TERMINATING
558b0e0d5910 7146763: Warnings cleanup in the sun.rmi and related packages
khazra
parents: 9502
diff changeset
  1130
        * is intentional
558b0e0d5910 7146763: Warnings cleanup in the sun.rmi and related packages
khazra
parents: 9502
diff changeset
  1131
        */
558b0e0d5910 7146763: Warnings cleanup in the sun.rmi and related packages
khazra
parents: 9502
diff changeset
  1132
        @SuppressWarnings("fallthrough")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
        private void await() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
            while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
                switch (status) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
                case NORMAL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
                case TERMINATE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
                    terminate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
                case TERMINATING:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
                        child.exitValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
                    } catch (IllegalThreadStateException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
                        long now = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
                        if (waitTime > now) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
                            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
                                wait(waitTime - now);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
                            } catch (InterruptedException ee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
                            continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
                        // REMIND: print message that group did not terminate?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
                    childGone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
                case CREATING:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
                        wait();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
                    } catch (InterruptedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
        // no synchronization to avoid delay wrt getInstantiator
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
        void shutdownFast() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
            Process p = child;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
            if (p != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
                p.destroy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
        synchronized void shutdown() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
            reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
            terminate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
            await();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
        MarshalledObject<? extends Remote> activate(ActivationID id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
                                                    boolean force)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
            throws ActivationException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
            Exception detail = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
             * Attempt to activate object and reattempt (several times)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
             * if activation fails due to communication problems.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
            for (int tries = MAX_TRIES; tries > 0; tries--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
                ActivationInstantiator inst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
                long currentIncarnation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
                // look up object to activate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
                ObjectEntry objEntry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
                synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
                    objEntry = getObjectEntry(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
                    // if not forcing activation, return cached stub
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
                    if (!force && objEntry.stub != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
                        return objEntry.stub;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
                    inst = getInstantiator(groupID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
                    currentIncarnation = incarnation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
                boolean groupInactive = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
                boolean failure = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
                // activate object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
                    return objEntry.activate(id, force, inst);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
                } catch (NoSuchObjectException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
                    groupInactive = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
                    detail = e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
                } catch (ConnectException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
                    groupInactive = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
                    failure = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
                    detail = e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
                } catch (ConnectIOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
                    groupInactive = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
                    failure = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
                    detail = e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
                } catch (InactiveGroupException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
                    groupInactive = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
                    detail = e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
                } catch (RemoteException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
                    // REMIND: wait some here before continuing?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
                    if (detail == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
                        detail = e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
                if (groupInactive) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
                    // group has failed or is inactive; mark inactive
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
                        System.err.println(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
                            MessageFormat.format(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
                                getTextResource("rmid.group.inactive"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
                                detail.toString()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
                        detail.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
                        getGroupEntry(groupID).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
                            inactiveGroup(currentIncarnation, failure);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
                    } catch (UnknownGroupException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
                        // not a problem
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
             * signal that group activation failed, nested exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
             * specifies what exception occurred when the group did not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
             * activate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
            throw new ActivationException("object activation failed after " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
                                          MAX_TRIES + " tries", detail);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
         * Returns the instantiator for the group specified by id and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
         * entry. If the group is currently inactive, exec some
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
         * bootstrap code to create the group.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
        private ActivationInstantiator getInstantiator(ActivationGroupID id)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
            throws ActivationException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
            assert Thread.holdsLock(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
            await();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
            if (group != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
                return group;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
            checkRemoved();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
            boolean acquired = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
                groupName = Pstartgroup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
                acquired = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
                String[] argv = activationArgs(desc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
                checkArgs(desc, argv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
                if (debugExec) {
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 23333
diff changeset
  1280
                    StringBuilder sb = new StringBuilder(argv[0]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
                    int j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
                    for (j = 1; j < argv.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
                        sb.append(' ');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
                        sb.append(argv[j]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
                    System.err.println(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
                        MessageFormat.format(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
                            getTextResource("rmid.exec.command"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
                            sb.toString()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
                    child = Runtime.getRuntime().exec(argv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
                    status = CREATING;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
                    ++incarnation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
                    watchdog = new Watchdog();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
                    watchdog.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
                    addLogRecord(new LogGroupIncarnation(id, incarnation));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
                    // handle child I/O streams before writing to child
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
                    PipeWriter.plugTogetherPair
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
                        (child.getInputStream(), System.out,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
                         child.getErrorStream(), System.err);
12040
558b0e0d5910 7146763: Warnings cleanup in the sun.rmi and related packages
khazra
parents: 9502
diff changeset
  1304
                    try (MarshalOutputStream out =
558b0e0d5910 7146763: Warnings cleanup in the sun.rmi and related packages
khazra
parents: 9502
diff changeset
  1305
                            new MarshalOutputStream(child.getOutputStream())) {
558b0e0d5910 7146763: Warnings cleanup in the sun.rmi and related packages
khazra
parents: 9502
diff changeset
  1306
                        out.writeObject(id);
558b0e0d5910 7146763: Warnings cleanup in the sun.rmi and related packages
khazra
parents: 9502
diff changeset
  1307
                        out.writeObject(desc);
558b0e0d5910 7146763: Warnings cleanup in the sun.rmi and related packages
khazra
parents: 9502
diff changeset
  1308
                        out.writeLong(incarnation);
558b0e0d5910 7146763: Warnings cleanup in the sun.rmi and related packages
khazra
parents: 9502
diff changeset
  1309
                        out.flush();
558b0e0d5910 7146763: Warnings cleanup in the sun.rmi and related packages
khazra
parents: 9502
diff changeset
  1310
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
                } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
                    terminate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
                    throw new ActivationException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
                        "unable to create activation group", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
                    long now = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
                    long stop = now + execTimeout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
                    do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
                        wait(stop - now);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
                        if (group != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
                            return group;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
                        now = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
                    } while (status == CREATING && now < stop);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
                } catch (InterruptedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
                terminate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
                throw new ActivationException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
                        (removed ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
                         "activation group unregistered" :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
                         "timeout creating child process"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
                if (acquired) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
                    Vstartgroup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
         * Waits for process termination and then restarts services.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
        private class Watchdog extends Thread {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
            private final Process groupProcess = child;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
            private final long groupIncarnation = incarnation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
            private boolean canInterrupt = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
            private boolean shouldQuit = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
            private boolean shouldRestart = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
            Watchdog() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
                super("WatchDog-"  + groupName + "-" + incarnation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
                setDaemon(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
            public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
                if (shouldQuit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
                 * Wait for the group to crash or exit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
                    groupProcess.waitFor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
                } catch (InterruptedException exit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
                boolean restart = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
                synchronized (GroupEntry.this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
                    if (shouldQuit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
                    canInterrupt = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
                    interrupted(); // clear interrupt bit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
                    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
                     * Since the group crashed, we should
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
                     * reset the entry before activating objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
                     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
                    if (groupIncarnation == incarnation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
                        restart = shouldRestart && !shuttingDown;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
                        reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
                        childGone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
                 * Activate those objects that require restarting
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
                 * after a crash.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
                if (restart) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
                    restartServices();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
             * Marks this thread as one that is no longer needed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
             * If the thread is in a state in which it can be interrupted,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
             * then the thread is interrupted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
            void dispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
                shouldQuit = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
                if (canInterrupt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
                    interrupt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
             * Marks this thread as no longer needing to restart objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
            void noRestart() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
                shouldRestart = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
    private String[] activationArgs(ActivationGroupDesc desc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
        ActivationGroupDesc.CommandEnvironment cmdenv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
        cmdenv = desc.getCommandEnvironment();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
        // argv is the literal command to exec
12040
558b0e0d5910 7146763: Warnings cleanup in the sun.rmi and related packages
khazra
parents: 9502
diff changeset
  1427
        List<String> argv = new ArrayList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
        // Command name/path
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
        argv.add((cmdenv != null && cmdenv.getCommandPath() != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
                    ? cmdenv.getCommandPath()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
                    : command[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
        // Group-specific command options
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
        if (cmdenv != null && cmdenv.getCommandOptions() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
            argv.addAll(Arrays.asList(cmdenv.getCommandOptions()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
        // Properties become -D parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
        Properties props = desc.getPropertyOverrides();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
        if (props != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
            for (Enumeration<?> p = props.propertyNames();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
                 p.hasMoreElements();)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
                String name = (String) p.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
                /* Note on quoting: it would be wrong
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
                 * here, since argv will be passed to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
                 * Runtime.exec, which should not parse
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
                 * arguments or split on whitespace.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
                argv.add("-D" + name + "=" + props.getProperty(name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
        /* Finally, rmid-global command options (e.g. -C options)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
         * and the classname
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
        for (int i = 1; i < command.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
            argv.add(command[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
        String[] realArgv = new String[argv.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
        System.arraycopy(argv.toArray(), 0, realArgv, 0, realArgv.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
        return realArgv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
    private void checkArgs(ActivationGroupDesc desc, String[] cmd)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
        throws SecurityException, ActivationException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
         * Check exec command using execPolicy object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
        if (execPolicyMethod != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
            if (cmd == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
                cmd = activationArgs(desc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
                execPolicyMethod.invoke(execPolicy, desc, cmd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
            } catch (InvocationTargetException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
                Throwable targetException = e.getTargetException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
                if (targetException instanceof SecurityException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
                    throw (SecurityException) targetException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
                    throw new ActivationException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
                        execPolicyMethod.getName() + ": unexpected exception",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
                        e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
                throw new ActivationException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
                    execPolicyMethod.getName() + ": unexpected exception", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
    private static class ObjectEntry implements Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
        private static final long serialVersionUID = -5500114225321357856L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
        /** descriptor for object */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
        ActivationDesc desc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
        /** the stub (if active) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
        volatile transient MarshalledObject<? extends Remote> stub = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
        volatile transient boolean removed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
        ObjectEntry(ActivationDesc desc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
            this.desc = desc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
        synchronized MarshalledObject<? extends Remote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
            activate(ActivationID id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
                     boolean force,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
                     ActivationInstantiator inst)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
            throws RemoteException, ActivationException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
            MarshalledObject<? extends Remote> nstub = stub;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
            if (removed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
                throw new UnknownObjectException("object removed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
            } else if (!force && nstub != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
                return nstub;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
            nstub = inst.newInstance(id, desc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
            stub = nstub;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
             * stub could be set to null by a group reset, so return
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
             * the newstub here to prevent returning null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
            return nstub;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
        void reset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
            stub = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
     * Add a record to the activation log. If the number of updates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
     * passes a predetermined threshold, record a snapshot.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
    private void addLogRecord(LogRecord rec) throws ActivationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
        synchronized (log) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
            checkShutdown();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
                log.update(rec, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
                numUpdates = snapshotInterval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
                System.err.println(getTextResource("rmid.log.update.warning"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
                e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
            if (++numUpdates < snapshotInterval) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
                log.snapshot(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
                numUpdates = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
                System.err.println(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
                    getTextResource("rmid.log.snapshot.warning"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
                e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
                    // shutdown activation system because snapshot failed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
                    system.shutdown();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
                } catch (RemoteException ignore) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
                    // can't happen
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
                // warn the client of the original update problem
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
                throw new ActivationException("log snapshot failed", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
     * Handler for the log that knows how to take the initial snapshot
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
     * and apply an update (a LogRecord) to the current state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
    private static class ActLogHandler extends LogHandler {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
        ActLogHandler() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
        public Object initialSnapshot()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
             * Return an empty Activation object.  Log will update
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
             * this object with recovered state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
            return new Activation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
        public Object applyUpdate(Object update, Object state)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
            throws Exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
            return ((LogRecord) update).apply(state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
     * Abstract class for all log records. The subclass contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
     * specific update information and implements the apply method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
     * that applys the update information contained in the record
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
     * to the current state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
    private static abstract class LogRecord implements Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
        /** indicate compatibility with JDK 1.2 version of class */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
        private static final long serialVersionUID = 8395140512322687529L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
        abstract Object apply(Object state) throws Exception;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
     * Log record for registering an object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
    private static class LogRegisterObject extends LogRecord {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
        /** indicate compatibility with JDK 1.2 version of class */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
        private static final long serialVersionUID = -6280336276146085143L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
        private ActivationID id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
        private ActivationDesc desc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
        LogRegisterObject(ActivationID id, ActivationDesc desc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
            this.id = id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
            this.desc = desc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
        Object apply(Object state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
                ((Activation) state).getGroupEntry(desc.getGroupID()).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
                    registerObject(id, desc, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
            } catch (Exception ignore) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
                System.err.println(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
                    MessageFormat.format(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
                        getTextResource("rmid.log.recover.warning"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
                        "LogRegisterObject"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
                ignore.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
            return state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
     * Log record for unregistering an object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
    private static class LogUnregisterObject extends LogRecord {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
        /** indicate compatibility with JDK 1.2 version of class */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
        private static final long serialVersionUID = 6269824097396935501L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
        private ActivationID id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
        LogUnregisterObject(ActivationID id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
            this.id = id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
        Object apply(Object state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
                ((Activation) state).getGroupEntry(id).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
                    unregisterObject(id, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
            } catch (Exception ignore) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
                System.err.println(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
                    MessageFormat.format(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
                        getTextResource("rmid.log.recover.warning"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
                        "LogUnregisterObject"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
                ignore.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
            return state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
     * Log record for registering a group.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
    private static class LogRegisterGroup extends LogRecord {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
        /** indicate compatibility with JDK 1.2 version of class */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
        private static final long serialVersionUID = -1966827458515403625L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
        private ActivationGroupID id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
        private ActivationGroupDesc desc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
        LogRegisterGroup(ActivationGroupID id, ActivationGroupDesc desc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
            this.id = id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
            this.desc = desc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
        Object apply(Object state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
            // modify state directly; cant ask a nonexistent GroupEntry
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
            // to register itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
            ((Activation) state).groupTable.put(id, ((Activation) state).new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
                                                GroupEntry(id, desc));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
            return state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
     * Log record for udpating an activation desc
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
    private static class LogUpdateDesc extends LogRecord {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
        /** indicate compatibility with JDK 1.2 version of class */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
        private static final long serialVersionUID = 545511539051179885L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
        private ActivationID id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
        private ActivationDesc desc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
        LogUpdateDesc(ActivationID id, ActivationDesc desc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
            this.id = id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
            this.desc = desc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
        Object apply(Object state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
                ((Activation) state).getGroupEntry(id).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
                    setActivationDesc(id, desc, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
            } catch (Exception ignore) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
                System.err.println(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
                    MessageFormat.format(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
                        getTextResource("rmid.log.recover.warning"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
                        "LogUpdateDesc"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
                ignore.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
            return state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
     * Log record for unregistering a group.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
    private static class LogUpdateGroupDesc extends LogRecord {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
        /** indicate compatibility with JDK 1.2 version of class */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
        private static final long serialVersionUID = -1271300989218424337L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
        private ActivationGroupID id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
        private ActivationGroupDesc desc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
        LogUpdateGroupDesc(ActivationGroupID id, ActivationGroupDesc desc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
            this.id = id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
            this.desc = desc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
        Object apply(Object state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
                ((Activation) state).getGroupEntry(id).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
                    setActivationGroupDesc(id, desc, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
            } catch (Exception ignore) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
                System.err.println(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
                    MessageFormat.format(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
                        getTextResource("rmid.log.recover.warning"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
                        "LogUpdateGroupDesc"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
                ignore.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
            return state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
     * Log record for unregistering a group.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
    private static class LogUnregisterGroup extends LogRecord {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
        /** indicate compatibility with JDK 1.2 version of class */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
        private static final long serialVersionUID = -3356306586522147344L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
        private ActivationGroupID id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
        LogUnregisterGroup(ActivationGroupID id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
            this.id = id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
        Object apply(Object state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
            GroupEntry entry = ((Activation) state).groupTable.remove(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
                entry.unregisterGroup(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
            } catch (Exception ignore) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
                System.err.println(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
                    MessageFormat.format(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
                        getTextResource("rmid.log.recover.warning"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
                        "LogUnregisterGroup"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
                ignore.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
            return state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
     * Log record for an active group incarnation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
    private static class LogGroupIncarnation extends LogRecord {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
        /** indicate compatibility with JDK 1.2 version of class */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
        private static final long serialVersionUID = 4146872747377631897L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
        private ActivationGroupID id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
        private long inc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
        LogGroupIncarnation(ActivationGroupID id, long inc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
            this.id = id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
            this.inc = inc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
        Object apply(Object state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
                GroupEntry entry = ((Activation) state).getGroupEntry(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
                entry.incarnation = inc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
            } catch (Exception ignore) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
                System.err.println(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
                    MessageFormat.format(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
                        getTextResource("rmid.log.recover.warning"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
                        "LogGroupIncarnation"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
                ignore.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
            return state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
     * Initialize command to exec a default group.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
    private void initCommand(String[] childArgs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
        command = new String[childArgs.length + 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
        AccessController.doPrivileged(new PrivilegedAction<Void>() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
            public Void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
                    command[0] = System.getProperty("java.home") +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
                        File.separator + "bin" + File.separator + "java";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
                } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
                    System.err.println(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
                        getTextResource("rmid.unfound.java.home.property"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
                    command[0] = "java";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
        System.arraycopy(childArgs, 0, command, 1, childArgs.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
        command[command.length-1] = "sun.rmi.server.ActivationGroupInit";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
    private static void bomb(String error) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
        System.err.println("rmid: " + error); // $NON-NLS$
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
        System.err.println(MessageFormat.format(getTextResource("rmid.usage"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
                    "rmid"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
        System.exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
     * The default policy for checking a command before it is executed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
     * makes sure the appropriate com.sun.rmi.rmid.ExecPermission and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
     * set of com.sun.rmi.rmid.ExecOptionPermissions have been granted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
    public static class DefaultExecPolicy {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
        public void checkExecCommand(ActivationGroupDesc desc, String[] cmd)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
            throws SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
            PermissionCollection perms = getExecPermissions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
             * Check properties overrides.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
            Properties props = desc.getPropertyOverrides();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
            if (props != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
                Enumeration<?> p = props.propertyNames();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
                while (p.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
                    String name = (String) p.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
                    String value = props.getProperty(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
                    String option = "-D" + name + "=" + value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
                        checkPermission(perms,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
                            new ExecOptionPermission(option));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
                    } catch (AccessControlException e) {
52902
e3398b2e1ab0 8214971: Replace use of string.equals("") with isEmpty()
rriggs
parents: 47216
diff changeset
  1860
                        if (value.isEmpty()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
                            checkPermission(perms,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
                                new ExecOptionPermission("-D" + name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1863
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1864
                            throw e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
             * Check group class name (allow nothing but the default),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
             * code location (must be null), and data (must be null).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
            String groupClassName = desc.getClassName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
            if ((groupClassName != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
                 !groupClassName.equals(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
                    ActivationGroupImpl.class.getName())) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
                (desc.getLocation() != null) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
                (desc.getData() != null))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
                throw new AccessControlException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
                    "access denied (custom group implementation not allowed)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1883
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1886
             * If group descriptor has a command environment, check
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
             * command and options.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
            ActivationGroupDesc.CommandEnvironment cmdenv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
            cmdenv = desc.getCommandEnvironment();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
            if (cmdenv != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
                String path = cmdenv.getCommandPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
                if (path != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
                    checkPermission(perms, new ExecPermission(path));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1897
                String[] options = cmdenv.getCommandOptions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1898
                if (options != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1899
                    for (String option : options) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
                        checkPermission(perms,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1901
                                        new ExecOptionPermission(option));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1902
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1904
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1905
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1907
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1908
         * Prints warning message if installed Policy is the default Policy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1909
         * implementation and globally granted permissions do not include
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1910
         * AllPermission or any ExecPermissions/ExecOptionPermissions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1911
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1912
        static void checkConfiguration() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
            Policy policy =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1914
                AccessController.doPrivileged(new PrivilegedAction<Policy>() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
                    public Policy run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
                        return Policy.getPolicy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1918
                });
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1919
            if (!(policy instanceof PolicyFile)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1920
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1921
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1922
            PermissionCollection perms = getExecPermissions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1923
            for (Enumeration<Permission> e = perms.elements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1924
                 e.hasMoreElements();)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1925
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1926
                Permission p = e.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1927
                if (p instanceof AllPermission ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1928
                    p instanceof ExecPermission ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1929
                    p instanceof ExecOptionPermission)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1930
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1931
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1932
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1933
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1934
            System.err.println(getTextResource("rmid.exec.perms.inadequate"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1935
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1936
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1937
        private static PermissionCollection getExecPermissions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1938
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1939
             * The approach used here is taken from the similar method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1940
             * getLoaderAccessControlContext() in the class
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1941
             * sun.rmi.server.LoaderHandler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1942
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1943
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1944
            // obtain permissions granted to all code in current policy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1945
            PermissionCollection perms = AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1946
                new PrivilegedAction<PermissionCollection>() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1947
                    public PermissionCollection run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1948
                        CodeSource codesource =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1949
                            new CodeSource(null, (Certificate[]) null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1950
                        Policy p = Policy.getPolicy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1951
                        if (p != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1952
                            return p.getPermissions(codesource);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1953
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1954
                            return new Permissions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1955
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
                });
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1959
            return perms;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1960
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1961
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
        private static void checkPermission(PermissionCollection perms,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1963
                                            Permission p)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1964
            throws AccessControlException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1965
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1966
            if (!perms.implies(p)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
                throw new AccessControlException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
                   "access denied " + p.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1970
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1972
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1973
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
     * Main program to start the activation system. <br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
     * The usage is as follows: rmid [-port num] [-log dir].
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1976
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1977
    public static void main(String[] args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1978
        boolean stop = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1980
        // Create and install the security manager if one is not installed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1981
        // already.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1982
        if (System.getSecurityManager() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1983
            System.setSecurityManager(new SecurityManager());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1985
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1986
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
            int port = ActivationSystem.SYSTEM_PORT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1988
            RMIServerSocketFactory ssf = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1989
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1990
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1991
             * If rmid has an inherited channel (meaning that it was
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1992
             * launched from inetd), set the server socket factory to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1993
             * return the inherited server socket.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1994
             **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1995
            Channel inheritedChannel = AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1996
                new PrivilegedExceptionAction<Channel>() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1997
                    public Channel run() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1998
                        return System.inheritedChannel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1999
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2000
                });
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2001
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2002
            if (inheritedChannel != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2003
                inheritedChannel instanceof ServerSocketChannel)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2004
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2005
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2006
                 * Redirect System.err output to a file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2007
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2008
                AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2009
                    new PrivilegedExceptionAction<Void>() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2010
                        public Void run() throws IOException {
41751
365b2e7c0d2c 8085192: java/rmi/activation/Activatable tests fail intermittently due to "Port already in use"
chegar
parents: 37782
diff changeset
  2011
                            boolean disable = Boolean.getBoolean(
365b2e7c0d2c 8085192: java/rmi/activation/Activatable tests fail intermittently due to "Port already in use"
chegar
parents: 37782
diff changeset
  2012
                                    "sun.rmi.server.activation.disableErrRedirect");
365b2e7c0d2c 8085192: java/rmi/activation/Activatable tests fail intermittently due to "Port already in use"
chegar
parents: 37782
diff changeset
  2013
                            if (disable)
365b2e7c0d2c 8085192: java/rmi/activation/Activatable tests fail intermittently due to "Port already in use"
chegar
parents: 37782
diff changeset
  2014
                                return null;
365b2e7c0d2c 8085192: java/rmi/activation/Activatable tests fail intermittently due to "Port already in use"
chegar
parents: 37782
diff changeset
  2015
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2016
                            File file =
13041
8477cb6992be 7143606: File.createTempFile should be improved for temporary files created by the platform.
robm
parents: 12040
diff changeset
  2017
                                Files.createTempFile("rmid-err", null).toFile();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2018
                            PrintStream errStream =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2019
                                new PrintStream(new FileOutputStream(file));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2020
                            System.setErr(errStream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2021
                            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2022
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2023
                    });
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2024
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2025
                ServerSocket serverSocket =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2026
                    ((ServerSocketChannel) inheritedChannel).socket();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2027
                port = serverSocket.getLocalPort();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2028
                ssf = new ActivationServerSocketFactory(serverSocket);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2029
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2030
                System.err.println(new Date());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2031
                System.err.println(getTextResource(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2032
                                       "rmid.inherited.channel.info") +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2033
                                       ": " + inheritedChannel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2034
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2035
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2036
            String log = null;
12040
558b0e0d5910 7146763: Warnings cleanup in the sun.rmi and related packages
khazra
parents: 9502
diff changeset
  2037
            List<String> childArgs = new ArrayList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2038
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2039
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2040
             * Parse arguments
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2041
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2042
            for (int i = 0; i < args.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2043
                if (args[i].equals("-port")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2044
                    if (ssf != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2045
                        bomb(getTextResource("rmid.syntax.port.badarg"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2046
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2047
                    if ((i + 1) < args.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2048
                        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2049
                            port = Integer.parseInt(args[++i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2050
                        } catch (NumberFormatException nfe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2051
                            bomb(getTextResource("rmid.syntax.port.badnumber"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2052
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2053
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2054
                        bomb(getTextResource("rmid.syntax.port.missing"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2055
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2056
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2057
                } else if (args[i].equals("-log")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2058
                    if ((i + 1) < args.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2059
                        log = args[++i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2060
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2061
                        bomb(getTextResource("rmid.syntax.log.missing"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2062
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2063
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2064
                } else if (args[i].equals("-stop")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2065
                    stop = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2066
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2067
                } else if (args[i].startsWith("-C")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2068
                    childArgs.add(args[i].substring(2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2069
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2070
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2071
                    bomb(MessageFormat.format(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2072
                        getTextResource("rmid.syntax.illegal.option"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2073
                        args[i]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2074
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2075
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2076
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2077
            if (log == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2078
                if (ssf != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2079
                    bomb(getTextResource("rmid.syntax.log.required"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2080
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2081
                    log = "log";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2082
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2083
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2084
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2085
            debugExec = AccessController.doPrivileged(
23333
b0af2c7c8c91 8035808: Eliminate dependency to GetPropertyAction and other sun.security.action convenient classes
mchung
parents: 22619
diff changeset
  2086
                (PrivilegedAction<Boolean>) () -> Boolean.getBoolean("sun.rmi.server.activation.debugExec"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2087
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2088
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2089
             * Determine class name for activation exec policy (if any).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2090
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2091
            String execPolicyClassName = AccessController.doPrivileged(
23333
b0af2c7c8c91 8035808: Eliminate dependency to GetPropertyAction and other sun.security.action convenient classes
mchung
parents: 22619
diff changeset
  2092
                (PrivilegedAction<String>) () -> System.getProperty("sun.rmi.activation.execPolicy"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2093
            if (execPolicyClassName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2094
                if (!stop) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2095
                    DefaultExecPolicy.checkConfiguration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2096
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2097
                execPolicyClassName = "default";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2098
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2099
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2100
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2101
             * Initialize method for activation exec policy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2102
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2103
            if (!execPolicyClassName.equals("none")) {
52902
e3398b2e1ab0 8214971: Replace use of string.equals("") with isEmpty()
rriggs
parents: 47216
diff changeset
  2104
                if (execPolicyClassName.isEmpty() ||
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2105
                    execPolicyClassName.equals("default"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2106
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2107
                    execPolicyClassName = DefaultExecPolicy.class.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2108
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2109
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2110
                try {
12040
558b0e0d5910 7146763: Warnings cleanup in the sun.rmi and related packages
khazra
parents: 9502
diff changeset
  2111
                    Class<?> execPolicyClass = getRMIClass(execPolicyClassName);
37782
ad8fe7507ecc 6850612: Deprecate Class.newInstance since it violates the checked exception language contract
darcy
parents: 25859
diff changeset
  2112
                    @SuppressWarnings("deprecation")
ad8fe7507ecc 6850612: Deprecate Class.newInstance since it violates the checked exception language contract
darcy
parents: 25859
diff changeset
  2113
                    Object tmp = execPolicyClass.newInstance();
ad8fe7507ecc 6850612: Deprecate Class.newInstance since it violates the checked exception language contract
darcy
parents: 25859
diff changeset
  2114
                    execPolicy = tmp;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2115
                    execPolicyMethod =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2116
                        execPolicyClass.getMethod("checkExecCommand",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2117
                                                  ActivationGroupDesc.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2118
                                                  String[].class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2119
                } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2120
                    if (debugExec) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2121
                        System.err.println(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2122
                            getTextResource("rmid.exec.policy.exception"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2123
                        e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2124
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2125
                    bomb(getTextResource("rmid.exec.policy.invalid"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2126
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2127
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2128
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2129
            if (stop == true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2130
                final int finalPort = port;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2131
                AccessController.doPrivileged(new PrivilegedAction<Void>() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2132
                    public Void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2133
                        System.setProperty("java.rmi.activation.port",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2134
                                           Integer.toString(finalPort));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2135
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2136
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2137
                });
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2138
                ActivationSystem system = ActivationGroup.getSystem();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2139
                system.shutdown();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2140
                System.exit(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2141
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2142
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2143
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2144
             * Fix for 4173960: Create and initialize activation using
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2145
             * a static method, startActivation, which will build the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2146
             * Activation state in two ways: if when rmid is run, no
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2147
             * log file is found, the ActLogHandler.recover(...)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2148
             * method will create a new Activation instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2149
             * Alternatively, if a logfile is available, a serialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2150
             * instance of activation will be read from the log's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2151
             * snapshot file.  Log updates will be applied to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2152
             * Activation object until rmid's state has been fully
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2153
             * recovered.  In either case, only one instance of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2154
             * Activation is created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2155
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2156
            startActivation(port, ssf, log,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2157
                            childArgs.toArray(new String[childArgs.size()]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2158
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2159
            // prevent activator from exiting
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2160
            while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2161
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2162
                    Thread.sleep(Long.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2163
                } catch (InterruptedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2164
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2165
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2166
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2167
            System.err.println(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2168
                MessageFormat.format(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2169
                    getTextResource("rmid.unexpected.exception"), e));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2170
            e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2171
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2172
        System.exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2173
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2174
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2175
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2176
     * Retrieves text resources from the locale-specific properties file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2177
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2178
    private static String getTextResource(String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2179
        if (Activation.resources == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2180
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2181
                Activation.resources = ResourceBundle.getBundle(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2182
                    "sun.rmi.server.resources.rmid");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2183
            } catch (MissingResourceException mre) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2184
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2185
            if (Activation.resources == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2186
                // throwing an Error is a bit extreme, methinks
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2187
                return ("[missing resource file: " + key + "]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2188
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2189
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2190
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2191
        String val = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2192
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2193
            val = Activation.resources.getString (key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2194
        } catch (MissingResourceException mre) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2195
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2196
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2197
        if (val == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2198
            return ("[missing resource: " + key + "]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2199
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2200
            return val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2201
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2202
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2203
12040
558b0e0d5910 7146763: Warnings cleanup in the sun.rmi and related packages
khazra
parents: 9502
diff changeset
  2204
    @SuppressWarnings("deprecation")
558b0e0d5910 7146763: Warnings cleanup in the sun.rmi and related packages
khazra
parents: 9502
diff changeset
  2205
    private static Class<?> getRMIClass(String execPolicyClassName) throws Exception  {
558b0e0d5910 7146763: Warnings cleanup in the sun.rmi and related packages
khazra
parents: 9502
diff changeset
  2206
        return RMIClassLoader.loadClass(execPolicyClassName);
558b0e0d5910 7146763: Warnings cleanup in the sun.rmi and related packages
khazra
parents: 9502
diff changeset
  2207
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2208
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2209
     * Dijkstra semaphore operations to limit the number of subprocesses
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2210
     * rmid attempts to make at once.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2211
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2212
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2213
     * Acquire the group semaphore and return a group name.  Each
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2214
     * Pstartgroup must be followed by a Vstartgroup.  The calling thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2215
     * will wait until there are fewer than <code>N</code> other threads
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2216
     * holding the group semaphore.  The calling thread will then acquire
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2217
     * the semaphore and return.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2218
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2219
    private synchronized String Pstartgroup() throws ActivationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2220
        while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2221
            checkShutdown();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2222
            // Wait until positive, then decrement.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2223
            if (groupSemaphore > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2224
                groupSemaphore--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2225
                return "Group-" + groupCounter++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2226
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2227
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2228
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2229
                wait();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2230
            } catch (InterruptedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2231
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2232
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2233
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2234
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2235
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2236
     * Release the group semaphore.  Every P operation must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2237
     * followed by a V operation.  This may cause another thread to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2238
     * wake up and return from its P operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2239
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2240
    private synchronized void Vstartgroup() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2241
        // Increment and notify a waiter (not necessarily FIFO).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2242
        groupSemaphore++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2243
        notifyAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2244
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2245
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2246
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2247
     * A server socket factory to use when rmid is launched via 'inetd'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2248
     * with 'wait' status.  This socket factory's 'createServerSocket'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2249
     * method returns the server socket specified during construction that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2250
     * is specialized to delay accepting requests until the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2251
     * 'initDone' flag is 'true'.  The server socket supplied to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2252
     * the constructor should be the server socket obtained from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2253
     * ServerSocketChannel returned from the 'System.inheritedChannel'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2254
     * method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2255
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2256
    private static class ActivationServerSocketFactory
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2257
        implements RMIServerSocketFactory
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2258
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2259
        private final ServerSocket serverSocket;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2260
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2261
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2262
         * Constructs an 'ActivationServerSocketFactory' with the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2263
         * 'serverSocket'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2264
         **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2265
        ActivationServerSocketFactory(ServerSocket serverSocket) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2266
            this.serverSocket = serverSocket;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2267
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2268
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2269
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2270
         * Returns the server socket specified during construction wrapped
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2271
         * in a 'DelayedAcceptServerSocket'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2272
         **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2273
        public ServerSocket createServerSocket(int port)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2274
            throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2275
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2276
            return new DelayedAcceptServerSocket(serverSocket);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2277
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2278
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2279
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2280
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2281
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2282
     * A server socket that delegates all public methods to the underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2283
     * server socket specified at construction.  The accept method is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2284
     * overridden to delay calling accept on the underlying server socket
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2285
     * until the 'initDone' flag is 'true'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2286
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2287
    private static class DelayedAcceptServerSocket extends ServerSocket {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2288
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2289
        private final ServerSocket serverSocket;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2290
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2291
        DelayedAcceptServerSocket(ServerSocket serverSocket)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2292
            throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2293
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2294
            this.serverSocket = serverSocket;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2295
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2296
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2297
        public void bind(SocketAddress endpoint) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2298
            serverSocket.bind(endpoint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2299
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2300
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2301
        public void bind(SocketAddress endpoint, int backlog)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2302
                throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2303
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2304
            serverSocket.bind(endpoint, backlog);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2305
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2306
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2307
        public InetAddress getInetAddress() {
18212
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 13041
diff changeset
  2308
            return AccessController.doPrivileged(
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 13041
diff changeset
  2309
                new PrivilegedAction<InetAddress>() {
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 13041
diff changeset
  2310
                    @Override
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 13041
diff changeset
  2311
                    public InetAddress run() {
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 13041
diff changeset
  2312
                        return serverSocket.getInetAddress();
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 13041
diff changeset
  2313
                    }
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 13041
diff changeset
  2314
                });
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2315
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2316
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2317
        public int getLocalPort() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2318
            return serverSocket.getLocalPort();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2319
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2320
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2321
        public SocketAddress getLocalSocketAddress() {
18212
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 13041
diff changeset
  2322
            return AccessController.doPrivileged(
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 13041
diff changeset
  2323
                new PrivilegedAction<SocketAddress>() {
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 13041
diff changeset
  2324
                    @Override
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 13041
diff changeset
  2325
                    public SocketAddress run() {
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 13041
diff changeset
  2326
                        return serverSocket.getLocalSocketAddress();
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 13041
diff changeset
  2327
                    }
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 13041
diff changeset
  2328
                });
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2329
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2330
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2331
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2332
         * Delays calling accept on the underlying server socket until the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2333
         * remote service is bound in the registry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2334
         **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2335
        public Socket accept() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2336
            synchronized (initLock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2337
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2338
                    while (!initDone) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2339
                        initLock.wait();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2340
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2341
                } catch (InterruptedException ignore) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2342
                    throw new AssertionError(ignore);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2343
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2344
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2345
            return serverSocket.accept();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2346
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2347
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2348
        public void close() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2349
            serverSocket.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2350
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2351
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2352
        public ServerSocketChannel getChannel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2353
            return serverSocket.getChannel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2354
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2355
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2356
        public boolean isBound() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2357
            return serverSocket.isBound();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2358
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2359
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2360
        public boolean isClosed() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2361
            return serverSocket.isClosed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2362
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2363
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2364
        public void setSoTimeout(int timeout)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2365
            throws SocketException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2366
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2367
            serverSocket.setSoTimeout(timeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2368
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2369
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2370
        public int getSoTimeout() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2371
            return serverSocket.getSoTimeout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2372
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2373
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2374
        public void setReuseAddress(boolean on) throws SocketException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2375
            serverSocket.setReuseAddress(on);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2376
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2377
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2378
        public boolean getReuseAddress() throws SocketException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2379
            return serverSocket.getReuseAddress();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2380
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2381
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2382
        public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2383
            return serverSocket.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2384
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2385
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2386
        public void setReceiveBufferSize(int size)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2387
            throws SocketException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2388
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2389
            serverSocket.setReceiveBufferSize(size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2390
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2391
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2392
        public int getReceiveBufferSize()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2393
            throws SocketException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2394
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2395
            return serverSocket.getReceiveBufferSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2396
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2397
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2398
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2399
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2400
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2401
 * PipeWriter plugs together two pairs of input and output streams by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2402
 * providing readers for input streams and writing through to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2403
 * appropriate output streams.  Both output streams are annotated on a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2404
 * per-line basis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2405
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2406
 * @author Laird Dornin, much code borrowed from Peter Jones, Ken
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2407
 *         Arnold and Ann Wollrath.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2408
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2409
class PipeWriter implements Runnable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2410
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2411
    /** stream used for buffering lines */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2412
    private ByteArrayOutputStream bufOut;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2413
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2414
    /** count since last separator */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2415
    private int cLast;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2416
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2417
    /** current chunk of input being compared to lineSeparator.*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2418
    private byte[] currSep;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2419
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2420
    private PrintWriter out;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2421
    private InputStream in;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2422
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2423
    private String pipeString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2424
    private String execString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2425
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2426
    private static String lineSeparator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2427
    private static int lineSeparatorLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2428
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2429
    private static int numExecs = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2430
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2431
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2432
        lineSeparator = AccessController.doPrivileged(
23333
b0af2c7c8c91 8035808: Eliminate dependency to GetPropertyAction and other sun.security.action convenient classes
mchung
parents: 22619
diff changeset
  2433
           (PrivilegedAction<String>) () -> System.getProperty("line.separator"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2434
        lineSeparatorLength = lineSeparator.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2435
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2436
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2437
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2438
     * Create a new PipeWriter object. All methods of PipeWriter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2439
     * except plugTogetherPair, are only accesible to PipeWriter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2440
     * itself.  Synchronization is unnecessary on functions that will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2441
     * only be used internally in PipeWriter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2442
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2443
     * @param in input stream from which pipe input flows
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2444
     * @param out output stream to which log messages will be sent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2445
     * @param dest String which tags output stream as 'out' or 'err'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2446
     * @param nExecs number of execed processes, Activation groups.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2447
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2448
    private PipeWriter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2449
        (InputStream in, OutputStream out, String tag, int nExecs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2450
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2451
        this.in = in;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2452
        this.out = new PrintWriter(out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2453
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2454
        bufOut = new ByteArrayOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2455
        currSep = new byte[lineSeparatorLength];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2456
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2457
        /* set unique pipe/pair annotations */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2458
        execString = ":ExecGroup-" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2459
            Integer.toString(nExecs) + ':' + tag + ':';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2460
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2461
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2462
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2463
     * Create a thread to listen and read from input stream, in.  buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2464
     * the data that is read until a marker which equals lineSeparator
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2465
     * is read.  Once such a string has been discovered; write out an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2466
     * annotation string followed by the buffered data and a line
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2467
     * separator.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2468
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2469
    public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2470
        byte[] buf = new byte[256];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2471
        int count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2472
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2473
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2474
            /* read bytes till there are no more. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2475
            while ((count = in.read(buf)) != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2476
                write(buf, 0, count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2477
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2478
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2479
            /*  flush internal buffer... may not have ended on a line
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2480
             *  separator, we also need a last annotation if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2481
             *  something was left.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2482
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2483
            String lastInBuffer = bufOut.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2484
            bufOut.reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2485
            if (lastInBuffer.length() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2486
                out.println (createAnnotation() + lastInBuffer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2487
                out.flush();                    // add a line separator
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2488
                                                // to make output nicer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2489
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2490
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2491
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2492
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2493
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2494
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2495
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2496
     * Write a subarray of bytes.  Pass each through write byte method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2497
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2498
    private void write(byte b[], int off, int len) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2499
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2500
        if (len < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2501
            throw new ArrayIndexOutOfBoundsException(len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2502
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2503
        for (int i = 0; i < len; ++ i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2504
            write(b[off + i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2505
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2506
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2507
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2508
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2509
     * Write a byte of data to the stream.  If we have not matched a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2510
     * line separator string, then the byte is appended to the internal
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2511
     * buffer.  If we have matched a line separator, then the currently
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2512
     * buffered line is sent to the output writer with a prepended
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2513
     * annotation string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2514
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2515
    private void write(byte b) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2516
        int i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2517
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2518
        /* shift current to the left */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2519
        for (i = 1 ; i < (currSep.length); i ++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2520
            currSep[i-1] = currSep[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2521
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2522
        currSep[i-1] = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2523
        bufOut.write(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2524
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2525
        /* enough characters for a separator? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2526
        if ( (cLast >= (lineSeparatorLength - 1)) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2527
             (lineSeparator.equals(new String(currSep))) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2528
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2529
            cLast = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2530
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2531
            /* write prefix through to underlying byte stream */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2532
            out.print(createAnnotation() + bufOut.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2533
            out.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2534
            bufOut.reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2535
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2536
            if (out.checkError()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2537
                throw new IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2538
                    ("PipeWriter: IO Exception when"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2539
                     " writing to output stream.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2540
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2541
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2542
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2543
            cLast++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2544
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2545
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2546
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2547
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2548
     * Create an annotation string to be printed out after
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2549
     * a new line and end of stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2550
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2551
    private String createAnnotation() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2552
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2553
        /* construct prefix for log messages:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2554
         * date/time stamp...
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2555
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2556
        return ((new Date()).toString()  +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2557
                 /* ... print pair # ... */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2558
                 (execString));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2559
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2560
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2561
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2562
     * Allow plugging together two pipes at a time, to associate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2563
     * output from an execed process.  This is the only publicly
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2564
     * accessible method of this object; this helps ensure that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2565
     * synchronization will not be an issue in the annotation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2566
     * process.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2567
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2568
     * @param in input stream from which pipe input comes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2569
     * @param out output stream to which log messages will be sent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2570
     * @param in1 input stream from which pipe input comes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2571
     * @param out1 output stream to which log messages will be sent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2572
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2573
    static void plugTogetherPair(InputStream in,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2574
                                 OutputStream out,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2575
                                 InputStream in1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2576
                                 OutputStream out1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2577
        Thread inThread = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2578
        Thread outThread = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2579
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2580
        int nExecs = getNumExec();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2581
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2582
        /* start RMI threads to read output from child process */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2583
        inThread = AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2584
            new NewThreadAction(new PipeWriter(in, out, "out", nExecs),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2585
                                "out", true));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2586
        outThread = AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2587
            new NewThreadAction(new PipeWriter(in1, out1, "err", nExecs),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2588
                                "err", true));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2589
        inThread.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2590
        outThread.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2591
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2592
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2593
    private static synchronized int getNumExec() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2594
        return numExecs++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2595
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2596
}