Ejemplo n.º 1
0
  private static void test(String proto) throws Exception {
    System.out.println(">>> Test for protocol " + proto);

    JMXServiceURL u = null;
    JMXConnectorServer server = null;

    HashMap env = new HashMap(2);
    // server will close a client connection after 1 second
    env.put("jmx.remote.x.server.connection.timeout", "1000");

    // disable the client ping
    env.put("jmx.remote.x.client.connection.check.period", "0");

    try {
      u = new JMXServiceURL(proto, null, 0);
      server = JMXConnectorServerFactory.newJMXConnectorServer(u, env, mbs);
    } catch (MalformedURLException e) {
      System.out.println(">>> Skipping unsupported URL " + proto);
    }

    server.start();

    JMXServiceURL addr = server.getAddress();

    long st = 2000;
    MyListener myListener;

    // a cycle to make sure that we test the blocking problem.
    do {
      JMXConnector client = JMXConnectorFactory.connect(addr, env);
      MBeanServerConnection conn = client.getMBeanServerConnection();
      myListener = new MyListener(conn);
      client.addConnectionNotificationListener(myListener, null, null);

      // wait the server to close the client connection
      Thread.sleep(st);

      // makes the listener to do a remote request via the connection
      // which should be closed by the server.
      conn.getDefaultDomain();

      // allow the listner to have time to work
      Thread.sleep(100);

      // get a closed notif, should no block.
      client.close();
      Thread.sleep(100);

      st += 2000;

    } while (!myListener.isDone());

    server.stop();
  }
Ejemplo n.º 2
0
    private void tryConnect() throws IOException {
      if (mode == MODE_SELF) {
        jmxc = null;
        conn = ManagementFactory.getPlatformMBeanServer();
      } else {
        if (mode == MODE_LOCAL) {
          if (!lvm.isManageable()) {
            lvm.startManagementAgent();
            if (!lvm.isManageable()) {
              // FIXME: what to throw
              throw new IOException(lvm + " not manageable"); // NOI18N
            }
          }
          if (jmxUrl == null) {
            jmxUrl = new JMXServiceURL(lvm.connectorAddress());
          }
        }

        Map<String, Object> env = new HashMap();
        if (envProvider != null) env.putAll(envProvider.getEnvironment(app, app.getStorage()));
        if (userName != null || password != null)
          env.put(JMXConnector.CREDENTIALS, new String[] {userName, password});

        if (!insecure && mode != MODE_LOCAL && env.get(JMXConnector.CREDENTIALS) != null) {
          env.put("jmx.remote.x.check.stub", "true"); // NOI18N
          checkSSLStub = true;
        } else {
          checkSSLStub = false;
        }

        jmxc = JMXConnectorFactory.newJMXConnector(jmxUrl, env);
        jmxc.addConnectionNotificationListener(this, null, null);
        try {
          jmxc.connect(env);
        } catch (java.io.IOException e) {
          // Likely a SSL-protected RMI registry
          if ("rmi".equals(jmxUrl.getProtocol())) { // NOI18N
            env.put("com.sun.jndi.rmi.factory.socket", sslRMIClientSocketFactory); // NOI18N
            jmxc.connect(env);
          } else {
            throw e;
          }
        }

        MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
        conn = Checker.newChecker(this, mbsc);
      }
      isDead = false;
    }