jdk/test/javax/management/remote/mandatory/connection/MultiThreadDeadLockTest.java
author alanb
Thu, 20 Dec 2012 20:29:59 +0000
changeset 14917 bf08557604f8
parent 1243 f5d91fb6df32
child 21596 0e3a39f29dbc
permissions -rw-r--r--
8001048: JSR-160: Allow IIOP transport to be optional Reviewed-by: dsamersoff, dfuchs, mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1243
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
     1
/*
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
     2
 * To change this template, choose Tools | Templates
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
     3
 * and open the template in the editor.
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
     4
 */
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
     5
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
     6
import java.io.IOException;
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
     7
import java.io.Serializable;
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
     8
import java.net.Socket;
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
     9
import java.rmi.server.RMIClientSocketFactory;
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    10
import java.util.HashMap;
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    11
import javax.management.MBeanServer;
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    12
import javax.management.MBeanServerFactory;
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    13
import javax.management.Notification;
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    14
import javax.management.NotificationBroadcasterSupport;
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    15
import javax.management.NotificationListener;
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    16
import javax.management.ObjectName;
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    17
import javax.management.remote.JMXConnector;
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    18
import javax.management.remote.JMXConnectorFactory;
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    19
import javax.management.remote.JMXConnectorServer;
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    20
import javax.management.remote.JMXConnectorServerFactory;
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    21
import javax.management.remote.JMXServiceURL;
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    22
import javax.management.remote.rmi.RMIConnectorServer;
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    23
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    24
/*
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    25
 * @test
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    26
 * @bug 6697180
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    27
 * @summary test on a client notification deadlock.
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    28
 * @author Shanliang JIANG
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    29
 * @run clean MultiThreadDeadLockTest
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    30
 * @run build MultiThreadDeadLockTest
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    31
 * @run main MultiThreadDeadLockTest
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    32
 */
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    33
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    34
public class MultiThreadDeadLockTest {
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    35
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    36
    private static long serverTimeout = 500L;
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    37
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    38
    public static void main(String[] args) throws Exception {
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    39
        print("Create the MBean server");
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    40
        MBeanServer mbs = MBeanServerFactory.createMBeanServer();
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    41
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    42
        print("Initialize environment map");
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    43
        HashMap env = new HashMap();
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    44
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    45
        print("Specify a client socket factory to control socket creation.");
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    46
        env.put(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE,
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    47
                clientFactory);
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    48
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    49
        print("Specify a server idle timeout to make a server close an idle connection.");
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    50
        env.put("jmx.remote.x.server.connection.timeout", serverTimeout);
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    51
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    52
        print("Disable client heartbeat.");
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    53
        env.put("jmx.remote.x.client.connection.check.period", 0);
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    54
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    55
        env.put("jmx.remote.x.notification.fetch.timeout", serverTimeout);
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    56
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    57
        print("Create an RMI server");
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    58
        JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    59
        JMXConnectorServer server =
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    60
                JMXConnectorServerFactory.newJMXConnectorServer(url, env, mbs);
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    61
        server.start();
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    62
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    63
        url = server.getAddress();
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    64
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    65
        print("Create jmx client on "+url);
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    66
        StateMachine.setState(CREATE_SOCKET); // allow to create client socket
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    67
        client = JMXConnectorFactory.connect(url, env);
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    68
        Thread.sleep(100);
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    69
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    70
        totoName = new ObjectName("default:name=toto");
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    71
        mbs.registerMBean(toto, totoName);
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    72
        print("Register the mbean: " + totoName);
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    73
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    74
        print("Add listener to toto MBean");
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    75
        client.getMBeanServerConnection().addNotificationListener(
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    76
                totoName, myListener, null, null);
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    77
        Thread.sleep(10);
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    78
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    79
        print("send notif, listener will block the fetcher");
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    80
        toto.sendNotif();
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    81
        Thread.sleep(100);
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    82
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    83
        StateMachine.setState(NO_OP);
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    84
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    85
        print("Sleep 3 times of server idle timeout: "+serverTimeout+
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    86
                ", the sever should close the idle connection.");
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    87
        Thread.sleep(serverTimeout*3);
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    88
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    89
        print("start the user thread to call mbean method, it will get IOexception" +
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    90
                " and start the reconnection, the socket factory will block the" +
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    91
                " socket creation.");
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    92
        UserThread ut = new UserThread();
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    93
        ut.start();
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    94
        Thread.sleep(10);
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    95
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    96
        print("Free the listener, the fetcher will get IO and makes " +
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    97
                "a deadlock if the bug is not fixed.");
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    98
        StateMachine.setState(FREE_LISTENER);
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
    99
        Thread.sleep(100);
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   100
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   101
        print("Allow to create new socket for the reconnection");
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   102
        StateMachine.setState(CREATE_SOCKET);
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   103
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   104
        print("Check whether the user thread gets free to call the mbean.");
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   105
        if (!ut.waitDone(5000)) {
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   106
            throw new RuntimeException("Possible deadlock!");
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   107
        }
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   108
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   109
        print("Remove the listener.");
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   110
        client.getMBeanServerConnection().removeNotificationListener(
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   111
                totoName, myListener, null, null);
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   112
        Thread.sleep(serverTimeout*3);
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   113
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   114
        print("\nWell passed, bye!");
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   115
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   116
        client.close();
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   117
        Thread.sleep(10);
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   118
        server.stop();
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   119
    }
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   120
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   121
    private static ObjectName totoName = null;
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   122
    private static JMXConnector client;
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   123
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   124
    public static class UserThread extends Thread {
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   125
        public UserThread() {
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   126
            setDaemon(true);
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   127
        }
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   128
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   129
        public void run() {
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   130
            try {
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   131
                client.getMBeanServerConnection().invoke(
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   132
                        totoName, "allowReturn", null, null);
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   133
            } catch (Exception e) {
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   134
                throw new Error(e);
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   135
            }
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   136
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   137
            synchronized(UserThread.class) {
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   138
                done = true;
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   139
                UserThread.class.notify();
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   140
            }
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   141
        }
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   142
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   143
        public boolean waitDone(long timeout) {
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   144
            synchronized(UserThread.class) {
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   145
                if(!done) {
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   146
                    try {
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   147
                        UserThread.class.wait(timeout);
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   148
                    } catch (Exception e) {
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   149
                        throw new Error(e);
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   150
                    }
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   151
                }
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   152
            }
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   153
            return done;
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   154
        }
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   155
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   156
        private boolean done = false;
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   157
    }
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   158
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   159
    public static interface TotoMBean {
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   160
        public void allowReturn();
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   161
    }
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   162
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   163
    public static class Toto extends NotificationBroadcasterSupport
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   164
            implements TotoMBean {
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   165
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   166
        public void allowReturn() {
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   167
            enter("allowReturn");
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   168
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   169
            leave("allowReturn");
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   170
        }
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   171
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   172
        public void sendNotif() {
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   173
            enter("sendNotif");
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   174
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   175
            sendNotification(new Notification("Toto", totoName, 0));
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   176
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   177
            leave("sendNotif");
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   178
        }
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   179
    }
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   180
    private static Toto toto = new Toto();
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   181
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   182
    public static NotificationListener myListener = new NotificationListener() {
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   183
        public void handleNotification(Notification notification, Object handback) {
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   184
            enter("handleNotification");
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   185
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   186
            StateMachine.waitState(FREE_LISTENER);
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   187
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   188
            leave("handleNotification");
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   189
        }
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   190
    };
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   191
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   192
    public static class RMIClientFactory
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   193
            implements RMIClientSocketFactory, Serializable {
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   194
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   195
        public Socket createSocket(String host, int port) throws IOException {
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   196
            enter("createSocket");
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   197
            //print("Calling createSocket(" + host + " " + port + ")");
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   198
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   199
            StateMachine.waitState(CREATE_SOCKET);
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   200
            Socket s = new Socket(host, port);
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   201
            leave("createSocket");
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   202
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   203
            return s;
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   204
        }
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   205
    }
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   206
    private static RMIClientFactory clientFactory = new RMIClientFactory();
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   207
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   208
    private static int CREATE_SOCKET = 1;
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   209
    private static int FREE_LISTENER = 3;
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   210
    private static int NO_OP = 0;
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   211
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   212
    public static class StateMachine {
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   213
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   214
        private static int state = NO_OP;
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   215
        private static int[] lock = new int[0];
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   216
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   217
        public static void waitState(int s) {
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   218
            synchronized (lock) {
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   219
                while (state != s) {
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   220
                    try {
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   221
                        lock.wait();
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   222
                    } catch (InterruptedException ire) {
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   223
                        // should not
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   224
                        throw new Error(ire);
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   225
                    }
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   226
                }
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   227
            }
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   228
        }
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   229
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   230
        public static int getState() {
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   231
            synchronized (lock) {
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   232
                return state;
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   233
            }
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   234
        }
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   235
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   236
        public static void setState(int s) {
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   237
            synchronized (lock) {
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   238
                state = s;
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   239
                lock.notifyAll();
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   240
            }
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   241
        }
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   242
    }
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   243
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   244
    private static void print(String m) {
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   245
        System.out.println(m);
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   246
    }
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   247
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   248
    private static void enter(String m) {
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   249
        System.out.println("\n---Enter the method " + m);
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   250
    }
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   251
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   252
    private static void leave(String m) {
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   253
        System.out.println("===Leave the method: " + m);
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   254
    }
f5d91fb6df32 6697180: JMX query results in java.io.IOException: Illegal state - also a deadlock can also be seen
sjiang
parents:
diff changeset
   255
}