jdk/test/java/rmi/testlibrary/RMID.java
author weijun
Fri, 20 Jun 2008 12:05:02 +0800
changeset 793 8183c2b0985f
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
6716534: Krb5LoginModule has not cleaned temp info between authentication attempts Reviewed-by: valeriep
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1998-2006 Sun Microsystems, Inc.  All Rights Reserved.
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.rmi.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.rmi.activation.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.Properties;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * Utility class that creates an instance of rmid with a policy
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * file of name <code>TestParams.defaultPolicy</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * Activation groups should run with the same security manager as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * test.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
public class RMID extends JavaVM {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    public static String MANAGER_OPTION="-Djava.security.manager=";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    /** Test port for rmid */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    private final int port;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    /** Initial log name */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    protected static String log = "log";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    /** rmid's logfile directory; currently must be "." */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    protected static String LOGDIR = ".";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    private static void mesg(Object mesg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        System.err.println("RMID: " + mesg.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    /** make test options and arguments */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    private static String makeOptions(boolean debugExec) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        String options = " -Dsun.rmi.server.activation.debugExec=" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
            debugExec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        // +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        //" -Djava.compiler= ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        // if test params set, want to propagate them
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        if (!TestParams.testSrc.equals("")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            options += " -Dtest.src=" + TestParams.testSrc + " ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        //if (!TestParams.testClasses.equals("")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        //    options += " -Dtest.classes=" + TestParams.testClasses + " ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        //}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        options += " -Dtest.classes=" + TestParams.testClasses //;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
         +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
         " -Djava.rmi.server.logLevel=v ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        // +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        // " -Djava.security.debug=all ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        return options;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    private static String makeArgs(boolean includePortArg, int port) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        String propagateManager = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        // rmid will run with a security manager set, but no policy
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        // file - it should not need one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        if (System.getSecurityManager() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            propagateManager = MANAGER_OPTION +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                TestParams.defaultSecurityManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            propagateManager = MANAGER_OPTION +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                System.getSecurityManager().getClass().getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        // getAbsolutePath requires permission to read user.dir
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        String args =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            " -log " + (new File(LOGDIR, log)).getAbsolutePath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        if (includePortArg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            args += " -port " + port;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        // +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        //      " -C-Djava.compiler= ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        // if test params set, want to propagate them
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        if (!TestParams.testSrc.equals("")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            args += " -C-Dtest.src=" + TestParams.testSrc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        if (!TestParams.testClasses.equals("")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            args += " -C-Dtest.classes=" + TestParams.testClasses;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        args += " " + getCodeCoverageArgs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        return args;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * Routine that creates an rmid that will run with or without a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * policy file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    public static RMID createRMID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        return createRMID(System.out, System.err, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    public static RMID createRMID(boolean debugExec) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        return createRMID(System.out, System.err, debugExec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    public static RMID createRMID(OutputStream out, OutputStream err) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        return createRMID(out, err, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    public static RMID createRMID(OutputStream out, OutputStream err,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                                  boolean debugExec)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        return createRMID(out, err, debugExec, true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                          TestLibrary.RMID_PORT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    public static RMID createRMID(OutputStream out, OutputStream err,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                                  boolean debugExec, boolean includePortArg,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                                  int port)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        String options = makeOptions(debugExec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        String args = makeArgs(includePortArg, port);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        RMID rmid = new RMID("sun.rmi.server.Activation", options, args,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                             out, err, port);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        rmid.setPolicyFile(TestParams.defaultRmidPolicy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        return rmid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * Test RMID should be created with the createRMID method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    protected RMID(String classname, String options, String args,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                   OutputStream out, OutputStream err, int port)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        super(classname, options, args, out, err);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        this.port = port;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    public static void removeLog() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
         * Remove previous log file directory before
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
         * starting up rmid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        File f = new File(LOGDIR, log);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        if (f.exists()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            mesg("removing rmid's old log file...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            String[] files = f.list();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            if (files != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                for (int i=0; i<files.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                    (new File(f, files[i])).delete();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            if (f.delete() != true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                mesg("\t" + " unable to delete old log file.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * This method is used for adding arguments to rmid (not its VM)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * for passing as VM options to its child group VMs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * Returns the extra command line arguments required
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * to turn on jcov code coverage analysis for rmid child VMs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    protected static String getCodeCoverageArgs() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        return TestLibrary.getExtraProperty("rmid.jcov.args","");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    public void start() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        start(10000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    public void slowStart() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        start(60000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    public void start(long waitTime) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        if (getVM() != null) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        // if rmid is already running, then the test will fail with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        // a well recognized exception (port already in use...).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        mesg("starting rmid...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        super.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        int slopFactor = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            slopFactor = Integer.valueOf(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                TestLibrary.getExtraProperty("jcov.sleep.multiplier","1"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        } catch (NumberFormatException ignore) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        waitTime = waitTime * slopFactor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        // give rmid time to come up
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                Thread.sleep(Math.min(waitTime, 10000));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            } catch (InterruptedException ie) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                Thread.currentThread().interrupt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            waitTime -= 10000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            // is rmid present?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            if (ActivationLibrary.rmidRunning(port)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                mesg("finished starting rmid.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        } while (waitTime > 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        TestLibrary.bomb("start rmid failed... giving up", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    public void restart() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        destroy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * Ask rmid to shutdown gracefully using a remote method call.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * catch any errors that might occur from rmid not being present
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * at time of shutdown invocation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * Shutdown does not nullify possible references to the rmid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * process object (destroy does though).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    public static void shutdown() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        shutdown(TestLibrary.RMID_PORT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    public static void shutdown(int port) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            ActivationSystem system = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                mesg("getting a reference to the activation system");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                system = (ActivationSystem) Naming.lookup("//:" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                    port +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                    "/java.rmi.activation.ActivationSystem");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                mesg("obtained a reference to the activation system");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            } catch (java.net.MalformedURLException mue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            if (system == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                TestLibrary.bomb("reference to the activation system was null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            system.shutdown();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            mesg("caught exception trying to shutdown rmid");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            mesg(e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            // wait for the shutdown to happen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            Thread.sleep(5000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        } catch (InterruptedException ie) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            Thread.currentThread().interrupt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        mesg("testlibrary finished shutting down rmid");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * Ask rmid to shutdown gracefully but then destroy the rmid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * process if it does not exit by itself.  This method only works
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * if rmid is a child process of the current VM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    public void destroy() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        // attempt graceful shutdown of the activation system on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        // TestLibrary.RMID_PORT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        shutdown(port);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        if (vm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                // destroy rmid if it is still running...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                    vm.exitValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                    mesg("rmid exited on shutdown request");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                } catch (IllegalThreadStateException illegal) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                    mesg("Had to destroy RMID's process " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                         "using Process.destroy()");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                    super.destroy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                mesg("caught exception trying to destroy rmid: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                     e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            // rmid will not restart if its process is not null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            vm = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
}