jdk/test/java/rmi/activation/Activatable/shutdownGracefully/ShutdownGracefully.java
author smarks
Mon, 07 Jan 2013 18:09:07 -0800
changeset 15005 796ffc400e9e
parent 14778 5947768d173d
child 22990 daa64fcb5ba7
permissions -rw-r--r--
7187882: TEST_BUG: java/rmi/activation/checkusage/CheckUsage.java fails intermittently Summary: Tighten up JavaVM test library API, and adjust tests to match. Reviewed-by: mchung, dmocek
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
15005
796ffc400e9e 7187882: TEST_BUG: java/rmi/activation/checkusage/CheckUsage.java fails intermittently
smarks
parents: 14778
diff changeset
     2
 * Copyright (c) 1999, 2013, 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
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
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/* @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @bug 4183169
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @summary Minor problem with the way ReliableLog handles IOExceptions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * @author Laird Dornin; code borrowed from Ann Wollrath
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * @library ../../../testlibrary
14778
5947768d173d 8004748: clean up @build tags in RMI tests
smarks
parents: 5506
diff changeset
    31
 * @build TestLibrary RMID
5947768d173d 8004748: clean up @build tags in RMI tests
smarks
parents: 5506
diff changeset
    32
 *     TestSecurityManager RegisteringActivatable ShutdownGracefully_Stub
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * @run main/othervm/policy=security.policy/timeout=700 ShutdownGracefully
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.rmi.activation.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.rmi.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.util.Properties;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * The test creates an rmid with a special security manager.  After
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * rmid makes two registrations (which is greater than rmid's
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * snapshotInterval) the security manager stops allowing rmid to write
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * to update and snapshot log files in rmid's log directory.  The Test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * registers an Activatable object twice with different group ids.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * The second registration will cause rmid to have to write to a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * LogFile (it causes a snapshot) and the security manager will not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * allow the file write to happen.  The test makes sure that rmid
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * shuts down in a graceful manner without any explicit request to do
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * so.  The test will not exit for 400 seconds if rmid does not exit
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * (after that time, the test will fail).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
public class ShutdownGracefully
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    extends Activatable implements Runnable, RegisteringActivatable
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private static RegisteringActivatable registering = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    private final static long SHUTDOWN_TIMEOUT = 400 * 1000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    public static void main(String args[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        RMID rmid = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        System.err.println("\nRegression test for bug/rfe 4183169\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            TestLibrary.suggestSecurityManager(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
                "java.rmi.RMISecurityManager");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            // start an rmid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            RMID.removeLog();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            rmid = RMID.createRMID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            // rmid needs to run with a security manager that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            // simulates a log problem; rmid should also snapshot
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            // quickly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            rmid.addOptions(new String[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                "-Djava.security.manager=TestSecurityManager",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                "-Dsun.rmi.activation.snapshotInterval=1"});
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            //      rmid.addArguments(new String[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            //          "-C-Djava.rmi.server.logCalls=true"});
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            rmid.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            // Ensure that activation groups run with the correct
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            // security manager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            Properties p = new Properties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            p.put("java.security.policy",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                  TestParams.defaultGroupPolicy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            p.put("java.security.manager",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                  "java.lang.SecurityManager");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            System.err.println("activation group will be created " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                               "in a new VM");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            ActivationGroupDesc groupDesc =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                new ActivationGroupDesc(p, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            ActivationSystem system = ActivationGroup.getSystem();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            ActivationGroupID groupID = system.registerGroup(groupDesc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            System.err.println("registering activatable");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            ActivationDesc desc = new ActivationDesc
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                (groupID, "ShutdownGracefully", null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            registering = (RegisteringActivatable)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                Activatable.register(desc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            System.err.println("activate and deactivate object " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                               "via method call");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            registering.shutdown();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
             * the security manager rmid is running with will stop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
             * rmid from writing to its log files; in 1.2.x this would
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
             * have caused rmid to have thrown a runtime exception and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
             * continue running in an unstable state.  With the fix
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
             * for 4183169, rmid should shutdown gracefully instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
             * register another activatable with a new group id; rmid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
             * should not recover from this...  I use two
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
             * registrations to more closely simulate the environment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
             * in which the bug was found.  In java versions with out
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
             * the appropriate bug fix, rmid would hide a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
             * NullPointerException in this circumstance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            p.put("dummyname", "dummyvalue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            groupDesc = new ActivationGroupDesc(p, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            ActivationGroupID secondGroupID =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                system.registerGroup(groupDesc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            desc = new ActivationDesc(secondGroupID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                "ShutdownGracefully", null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                registering = (RegisteringActivatable)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                    Activatable.register(desc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                System.err.println("second activate and deactivate " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                                   "object via method call");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            } catch (ActivationException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                System.err.println("received exception from registration " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                                   "call that should have failed...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
             * no longer needed because the security manager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
             * throws an exception during snapshot
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                registering.shutdown();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                System.err.println("received exception from remote " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                                   "call that should have failed...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            } catch (RemoteException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            TestLibrary.bomb("\nfailure: unexpected exception ", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                Thread.sleep(4000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            } catch (InterruptedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            registering = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            // Need to make sure that rmid goes away by itself
15005
796ffc400e9e 7187882: TEST_BUG: java/rmi/activation/checkusage/CheckUsage.java fails intermittently
smarks
parents: 14778
diff changeset
   171
            JavaVM rmidProcess = rmid;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            if (rmidProcess != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                    Runnable waitThread =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                        new ShutdownDetectThread(rmidProcess);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                    synchronized (waitThread) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                        (new Thread(waitThread)).start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                        waitThread.wait(SHUTDOWN_TIMEOUT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                        System.err.println("rmid has shutdown");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                        if (!rmidDone) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                            // ensure that this rmid does not infect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                            // other tests.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                            rmidProcess.destroy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                            TestLibrary.bomb("rmid did not shutdown " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                                             "gracefully in time");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                    TestLibrary.bomb("exception waiting for rmid " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                                     "to shut down");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            // else rmid should be down
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        System.err.println
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            ("\nsuccess: ShutdownGracefully test passed ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    private static boolean rmidDone = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * class that waits for rmid to exit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    private static class ShutdownDetectThread implements Runnable {
15005
796ffc400e9e 7187882: TEST_BUG: java/rmi/activation/checkusage/CheckUsage.java fails intermittently
smarks
parents: 14778
diff changeset
   208
        private JavaVM rmidProcess = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
15005
796ffc400e9e 7187882: TEST_BUG: java/rmi/activation/checkusage/CheckUsage.java fails intermittently
smarks
parents: 14778
diff changeset
   210
        ShutdownDetectThread(JavaVM rmidProcess) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            this.rmidProcess = rmidProcess;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            System.err.println("waiting for rmid to shutdown");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                rmidProcess.waitFor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            } catch (InterruptedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                // should not happen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                // notify parent thread when rmid has exited
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                this.notify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                rmidDone = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            RMID.removeLog();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * implementation of RegisteringActivatable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    public ShutdownGracefully
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        (ActivationID id, MarshalledObject mo) throws RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        // register/export anonymously
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        super(id, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * Spawns a thread to deactivate the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    public void shutdown() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        (new Thread(this, "ShutdownGracefully")).start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * Thread to deactivate object. First attempts to make object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * inactive (via the inactive method).  If that fails (the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * object may still have pending/executing calls), then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * unexport the object forcibly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            Thread.sleep(50 * 1000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        } catch (InterruptedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        ActivationLibrary.deactivate(this, getID());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
}