jdk/test/javax/management/remote/mandatory/connection/CloseServerTest.java
changeset 4156 acaa49a2768a
parent 1247 b4c26443dee5
child 5506 202f599c92aa
equal deleted inserted replaced
4155:460e37d40f12 4156:acaa49a2768a
     1 /*
     1 /*
     2  * Copyright 2003-2008 Sun Microsystems, Inc.  All Rights Reserved.
     2  * Copyright 2003 Sun Microsystems, Inc.  All Rights Reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    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;
       
    35 import java.net.MalformedURLException;
    34 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;
       
    41 import javax.management.*;
    37 import javax.management.*;
    42 import javax.management.remote.*;
    38 import javax.management.remote.*;
    43 import javax.management.remote.rmi.RMIConnectorServer;
       
    44 
    39 
    45 public class CloseServerTest {
    40 public class CloseServerTest {
    46     private static final String[] protocols = {"rmi", "iiop", "jmxmp"};
    41     private static final String[] protocols = {"rmi", "iiop", "jmxmp"};
    47     private static final MBeanServer mbs = MBeanServerFactory.createMBeanServer();
    42     private static final MBeanServer mbs = MBeanServerFactory.createMBeanServer();
    48 
    43 
   134 
   129 
   135             client.close();
   130             client.close();
   136 
   131 
   137             server.stop();
   132             server.stop();
   138 
   133 
   139             List<Map<String, String>> envs = Arrays.asList(
   134             // with a client listener, but close the server first
   140                     Collections.singletonMap(
   135             System.out.println(">>> Open, start a server, create a client, add a listener, close the server then the client.");
   141                         RMIConnectorServer.DELEGATE_TO_EVENT_SERVICE, "false"),
   136             server = JMXConnectorServerFactory.newJMXConnectorServer(u, null, mbs);
   142                     Collections.singletonMap(
   137             server.start();
   143                         RMIConnectorServer.DELEGATE_TO_EVENT_SERVICE, "true"));
       
   144 
   138 
   145             for (Map<String, String> env : envs) {
   139             addr = server.getAddress();
   146                     System.out.println(
   140             client = JMXConnectorFactory.newJMXConnector(addr, null);
   147                             ">>>>>>>> " + RMIConnectorServer.DELEGATE_TO_EVENT_SERVICE +
   141             client.connect(null);
   148                             " = " + env.get(RMIConnectorServer.DELEGATE_TO_EVENT_SERVICE));
       
   149 
   142 
   150                 // with a client listener, but close the server first
   143             mserver = client.getMBeanServerConnection();
   151                 System.out.println(">>> Open, start a server, create a client, " +
   144             mserver.addNotificationListener(delegateName, dummyListener, null, null);
   152                         "add a listener, close the server then the client.");
       
   153                 server = JMXConnectorServerFactory.newJMXConnectorServer(u, env, mbs);
       
   154                 server.start();
       
   155 
   145 
   156                 addr = server.getAddress();
   146             server.stop();
   157                 client = JMXConnectorFactory.newJMXConnector(addr, null);
       
   158                 client.connect(null);
       
   159 
   147 
   160                 mserver = client.getMBeanServerConnection();
   148             try {
   161                 mserver.addNotificationListener(delegateName, dummyListener, null, null);
   149                 client.close();
       
   150             } catch (Exception e) {
       
   151                 // ok, it is because the server has been closed.
       
   152             }
   162 
   153 
   163                 server.stop();
   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();
   164 
   158 
   165                 try {
   159             addr = server.getAddress();
   166                     client.close();
   160             client = JMXConnectorFactory.newJMXConnector(addr, null);
   167                 } catch (Exception e) {
   161             client.connect(null);
   168                     // ok, it is because the server has been closed.
       
   169                 }
       
   170 
   162 
   171                 // with a client listener, but close the client first
   163             mserver = client.getMBeanServerConnection();
   172                 System.out.println(">>> Open, start a server, create a client, " +
   164             mserver.addNotificationListener(delegateName, dummyListener, null, null);
   173                         "add a listener, close the client then the server.");
       
   174                 server = JMXConnectorServerFactory.newJMXConnectorServer(u, env, mbs);
       
   175                 server.start();
       
   176 
   165 
   177                 addr = server.getAddress();
   166             client.close();
   178                 client = JMXConnectorFactory.newJMXConnector(addr, null);
   167             server.stop();
   179                 client.connect(null);
       
   180 
       
   181                 mserver = client.getMBeanServerConnection();
       
   182                 mserver.addNotificationListener(delegateName, dummyListener, null, null);
       
   183 
       
   184                 client.close();
       
   185                 server.stop();
       
   186             }
       
   187         } catch (MalformedURLException e) {
   168         } catch (MalformedURLException e) {
   188             System.out.println(">>> Skipping unsupported URL " + u);
   169             System.out.println(">>> Skipping unsupported URL " + u);
   189             return true;
   170             return true;
   190         }
   171         }
   191 
   172