⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jmxwrapper.java

📁 java开源的企业总线.xmlBlaster
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
         else            break;      }      // new since xmlBlaster 1.0.7+      while (true) {         int index = value.indexOf("/");         if (index >= 0)            value = value.substring(0,index) + "_" + value.substring(index+1);         else            break;      }      return value;   }   /**    * Initialize the MBean server and adaptors.    */   public synchronized void init() throws XmlBlasterException {      if (this.mbeanServer == null) return;      boolean supportsJconsole = true;      try {         if (new Float(System.getProperty("java.runtime.version").substring(0,3)).floatValue() < 1.5)            supportsJconsole = false;      }      catch (Throwable e) {         log.fine(e.toString());      }      // In a cluster environment set for example jndiPath=="/"+${cluster.node.id}      String jndiPath = glob.getProperty().get("xmlBlaster/jmx/rmiregistry/jndiPath", "/jmxrmi"); // "/jmxconnector";      String ssl = System.getProperty("com.sun.management.jmxremote.ssl");      //String aut = System.getProperty("com.sun.management.jmxremote.authenticate");      String pwd = System.getProperty("com.sun.management.jmxremote.password.file");      //boolean isAuthenticated = !((ssl==null||"false".equals(ssl)) && (aut==null||"false".equals(aut)));      boolean isAuthenticated = !(ssl==null||"false".equals(ssl)) || pwd!=null;      if (System.getProperty("com.sun.management.jmxremote.port") != null) {         // For localhost or remote access with specific port         // You have to configure authentication!         // JDK >= 1.5 automatically creates an RMI connector and start it for us         int port = new Integer(System.getProperty("com.sun.management.jmxremote.port")).intValue();         if (supportsJconsole) {            String loc = "service:jmx:rmi:///jndi/rmi://"+glob.getLocalIP()+":"+port+jndiPath;            log.info("'java -Dcom.sun.management.jmxremote.port=" + port +                         "' is specified, JMX is switched on, try to start 'jconsole " + loc + "'");            if (!isAuthenticated)               log.warning("Caution: Your JMX access is not protected with SSL or password, see http://www.xmlBlaster.org/xmlBlaster/doc/requirements/admin.jmx.html#jconsole");            useJmx++;         }         else {            log.info("'java -Dcom.sun.management.jmxremote.port="+port+"' is specified "+                         " but is not supported in this runtime " + System.getProperty("java.runtime.version"));         }      }      else if (System.getProperty("com.sun.management.jmxremote") != null) {         // For localhost or remote access with default port 1099         // You have to configure authentication!         // JDK >= 1.5 automatically creates an RMI connector and start it for us         String loc = "service:jmx:rmi:///jndi/rmi://"+glob.getLocalIP()+":"+DEFAULT_REGISTRY_PORT+jndiPath;         if (supportsJconsole) {            log.info("'java -Dcom.sun.management.jmxremote' is specified, JMX is switched on, try to start 'jconsole' or 'jconsole "+loc+"'");            if (!isAuthenticated)               log.warning("Caution: Your JMX access is not protected with SSL or password, see http://www.xmlBlaster.org/xmlBlaster/doc/requirements/admin.jmx.html#jconsole");            useJmx++;         }         else {            log.info("'java -Dcom.sun.management.jmxremote' is specified "+                         " but is not supported in this runtime " + System.getProperty("java.runtime.version"));         }      }      else if (glob.getProperty().get("xmlBlaster/jmx/rmi", false)) {         // JDK >= 1.5: Create manually an RMI connector and start it         // If there is no rmiregistry around we start one         // url ::= service:jmx:protocol:sap         // sap ::= //[host[:port]][url-path]         //         // JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://localhost:3000/jndi/rmi://localhost:9999/server");         //         //   which tells the RMIConnectorServer to bind to the RMIRegistry running         //   on port 9999 and to export the RMIServer and RMIConnection remote objects on port 3000.         if (!supportsJconsole) {            log.warning("JMX setting '-xmlBlaster/jmx/rmi true' ignored in this JVM runtime, you need JDK 1.5 or higher.");         }         else {            try {               // Force to export the RMIServer and RMIConnection remote objects on host and port               int rmiServerPort = glob.getProperty().get("xmlBlaster/jmx/rmiserver/port", 6011);               String rmiServerHost = glob.getProperty().get("xmlBlaster/jmx/rmiserver/hostname", (String)null);               // Force the RMI registry               int rmiRegistryPort = glob.getProperty().get("xmlBlaster/jmx/rmiregistry/port", DEFAULT_REGISTRY_PORT); // 1099               String rmiRegistryHost = glob.getProperty().get("xmlBlaster/jmx/rmiregistry/hostname", glob.getLocalIP());               startRmiRegistry(rmiRegistryHost, rmiRegistryPort);               String bindName = "rmi://"+rmiRegistryHost+":"+rmiRegistryPort+jndiPath;               try {  // If an external rmiregistry is running cleanup old entries:                  Naming.unbind(bindName);               } catch (Exception e) {                  log.fine("Can't unbind '" + bindName + "': " + e.toString());               }               //String loc = "service:jmx:rmi://"+rmiRegistryHost+":"+rmiRegistryPort+"/jndi/" + bindName;               String loc = "service:jmx:rmi:///jndi/" + bindName;               if (rmiServerHost != null) {                  loc = "service:jmx:rmi://" + rmiServerHost + ":" + rmiServerPort + "/jndi/" + bindName;               }               //since JDK 1.5 or with including jmxremote.jar for JDK 1.3/1.4               final String storedUser = glob.getProperty().get("xmlBlaster/jmx/rmi/user", (String)null);               final String storedPassword = glob.getProperty().get("xmlBlaster/jmx/rmi/password", (String)null);               Map props = new TreeMap();               if (storedUser != null) {                  javax.management.remote.JMXAuthenticator auth = new javax.management.remote.JMXAuthenticator() {                     public javax.security.auth.Subject authenticate(Object credentials) {                        if (log.isLoggable(Level.FINER)) log.finer("Calling authenticate(" + ((credentials==null)?"null":credentials.toString()) + ")");                        if (!(credentials instanceof String[])) throw new SecurityException("xmlBlaster responds: Bad credentials, please pass user name and password");                        String[] creds = (String[])credentials;                        if (creds.length != 2) throw new SecurityException("xmlBlaster responds: Bad credentials, please pass user name and password");                        String user = creds[0];                        String password = creds[1];                        if (log.isLoggable(Level.FINE)) log.fine("Calling authenticate(user=" + user + ", password=" + password + ")");                        if (password == null) throw new SecurityException("xmlBlaster responds: Missing password");                        if (!storedUser.equals(user)) throw new SecurityException("xmlBlaster responds: Unknown user " + user + ",  please try with user '" + storedUser + "'");                        if (!storedPassword.equals(password)) throw new SecurityException("xmlBlaster responds: Bad password, please try again");                        Set principals = new HashSet();                        principals.add(new javax.management.remote.JMXPrincipal(user));                        return new Subject(true, principals, Collections.EMPTY_SET, Collections.EMPTY_SET);                     }                  };                  props.put("jmx.remote.authenticator", auth); // JMXConnectorServer.AUTHENTICATOR               }               else {                  log.warning("You should switch on authentication with '-xmlBlaster/jmx/rmi/user' and '-xmlBlaster/jmx/rmi/password'");               }               //since JDK 1.5 or with including jmxremote.jar for JDK 1.3/1.4               //javax.management.remote.JMXServiceURL url = new javax.management.remote.JMXServiceURL(loc);               //javax.management.remote.JMXConnectorServer cs = javax.management.remote.JMXConnectorServerFactory.newJMXConnectorServer(url, props, getMBeanServer());               //cs.start();               // JDK 1.3 and 1.4: Not available so we need to use reflection               Class clazz = java.lang.Class.forName("javax.management.remote.JMXServiceURL");               Class[] paramCls =  new Class[] { java.lang.String.class }; // url location               Object[] params = new Object[] { loc };               java.lang.reflect.Constructor ctor = clazz.getConstructor(paramCls);               Object jMXServiceURL = ctor.newInstance(params);               clazz = java.lang.Class.forName("javax.management.remote.JMXConnectorServerFactory");               paramCls = new Class[] {                  java.lang.Class.forName("javax.management.remote.JMXServiceURL"),                  java.util.Map.class,                   // properties                  javax.management.MBeanServer.class               };               params = new Object[] {                  jMXServiceURL,                  props,                  getMBeanServer()               };               java.lang.reflect.Method method = clazz.getMethod("newJMXConnectorServer", paramCls);               Object jMXConnectorServer = method.invoke(clazz, params); // Returns "JMXConnectorServer"               clazz = java.lang.Class.forName("javax.management.remote.JMXConnectorServer");               paramCls = new Class[0];               params = new Object[0];               method = clazz.getMethod("start", paramCls);               method.invoke(jMXConnectorServer, params); // finally ... starts JMX               log.info("JMX is switched on because of 'xmlBlaster/jmx/rmi true' is set, try to start 'jconsole " + loc + "' and user=" + storedUser);               useJmx++;            }            catch(Throwable ex) {               ex.printStackTrace();               throw new XmlBlasterException(this.glob, ErrorCode.RESOURCE_UNAVAILABLE, ME, " could not create JMXConnectorServer", ex);            }         }      }      else {         if (supportsJconsole) {            log.info("JMX over RMI is switched off, for details see http://www.xmlBlaster.org/xmlBlaster/doc/requirements/admin.jmx.html#jconsole");         }      }      if (glob.getProperty().get("xmlBlaster/jmx/HtmlAdaptor", false)) {         try {            String hostname = glob.getProperty().get("xmlBlaster/jmx/HtmlAdaptor/hostname", glob.getLocalIP());            int port = glob.getProperty().get("xmlBlaster/jmx/HtmlAdaptor/port", 8082);            String loginName = glob.getProperty().get("xmlBlaster/jmx/HtmlAdaptor/loginName", (String)null);            String password = glob.getProperty().get("xmlBlaster/jmx/HtmlAdaptor/password", "secret");            if (loginName != null) {               AuthInfo authInfos[] = { new AuthInfo(loginName, password) };               this.html = new HtmlAdaptorServer(port, authInfos);            }            else {               this.html = new HtmlAdaptorServer(port);            }            ObjectName html_name = new ObjectName("Adaptor:name=html,port="+port);            ObjectInstance objectInstance = this.mbeanServer.registerMBean(this.html, html_name);            JmxMBeanHandle handle = new JmxMBeanHandle(objectInstance, null, this.html);            this.mbeanMap.put(html_name.toString(), handle);            if (loginName == null) {               log.info("Registered JMX HTML adaptor on http://"+hostname+":"+port +                        ". No authentication is configured with 'xmlBlaster/jmx/HtmlAdaptor/loginName=...'");            }            else {               log.info("Registered JMX HTML adaptor on http://"+hostname+":"+port + " with login name '" + loginName + "'");            }            useJmx++;         }         catch(Exception ex) {            log.severe(" Could not create HtmlAdaptorServer: " + ex.toString());         }         this.html.start();      }      if (glob.getProperty().get("xmlBlaster/jmx/XmlBlasterAdaptor", false)) {         try {            startXmlBlasterConnector(this.mbeanServer);            useJmx++;         }         catch (XmlBlasterException ex) {            log.severe("Error when starting xmlBlasterConnector " + ex.toString());            ex.printStackTrace();         }      }      if (this.useJmx > 0) {         boolean observeLowMemory = glob.getProperty().get("xmlBlaster/jmx/observeLowMemory", true);         if (observeLowMemory) {            try {               // JDK 1.3 and 1.4: Not available so we need to use reflection               Class clazz = java.lang.Class.forName("org.xmlBlaster.util.admin.extern.LowMemoryDetector");               if (clazz != null) {                  Class[] paramCls =  new Class[] { float.class }; // url location                  java.lang.reflect.Constructor ctor = clazz.getConstructor(paramCls);                  float thresholdFactor = glob.getProperty().get("xmlBlaster/jmx/memoryThresholdFactor", (float)0.9);                  Object[] params = new Object[] { new Float(thresholdFactor) };                  ctor.newInstance(params);               }            }            catch (Exception e) {               log.warning("org.xmlBlaster.util.admin.extern.LowMemoryDetector is not available for low memory detection");            }         }      }   }   /**    * Start xmlBlaster security manager and RMI registry.    * @param registryPort xmlBlaster/jmx/rmiregistry/port=1099    * @param registryHost xmlBlaster/jmx/rmiregistry/hostname=loclhost    */   private synchronized void startRmiRegistry(String registryHost, int registryPort) throws XmlBlasterException {      if (this.createSecurityManager)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -