jdk/test/javax/management/remote/mandatory/connection/CloseServerTest.java
changeset 1004 5ba8217eb504
parent 2 90ce3da70b43
child 1247 b4c26443dee5
equal deleted inserted replaced
1003:b2f6b7e00c29 1004:5ba8217eb504
    29  * @run clean CloseServerTest
    29  * @run clean CloseServerTest
    30  * @run build CloseServerTest
    30  * @run build CloseServerTest
    31  * @run main CloseServerTest
    31  * @run main CloseServerTest
    32  */
    32  */
    33 
    33 
       
    34 import com.sun.jmx.remote.util.EnvHelp;
    34 import java.net.MalformedURLException;
    35 import java.net.MalformedURLException;
    35 import java.io.IOException;
       
    36 
    36 
       
    37 import java.util.Arrays;
       
    38 import java.util.Collections;
       
    39 import java.util.List;
       
    40 import java.util.Map;
    37 import javax.management.*;
    41 import javax.management.*;
    38 import javax.management.remote.*;
    42 import javax.management.remote.*;
       
    43 import javax.management.remote.rmi.RMIConnectorServer;
    39 
    44 
    40 public class CloseServerTest {
    45 public class CloseServerTest {
    41     private static final String[] protocols = {"rmi", "iiop", "jmxmp"};
    46     private static final String[] protocols = {"rmi", "iiop", "jmxmp"};
    42     private static final MBeanServer mbs = MBeanServerFactory.createMBeanServer();
    47     private static final MBeanServer mbs = MBeanServerFactory.createMBeanServer();
    43 
    48 
   129 
   134 
   130             client.close();
   135             client.close();
   131 
   136 
   132             server.stop();
   137             server.stop();
   133 
   138 
   134             // with a client listener, but close the server first
   139             List<Map<String, String>> envs = Arrays.asList(
   135             System.out.println(">>> Open, start a server, create a client, add a listener, close the server then the client.");
   140                     Collections.singletonMap(
   136             server = JMXConnectorServerFactory.newJMXConnectorServer(u, null, mbs);
   141                         RMIConnectorServer.DELEGATE_TO_EVENT_SERVICE, "false"),
   137             server.start();
   142                     Collections.singletonMap(
       
   143                         RMIConnectorServer.DELEGATE_TO_EVENT_SERVICE, "true"));
   138 
   144 
   139             addr = server.getAddress();
   145             for (Map<String, String> env : envs) {
   140             client = JMXConnectorFactory.newJMXConnector(addr, null);
   146                     System.out.println(
   141             client.connect(null);
   147                             ">>>>>>>> " + RMIConnectorServer.DELEGATE_TO_EVENT_SERVICE +
       
   148                             " = " + env.get(RMIConnectorServer.DELEGATE_TO_EVENT_SERVICE));
   142 
   149 
   143             mserver = client.getMBeanServerConnection();
   150                 // with a client listener, but close the server first
   144             mserver.addNotificationListener(delegateName, dummyListener, null, null);
   151                 System.out.println(">>> Open, start a server, create a client, " +
       
   152                         "add a listener, close the server then the client.");
       
   153                 server = JMXConnectorServerFactory.newJMXConnectorServer(u, env, mbs);
       
   154                 server.start();
   145 
   155 
   146             server.stop();
   156                 addr = server.getAddress();
       
   157                 client = JMXConnectorFactory.newJMXConnector(addr, null);
       
   158                 client.connect(null);
   147 
   159 
   148             try {
   160                 mserver = client.getMBeanServerConnection();
       
   161                 mserver.addNotificationListener(delegateName, dummyListener, null, null);
       
   162 
       
   163                 server.stop();
       
   164 
       
   165                 try {
       
   166                     client.close();
       
   167                 } catch (Exception e) {
       
   168                     // ok, it is because the server has been closed.
       
   169                 }
       
   170 
       
   171                 // with a client listener, but close the client first
       
   172                 System.out.println(">>> Open, start a server, create a client, " +
       
   173                         "add a listener, close the client then the server.");
       
   174                 server = JMXConnectorServerFactory.newJMXConnectorServer(u, env, mbs);
       
   175                 server.start();
       
   176 
       
   177                 addr = server.getAddress();
       
   178                 client = JMXConnectorFactory.newJMXConnector(addr, null);
       
   179                 client.connect(null);
       
   180 
       
   181                 mserver = client.getMBeanServerConnection();
       
   182                 mserver.addNotificationListener(delegateName, dummyListener, null, null);
       
   183 
   149                 client.close();
   184                 client.close();
   150             } catch (Exception e) {
   185                 server.stop();
   151                 // ok, it is because the server has been closed.
       
   152             }
   186             }
   153 
       
   154             // with a client listener, but close the client first
       
   155             System.out.println(">>> Open, start a server, create a client, add a listener, close the client then the server.");
       
   156             server = JMXConnectorServerFactory.newJMXConnectorServer(u, null, mbs);
       
   157             server.start();
       
   158 
       
   159             addr = server.getAddress();
       
   160             client = JMXConnectorFactory.newJMXConnector(addr, null);
       
   161             client.connect(null);
       
   162 
       
   163             mserver = client.getMBeanServerConnection();
       
   164             mserver.addNotificationListener(delegateName, dummyListener, null, null);
       
   165 
       
   166             client.close();
       
   167             server.stop();
       
   168         } catch (MalformedURLException e) {
   187         } catch (MalformedURLException e) {
   169             System.out.println(">>> Skipping unsupported URL " + u);
   188             System.out.println(">>> Skipping unsupported URL " + u);
   170             return true;
   189             return true;
   171         }
   190         }
   172 
   191