private static void maybeStartHtmlJmxAdaptor() {
    MBeanServer beanServer = ManagementFactory.getPlatformMBeanServer();

    String htmlAdaptorAvailable = System.getProperty("hornetq.htmladaptor.available");

    if ("TRUE".equalsIgnoreCase(htmlAdaptorAvailable)) {

      try {

        String strPort = System.getProperty("hornetq.htmladaptor.port");

        int htmlAdaptorPort = Integer.parseInt(strPort);

        String userName = System.getProperty("hornetq.htmladaptor.userName");
        String password = System.getProperty("hornetq.htmladaptor.password");

        final HtmlAdaptorServer adapter = new HtmlAdaptorServer();

        ObjectName adapterName =
            new ObjectName("SimpleAgent:name=htmladapter,port=" + htmlAdaptorPort);

        adapter.setPort(htmlAdaptorPort);

        if (userName != null && password != null) {
          adapter.addUserAuthenticationInfo(new AuthInfo(userName, password));
        }

        beanServer.registerMBean(adapter, adapterName);
        adapter.start();

        Runtime.getRuntime()
            .addShutdownHook(
                new Thread() {
                  public void run() {
                    adapter.stop();
                  }
                });
      } catch (Exception e) {
        log.error("Error starting up the HtmlAdaptorServer: " + e.getMessage(), e);
        log.error(
            "If you don't want this, remove the hornetq.htmladaptor.available property "
                + "or set it to false");
        System.exit(-1);
      }
    }
  }
  public void stop() {
    try {
      ObjectName objectName = new ObjectName(resourceAdapterObjectName);
      Set<ObjectInstance> mbeanSet = mBeanServer.queryMBeans(objectName, null);

      for (ObjectInstance mbean : mbeanSet) {
        String stateString =
            (String) mBeanServer.getAttribute(mbean.getObjectName(), "StateString");

        if ("Started".equalsIgnoreCase(stateString) || "Starting".equalsIgnoreCase(stateString)) {
          mBeanServer.invoke(mbean.getObjectName(), "stop", new Object[0], new String[0]);
        }
      }
    } catch (Exception e) {
      log.error("Unable to stop HornetQ resource adapter.", e);
    }
  }