diff --git a/index.js b/index.js index 80f9d35..61f72b1 100644 --- a/index.js +++ b/index.js @@ -13,7 +13,7 @@ function createClient(options) { port = options.port; urlPath = options.urlPath; } - return new Client(serviceOrHost, port, protocol, urlPath, options.username, options.password); + return new Client(serviceOrHost, port, protocol, urlPath, options.username, options.password, options.protocolProvider, options.timeout); } module.exports = { diff --git a/lib/adapters/javaReflection.js b/lib/adapters/javaReflection.js index 572b7a4..fe4b662 100644 --- a/lib/adapters/javaReflection.js +++ b/lib/adapters/javaReflection.js @@ -24,6 +24,8 @@ JavaReflection.prototype.invokeMethod = function(obj, methodName, paramsClass, p return paramsClass; } + if(!obj) + return; var javaParamsClass = newClassArray(paramsClass); obj.getClass(function(err, javaClass) { if (checkError(err, self)) return; diff --git a/lib/adapters/mbeanServerConnection.js b/lib/adapters/mbeanServerConnection.js index 718c181..8b42a65 100644 --- a/lib/adapters/mbeanServerConnection.js +++ b/lib/adapters/mbeanServerConnection.js @@ -44,10 +44,58 @@ MBeanServerConnection.prototype.connect = function(jmxServiceUrl) { var JMXConnector = java.import("javax.management.remote.JMXConnector"); map.put(JMXConnector.CREDENTIALS, credentials, function(err) { if (checkError(err, self)) return; - callback(map); + if(self.protocolProvider) { + map.put(self.JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES, self.protocolProvider, function (err) { + if (checkError(err, self)) return; + if(self.timeout>=0) { + var waitTime=java.newLong(self.timeout); + map.put("jmx.remote.x.request.waiting.timeout",waitTime,function(err){ + if (checkError(err, self)) return; + callback(map); + }); + return; + } + callback(map); + }); + } else { + if(self.timeout>=0) + { + var waitTime=java.newLong(self.timeout); + map.put("jmx.remote.x.request.waiting.timeout",waitTime,function(err){ + if (checkError(err, self)) return; + callback(map); + }); + return; + } + callback(map); + } }); } else { - callback(map); + if(self.protocolProvider) { + map.put(self.JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES, self.protocolProvider, function (err) { + if (checkError(err, self)) return; + if(self.timeout>=0) { + var waitTime=java.newLong(self.timeout); + map.put("jmx.remote.x.request.waiting.timeout",waitTime,function(err){ + if (checkError(err, self)) return; + callback(map); + }); + return; + } + callback(map); + }); + } else { + if(self.timeout>=0) + { + var waitTime=java.newLong(self.timeout); + map.put("jmx.remote.x.request.waiting.timeout",waitTime,function(err){ + if (checkError(err, self)) return; + callback(map); + }); + return; + } + callback(map); + } } }); } @@ -181,5 +229,10 @@ MBeanServerConnection.prototype.setCredentials = function(username, password) { this.password = password; }; +MBeanServerConnection.prototype.setOptions = function(protocolProvider, timeout) { + this.protocolProvider=protocolProvider; + this.timeout=timeout; +}; + module.exports = MBeanServerConnection; diff --git a/lib/client.js b/lib/client.js index e7a6b00..de89f30 100644 --- a/lib/client.js +++ b/lib/client.js @@ -2,7 +2,7 @@ var JavaJmx = require("./javaJmx"), util = require("util"), EventEmitter = require("events").EventEmitter; -function Client(serviceOrHost, port, protocol, urlPath, username, password) { +function Client(serviceOrHost, port, protocol, urlPath, username, password, protocolProvider, timeout) { var self = this; function subscribeTo(obj) { @@ -24,11 +24,14 @@ function Client(serviceOrHost, port, protocol, urlPath, username, password) { self.jmxServiceUrl = this.javaJmx.JmxServiceUrl(serviceOrHost, port, protocol, urlPath); self.username = username; self.password = password; + self.protocolProvider = protocolProvider; + self.timeout= timeout; } util.inherits(Client, EventEmitter); Client.prototype.connect = function() { this.javaJmx.setCredentials(this.username, this.password); + this.javaJmx.setOptions(this.protocolProvider,this.timeout); this.javaJmx.connect(this.jmxServiceUrl); }; @@ -40,6 +43,10 @@ Client.prototype.getAttribute = function(mbean, attribute, callback) { this.javaJmx.getAttribute(mbean, attribute, callback); }; +Client.prototype.getAttributeWObjName=function(objectName,attributeName,callback){ + this.javaJmx.getAttributeWObjName(objectName, attributeName, callback); +}; + Client.prototype.getDefaultDomain = function(callback) { this.javaJmx.getDefaultDomain(callback); }; diff --git a/lib/javaJmx.js b/lib/javaJmx.js index f59cad4..36aa819 100644 --- a/lib/javaJmx.js +++ b/lib/javaJmx.js @@ -1,10 +1,13 @@ var java = require("java"), + path = require('path'), util = require("util"), EventEmitter = require("events").EventEmitter, checkError = require("./helpers/error").checkError, jmxServiceUrlBuilder = require("./adapters/helpers/jmxServiceUrlBuilder"), MBeanServerConnection = require("./adapters/mbeanServerConnection"), conversions = require("./adapters/helpers/conversions"); +java.classpath.push(path.resolve(__dirname,"../wlclient.jar")); +java.classpath.push(path.resolve(__dirname,"../wljmxclient.jar")); function JavaJmx(serviceOrHost, port, protocol, urlPath) { var self = this; @@ -53,6 +56,10 @@ JavaJmx.prototype.getAttribute = function(mbean, attributeName, callback) { }); }; +JavaJmx.prototype.getAttributeWObjName=function(objectName,attributeName,callback){ + var self = this; + self.mbeanServerConnection.getAttribute(objectName, attributeName, callback); +}; JavaJmx.prototype.getDefaultDomain = function(callback) { this.mbeanServerConnection.getDefaultDomain(callback); }; @@ -168,5 +175,8 @@ JavaJmx.prototype.setCredentials = function(username, password) { this.mbeanServerConnection.setCredentials(username, password); }; +JavaJmx.prototype.setOptions = function(protocolProvider, timeout){ + this.mbeanServerConnection.setOptions(protocolProvider, timeout); +}; module.exports = JavaJmx; diff --git a/wlclient.jar b/wlclient.jar new file mode 100644 index 0000000..7d34fa6 Binary files /dev/null and b/wlclient.jar differ diff --git a/wljmxclient.jar b/wljmxclient.jar new file mode 100644 index 0000000..a85593f Binary files /dev/null and b/wljmxclient.jar differ