diff --git a/README.md b/README.md index 8f5c248..5a1fe00 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,24 @@ client.read([{mbean: "JMImplementation:type=MBeanServerDelegate", attribute="Imp }); ``` +### Exec mbean method + +#### client.exec(mbean, operation, arguments, callback) + +``` +//execute the operation "operation" on mbean1 with no arguments for the call: +client.exec("mbean1", "operation", [], function(result){ + console.log(...); +}); + +//execute the operation "operation" on all mbeans with "argument1" and "argument2" as arguments for each call: +client.exec(["mbean1","mbean2"], "operation", ["argument1", "argument2"], function(result){ + console.log(...); +}); + +``` + + jmx4node -------- diff --git a/lib/jolokia-client.js b/lib/jolokia-client.js index 2f6b147..69d879c 100644 --- a/lib/jolokia-client.js +++ b/lib/jolokia-client.js @@ -196,6 +196,44 @@ Jolokia.prototype.dump = function(mbean, callback) { }); }; +Jolokia.prototype.exec = function(mbean, operation, arguments, callback) { + //mbean can be an array of mbeans, same operation is taken for all mbeans, arguments is an array. Supply [] for no arguments. + + if (!_.isArray(mbean)) { + requestJSON(this.url, { + "type" : "exec", + "mbean" : mbean, + "operation" : operation, + "arguments" : arguments + }, function(response) { + callback(response); + }); + return; + } + + var content = []; + + for ( var idx in mbean) { + var bean = mbean[idx]; + + content[idx] = _.isString(bean) ? { + "type" : "exec", + "mbean" : bean, + "operation" : operation, + "arguments" : arguments + } : { + "type" : "exec", + "mbean" : bean.mbean, + "operation" : operation, + "arguments" : arguments + }; + } + + requestJSON(this.url, content, function(response) { + callback(response); + }); +}; + // Exports // ----------------------------------------------------------------------------