• 7.8.2 增强模块(续)

    长期以来,node.js被诟病最多问题的就是缺乏持久化能力与管理能力。Java能够轻松解决这些问题,所以扩充两个模块sql和edb,分别提供关系数据库,键值对数据库访问能力,扩充一个简单JMX查询模块monitor。

    • Monitor

      • mointor.Host类

        • ‘close’ 事件

        • host.query(objectName, callback)

        • host.destroy()

        • host.ref()

        • host.unref()

      • monitor.connect (host, serverPort, rmiPort[, username, password])

      例如,启动switcher服务器(配置了本机jmx服务,见service-switcher.xml)

      service-switcher.xml


      var host = require('monitor').connect('localhost', 10003, 10002);
      setInterval(function(){
          host.query('java.lang:type=Threading', console.log);
      }, 10000);
      

      运行该程序,即可10秒间隔,查询线程状态。


      monitor.Host类

      描述了一个JMX连接


      ‘close’ 事件

      执行destroy,关闭Host对象,但是关闭时可能还有操作正在执行,所有的操作执行结束以后触发该事件,表示Host彻底关闭。


      host.query(objectName, callback)

      objectName<String> 需要查询的jmx对象名

      callback <Function>

      查询完成使用 callback(err, obj) 回调。


      host.destroy()

      关闭Host对象连接,destroy之后执行的操作直接用实例已经关闭的错误回调。


      host.ref()

      Opposite of unref, calling ref on a previously unrefd host will not let the program exit if it's the only host left (the default behavior). If the host is refd calling ref again will have no effect.

      Returns server.


      host.unref()

      Calling unref on a host will allow the program to exit if this is the only active host in the event system. If the host is already unrefd calling unref again will have no effect.

      Returns server.


      monitor.connect (host, serverPort, rmiPort[, username, password])

      host<String>

      serverPort<Number> Integer

      rmiPort<Number> Integer

      username<String>

      password<String>

      提供连接参数,创建Host对象。


上一页 下一页