Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.management.remote.JMXConnectorFactory as JmxFactory
- import javax.management.remote.JMXServiceURL as JmxUrl
- def props = new Properties()
- def file = new File('./jmx.properties')
- if (file.exists()){
- new File('jmx.properties').withInputStream {
- stream -> props.load(stream)
- }
- } else{
- props.putAll([host : 'localhost', port : 0000])
- }
- def serverUrl = "service:jmx:rmi:///jndi/rmi://${props.host}:${props.port}/jmxrmi"
- String beanName = "analytics:name=Groovy executor"
- def server = JmxFactory.connect(new JmxUrl(serverUrl)).MBeanServerConnection
- def dataSystem = new GroovyMBean(server, beanName)
- String result
- String[] args = new String[1]
- args[0] = "classpath_script_filename"
- if (args.length == 0){
- result = 'required parameter (script name) is absent!'
- } else if (args.length == 1) {
- String scriptName = args[0]
- println "invoke script '$scriptName' on $serverUrl"
- result = dataSystem.executeScriptInContext(scriptName);
- } else {
- /** аргументов больше одного, интерпретируем их как выражения key=value **/
- String scriptName = args[0]
- Map<String, String> map = [:]
- for (int i = 1; i < args.length; i++) {
- String argument = args[i]
- if (argument ==~ /\p{Alnum}+=\p{Alnum}+/){
- String[] arr = argument.split('=')
- map[arr[0]] = arr[1]
- println argument
- }
- }
- println "invoke script '$scriptName' on $serverUrl with args:${map}"
- result = dataSystem.executeScriptInContextWithArgs(scriptName,map)
- }
- println result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement