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