Author: pidster
Date: Sat Jan 8 12:07:31 2011
New Revision: 1056696
URL: http://svn.apache.org/viewvc?rev=1056696&view=rev
Log:
Fix some errors detected by GroovyLint - some guessing required
Modified:
incubator/kitty/trunk/src/org/apache/kitty/CmdShell.groovy
incubator/kitty/trunk/src/org/apache/kitty/client/Client.groovy
incubator/kitty/trunk/src/org/apache/kitty/client/jmxmp/JMXMPClient.groovy
incubator/kitty/trunk/test/org/apache/kitty/test/ClientTest0.groovy
Modified: incubator/kitty/trunk/src/org/apache/kitty/CmdShell.groovy
URL:
http://svn.apache.org/viewvc/incubator/kitty/trunk/src/org/apache/kitty/CmdShell.groovy?rev=1056696&r1=1056695&r2=1056696&view=diff
==============================================================================
--- incubator/kitty/trunk/src/org/apache/kitty/CmdShell.groovy (original)
+++ incubator/kitty/trunk/src/org/apache/kitty/CmdShell.groovy Sat Jan 8
12:07:31 2011
@@ -1,29 +1,29 @@
/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.apache.kitty
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import org.apache.kitty.client.Client;
-import org.apache.kitty.utils.Help;
-import org.apache.kitty.utils.Constants;
+import java.io.BufferedReader
+import java.io.InputStreamReader
+
+import org.apache.kitty.client.Client
+import org.apache.kitty.utils.Constants
+import org.apache.kitty.utils.Help
/**
* <pre>
@@ -37,7 +37,7 @@ import org.apache.kitty.utils.Constants;
*
*/
class CmdShell {
-
+
def static final PROMPT = "kitty>"
static String HOST = "localhost"
static String PORT = "9024"
@@ -45,7 +45,21 @@ class CmdShell {
def static remote
static InputStreamReader inReader;
static BufferedReader bReader;
- static commands = ["help", "connect", "disconnect", "exit", "ls",
"echo", "domains", "cd", "get", "set", "invoke", "pwd", "setdomain"]
+ static commands = [
+ "help",
+ "connect",
+ "disconnect",
+ "exit",
+ "ls",
+ "echo",
+ "domains",
+ "cd",
+ "get",
+ "set",
+ "invoke",
+ "pwd",
+ "setdomain"
+ ]
/**
*
@@ -58,74 +72,62 @@ class CmdShell {
static main(args) {
startShell()
}
-
- static startShell()
- {
+
+ static startShell() {
def input
- this.inReader = new InputStreamReader(System.in)
- this.bReader = new BufferedReader(inReader)
- this.client = new Client()
-
- while(!(input.equals("exit")))
- {
+ inReader = new InputStreamReader(System.in)
+ bReader = new BufferedReader(inReader)
+ client = new Client()
+
+ while (!(input.equals("exit"))) {
print PROMPT
input = getUserInput()
inputHandler(input)
}
- this.inReader.close()
- this.bReader.close()
-
- }
-
- static inputHandler(String input)
- {
+ inReader.close()
+ bReader.close()
+ }
+
+ static inputHandler(String input) {
Integer index = 0
String[] params
-
- if(input.contains(" "))
- {
+
+ if (input.contains(" ")) {
params = input.split(" ")
input = params[0]
}
- else
- {
+ else {
params = {input}
}
-
- if(this.commands.contains(input))
- {
+
+ if (commands.contains(input)) {
index = commands.indexOf(input)
//println "The index is" + index
-
+
switch(index)
{
case 0:
cmdHelp()
break;
case 1:
- if(params.length > 3)
- {
+ if (params.length > 3) {
println "You have entered an
invalid number of parameters, you may enter host and port as parameters only"
}
- if(params.length == 3)
- {
+ if (params.length == 3) {
cmdConnect(params[1],params[2])
}
- else
- {
- if(params.length == 2)
- {
+ else {
+ if (params.length == 2) {
cmdConnect(params[1])
}
- else
- {
+ else {
cmdConnect()
}
}
break;
case 2:
cmdDisconnect()
- this.remote = null;
+ remote = null;
break;
case 3:
cmdExit()
@@ -140,60 +142,50 @@ class CmdShell {
cmdDomains()
break;
case 7:
- if(params.length >= 2)
- {
+ if (params.length >= 2) {
cmdCd(params[1])
}
- else
- {
+ else {
println
Constants.ERROR_TOO_FEW_PARAMETERS
println "You must enter a path
parameter after 'cd'"
}
break;
case 8:
- if(params.length >= 2)
- {
+ if (params.length >= 2) {
cmdGet(params[1])
}
- else
- {
+ else {
println
Constants.ERROR_TOO_FEW_PARAMETERS
println "You must enter at 1
parameter after the command"
}
break;
case 9:
- if(params.length >= 3)
- {
+ if (params.length >= 3) {
cmdSet(params[1], params[2])
}
- else
- {
+ else {
println
Constants.ERROR_TOO_FEW_PARAMETERS
println "You must enter an
attribute parameter and a value parameter"
}
break;
case 10:
- if(params.length >= 3)
- {
+ if (params.length >= 3) {
cmdInvoke(params[1],params[2])
}
- else
- {
+ else {
println
Constants.ERROR_TOO_FEW_PARAMETERS
println "You must enter an
operation name followed by parameter(s)"
}
-
+
break;
case 11:
cmdPwd()
break;
case 12:
- if(params.length >= 2)
- {
+ if (params.length >= 2) {
cmdSetDomain(params[1])
}
- else
- {
+ else {
println
Constants.ERROR_TOO_FEW_PARAMETERS
println "You must enter a
domain name parameter after 'setdomain' command"
}
@@ -202,215 +194,168 @@ class CmdShell {
break;
}
}
- else
- {
+ else {
println input + " is not a valid command"
}
}
-
- static String getUserInput()
- {
+
+ static String getUserInput() {
def userInput
userInput = bReader.readLine()
return userInput;
}
-
- static cmdHelp()
- {
+
+ static cmdHelp() {
Help h = new Help()
println h.toString()
}
-
- static cmdConnect()
- {
- def _host = this.HOST
- def _port = this.PORT
+
+
+ static cmdConnect() {
+ def _host = HOST
+ def _port = PORT
println "connecting to $_host at port $_port...."
- this.getClient().connect(this.HOST, this.PORT)
- if(this.getClient().getRemote())
- {
+ getClient().connect(HOST, PORT)
+ if (getClient().getRemote()) {
println "Successfully connected to host"
- this.remote = this.getClient().getRemote()
+ remote = getClient().getRemote()
}
- else
- {
+ else {
println "Connection attempt was unsuccessful"
}
-
}
-
- static cmdConnect(_host)
- {
- def _port = this.PORT
- this.getClient().connect(_host, this.PORT)
+
+ static cmdConnect(_host) {
+ def _port = PORT
+ getClient().connect(_host, PORT)
println "connecting to $_host at port $_port...."
- if(this.getClient().getRemote())
- {
+ if (getClient().getRemote()) {
println "Successfully connected to host"
- this.remote = this.getClient().getRemote()
+ remote = getClient().getRemote()
}
- else
- {
+ else {
println "Connection attempt was unsuccessful"
}
-
}
-
- static cmdConnect(_host, _port)
- {
+
+ static cmdConnect(_host, _port) {
println "connecting to $_host at port $_port...."
- this.getClient().connect(_host, _port)
- if(this.getClient().getRemote())
- {
+ getClient().connect(_host, _port)
+ if (getClient().getRemote()) {
println "Successfully connected to host"
- this.remote = this.getClient().getRemote()
+ remote = getClient().getRemote()
}
- else
- {
+ else {
println "Connection attempt was unsuccessful"
}
-
}
-
- static cmdDisconnect()
- {
+
+ static cmdDisconnect() {
println "disconnecting..."
- if(client.getRemote())
- {
- this.client.disconnect();
- if(!client.getRemote())
- {
+ if (client.getRemote()) {
+ client.disconnect();
+ if (!client.getRemote()) {
println "successfully disconnected from host"
}
}
- else
- {
+ else {
println "client can not disconnect because it is not
connected to a host"
}
-
}
-
- static cmdExit()
- {
+
+ static cmdExit() {
println "exiting..."
println "successfully exited kitty"
}
-
- static cmdLs()
- {
+
+ static cmdLs() {
println "listing files and directories..."
- if(remote)
- {
- this.getClient().ls()
+ if (remote) {
+ getClient().ls()
println "The domain list is:"
}
- else
- {
+ else {
println Constants.ERROR_NOT_CONNECTED
}
}
-
- static cmdEcho(def input)
- {
- if(input.size() > 1)
- {
+
+ static cmdEcho(def input) {
+ if (input.size() > 1) {
input.each { print it+" " }
}
println()
}
-
- static cmdDomains()
- {
+
+ static cmdDomains() {
println "getting domains..."
- def domains = this.getClient().getDomainList()
- if(domains)
- {
+ def domains = getClient().getDomainList()
+ if (domains) {
println "A list of domains is available"
}
- else
- {
+ else {
println "No domains are available"
}
}
-
- static cmdCd(String path)
- {
+
+ static cmdCd(String path) {
println "changing remote path..."
- if(remote)
- {
- this.getClient().cd(path)
+ if (remote) {
+ getClient().cd(path)
}
- else
- {
+ else {
println Constants.ERROR_NOT_CONNECTED
}
}
-
- static cmdGet(def attr)
- {
+
+ static cmdGet(def attr) {
println "get $attr..."
- if(remote)
- {
- this.getClient().get(attr)
+ if (remote) {
+ getClient().get(attr)
}
- else
- {
+ else {
println Constants.ERROR_NOT_CONNECTED
}
}
-
- static cmdSet(def attr, def val)
- {
+
+ static cmdSet(def attr, def val) {
println "set $attr to $val"
- if(remote)
- {
- this.getClient().set(attr, val)
+ if (remote) {
+ getClient().set(attr, val)
}
- else
- {
+ else {
println Constants.ERROR_NOT_CONNECTED
}
}
-
- static cmdInvoke(def op, def params)
- {
+
+ static cmdInvoke(def op, def params) {
println "Invoking the following operation: $op"
- if(remote)
- {
- this.getClient().invoke(op, params)
+ if (remote) {
+ getClient().invoke(op, params)
}
- else
- {
+ else {
println Constants.ERROR_NOT_CONNECTED
}
}
-
- static cmdPwd()
- {
+
+ static cmdPwd() {
println "Displaying the current remote path..."
- if(remote)
- {
- String name = (String)this.getClient().pwd()
+ if (remote) {
+ String name = (String) getClient().pwd()
println name
}
- else
- {
+ else {
println Constants.ERROR_NOT_CONNECTED
}
}
-
- static cmdSetDomain(def domain)
- {
+
+ static cmdSetDomain(def domain) {
println "Setting the domain to $domain..."
- if(remote)
- {
- this.getClient().setDomain(domain)
+ if (remote) {
+ getClient().setDomain(domain)
println "The domain is set to $domain"
}
- else
- {
+ else {
println Constants.ERROR_NOT_CONNECTED
}
}
-
}
Modified: incubator/kitty/trunk/src/org/apache/kitty/client/Client.groovy
URL:
http://svn.apache.org/viewvc/incubator/kitty/trunk/src/org/apache/kitty/client/Client.groovy?rev=1056696&r1=1056695&r2=1056696&view=diff
==============================================================================
--- incubator/kitty/trunk/src/org/apache/kitty/client/Client.groovy (original)
+++ incubator/kitty/trunk/src/org/apache/kitty/client/Client.groovy Sat Jan 8
12:07:31 2011
@@ -1,29 +1,31 @@
/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.apache.kitty.client
-import java.io.IOException
-import javax.management.remote.JMXConnectorFactory;
-import javax.management.remote.JMXServiceURL;
-import javax.management.Attribute;
-import javax.management.ObjectName;
-import org.apache.kitty.exceptions.*;
+import java.io.IOException
+
+import javax.management.Attribute
+import javax.management.ObjectName
+import javax.management.remote.JMXConnectorFactory
+import javax.management.remote.JMXServiceURL
+
+import org.apache.kitty.exceptions.*
/**
@@ -40,7 +42,7 @@ import org.apache.kitty.exceptions.*;
*
*/
class Client {
-
+
def host
def port
def domain
@@ -49,19 +51,18 @@ class Client {
def remote
def connector
def url
-
- public connect(def _host, def _port)
- {
+ def mbean
+
+ public connect(def _host, def _port) {
//TODO
def serviceURL
def properties = new HashMap()
- if(remote != null)
+ if (remote != null)
{
disconnect()
}
-
- try
- {
+
+ try {
serviceURL =
"service:jmx:rmi:///jndi/rmi://$_host:$_port/jmxrmi"
this.url = new JMXServiceURL(serviceURL)
println "the url is $url"
@@ -69,33 +70,26 @@ class Client {
this.connector = JMXConnectorFactory.connect(this.url,
properties)
this.remote = this.connector.getMBeanServerConnection()
}
- catch(IOException e)
- {
+ catch(IOException e) {
connector = null
remote = null
println e.getMessage()
}
- finally
- {
- if(this.remote != null)
- {
+ finally {
+ if (this.remote != null) {
this.host = _host
this.port = _port
}
}
}
-
- public disconnect()
- {
- try
- {
- if(this.remote != null)
- {
+
+ public disconnect() {
+ try {
+ if (this.remote != null) {
connector.close()
}
}
- finally
- {
+ finally {
this.host = null
this.port = null
this.remote = null
@@ -104,26 +98,23 @@ class Client {
this.mBeansPath = null
}
}
-
+
/**
* <pre>
* Get a list of domains from the remote host and print the list to
standard output
* </pre>
* @return
*/
- public domains()
- {
- if(this.remote)
- {
+ public domains() {
+ if (this.remote) {
this.domainList = remote.getDomains()
this.domainList.each { println it }
}
- else
- {
+ else {
println "The remote connection is null"
}
}
-
+
/**
* <pre>
* Assign a value to the domain
@@ -131,51 +122,41 @@ class Client {
* @param _domain
* @return
*/
- public setDomain(def _domain)
- {
- if(this.remote)
- {
- if(_domain.equals(""))
- {
+ public setDomain(def _domain) {
+ if (this.remote) {
+ if (_domain.equals("")) {
this.domain = null
return
}
-
+
this.domainList = remote.getDomains()
this.domainList.each {
- if(it.equals(_domain))
- {
+ if (it.equals(_domain)) {
this.domain = _domain
this.mBeanPath = []
return
}
}
}
- else
- {
+ else {
println "domain not found"
}
}
-
+
/**
*
* @return
*/
- public ls()
- {
- if(this.remote)
- {
- if(this.domain)
- {
+ public ls() {
+ if (this.remote) {
+ if (this.domain) {
def objectName = this.domain + ":"
def objectName2
- if(objectName.length() > 0)
- {
+ if (objectName.length() > 0) {
objectName +=
",".concat(this.mBeansPath.join()) // make sure mBeansPath is a list,
otherwise remove the .join() command
objectName2 = objectName + ","
}
- else
- {
+ else {
objectName2 = objectName
}
def pool = new ObjectName(objectName2 + "*")
@@ -183,300 +164,243 @@ class Client {
println objectName
println "-----"
def qNames = this.remote.queryNames(pool, null)
- try
- {
+ try {
qNames.each { mbean ->
def p =
mbean.toString().split(objectName2)[1].split(',')[0]
paths[p] = p
}
- paths.each { p ->
- println "M " + p
- }
+ paths.each { p -> println "M " + p }
}
- catch(Exception e)
- {
+ catch(Exception e) {
throw new DomainIsNoneException()
}
-
- try
- {
+
+ try {
mbean = this.remote.getMBeanInfo( new
ObjectName(objectName))
- for(attr in mbean.getAttributes())
- {
+ for (attr in mbean.getAttributes()) {
def readable
def writable
- try
- {
- def value =
this.remote.getAttribute(new ObjectName(objectName), attr.getName())
- def valueStr =
(String)value
+ def value
+ def valueStr
+
+ try {
+ value =
this.remote.getAttribute(new ObjectName(objectName), attr.getName())
+ valueStr = (String)value
}
- catch(Exception e)
- {
+ catch(Exception e) {
valueStr = "-- " +
attr.getType() + " --"
}
- if(attr.isReadable())
- {
+ if (attr.isReadable()) {
readable = "r"
}
- else
- {
+ else {
readable = "-"
}
- if(attr.isWritable())
- {
+ if (attr.isWritable()) {
writable = "w"
}
- else
- {
+ else {
writable = "-"
}
println "A " + readable +
writable + " " + attr.getName() + " : " + valueStr
}
}
- catch(Exception e)
- {
+ catch(Exception e) {
//
}
-
- try
- {
+
+ try {
mbean = this.remote.getMBeanInfo( new
ObjectName(objectName))
- for(ops in mbean.getOperations())
- {
+ for (ops in mbean.getOperations()) {
def params = []
- for(p in ops.getSignature())
- {
+ for (p in ops.getSignature()) {
params.append(p.getType())
}
println "O " +
ops.getReturnType() + " " + ops.getName() + " ( " + ",".concat(params.join())
+ ")"
}
}
- catch(Exception e)
- {
+ catch(Exception e) {
throw new DomainIsNoneException()
}
}
}
}
-
+
/**
*
* @return
*/
- public cd(String path)
- {
- if(this.remote)
- {
- if(this.domain)
- {
- if(path == "..")
- {
- if(this.mBeansPath.length())
- {
- this.mBeansPath.pop()
+ public cd(String path) {
+ if (this.remote) {
+ if (this.domain) {
+ if (path == "..") {
+ if (this.mBeansPath.length()) {
+ this.mBeansPath.pop()
}
}
- else
- {
- for(p in path.split(','))
- {
- this.mBeansPath.append(p)
+ else {
+ for (p in path.split(',')) {
+ this.mBeansPath.append(p)
}
}
}
}
}
-
+
/**
*
*/
- public get(att)
- {
- if(this.remote)
- {
- if(this.domain)
- {
- def objectName = this.domain + ":"
+ public get(att) {
+ if (this.remote) {
+ if (this.domain) {
+ def objectName = this.domain + ":"
def readable
def writable
- def valueStr
- if(this.mBeansPath.length > 0)
- {
- objectName = objectName +
','.concat(this.mBeansPath.join())
- }
- try
- {
- mbean = this.remote.getMBeanInfo(new
ObjectName(objectName))
- }
- catch(Exception e)
- {
- throw new MBeanNotFoundException()
- }
- attr = null
- for(a in mbean.getAttributes())
- {
- if(a.getName() == att)
- {
- attr = a
- break
+ def value
+ def valueStr
+ def attr = null
+
+ if (this.mBeansPath.length > 0) {
+ objectName = objectName +
','.concat(this.mBeansPath.join())
+ }
+ try {
+ mbean = this.remote.getMBeanInfo(new
ObjectName(objectName))
+ }
+ catch(Exception e) {
+ throw new MBeanNotFoundException()
+ }
+
+ for (a in mbean.getAttributes()) {
+ if (a.getName() == att) {
+ attr = a
+ break
}
}
- if(!attr)
- {
- throw new MBeanAttributeNotFoundException()
- }
- try
- {
- value = this.remote.getAttribute(new
ObjectName(objectName), att)
- valueStr = str(value)
- }
- catch(Exception e)
- {
- valueStr = "-- " + attr.getType() + " --"
- }
- if(attr.isReadable())
- {
- readable = "Y"
- }
- else
- {
- readable = "N"
- }
- if(attr.isWritable())
- {
- writable = "Y"
- }
- else
- {
- writable = "N"
- }
- println "ObjectName :" + objectName
- println "Attribute :" + attr.getName()
- println "Value :" + valueStr
- println "isReadable : " + readable
- println "isWritable : " + writable
+ if (!attr) {
+ throw new
MBeanAttributeNotFoundException()
+ }
+ try {
+ value = this.remote.getAttribute(new
ObjectName(objectName), att)
+ valueStr = str(value)
+ }
+ catch(Exception e) {
+ valueStr = "-- " + attr.getType() + "
--"
+ }
+ if (attr.isReadable()) {
+ readable = "Y"
+ }
+ else {
+ readable = "N"
+ }
+ if (attr.isWritable()) {
+ writable = "Y"
+ }
+ else {
+ writable = "N"
+ }
+ println "ObjectName :" + objectName
+ println "Attribute :" + attr.getName()
+ println "Value :" + valueStr
+ println "isReadable : " + readable
+ println "isWritable : " + writable
}
}
}
-
+
/**
*
* @return
*/
- public set(att, val)
- {
- if(this.remote)
- {
- if(this.domain)
- {
- def objectName = this.domain + ":"
- if(this.mBeansPath.length() > 0)
- {
- objectName = objectName +
','.concat(this.mBeansPath.join())
- }
- try
- {
- mbean = this.remote.getMBeanInfo(new
ObjectName(objectName))
- }
- catch(Exception e)
- {
- throw new MBeanNotFoundException()
- }
- attr = null
- for(a in mbean.getAttributes())
- {
- if(a.getName() == att)
- attr = a
- break
- }
- if(!attr)
- {
- throw new MBeanAttributeNotFoundException()
- }
- if(attr.isWritable())
- {
- try
- {
- a = new Attribute(att, val)
- this.remote.setAttribute(new ObjectName(objectName), a)
+ public set(att, val) {
+ if (this.remote) {
+ if (this.domain) {
+ def objectName = this.domain + ":"
+ def attr
+
+ if (this.mBeansPath.length() > 0) {
+ objectName = objectName +
','.concat(this.mBeansPath.join())
+ }
+ try {
+ mbean = this.remote.getMBeanInfo(new
ObjectName(objectName))
+ }
+ catch(Exception e) {
+ throw new MBeanNotFoundException()
+ }
+ attr = null
+ for (a in mbean.getAttributes()) {
+ if (a.getName() == att)
+ attr = a
+ break
+ }
+ if (!attr) {
+ throw new
MBeanAttributeNotFoundException()
+ }
+ if (attr.isWritable()) {
+ try {
+ def a = new Attribute(att, val)
+ this.remote.setAttribute(new
ObjectName(objectName), a)
}
- catch(Exception e)
- {
- throw new SetAttributeException()
+ catch(Exception e) {
+ throw new
SetAttributeException()
}
}
- else
- {
- throw new SetAttributeException()
+ else {
+ throw new SetAttributeException()
}
}
}
}
-
+
/**
*
* @param op
* @param params
* @return
*/
- public invoke(op, params)
- {
- if(this.remote)
- {
- if(this.domain)
- {
+ public invoke(op, params) {
+ if (this.remote) {
+ if (this.domain) {
def objectName = this.domain + ":"
- if(this.mBeansPath.length())
- {
+ if (this.mBeansPath.length()) {
objectName = objectName +
','.concat(this.mBeansPath.join())
}
try{
mbean = this.remote.getMBeanInfo(new
ObjectName(objectName))
}
- catch(Exception)
- {
+ catch(Exception) {
throw new MBeanNotFoundException()
}
def ops = null
- for(o in mbean.getOperations())
- {
- if(o.getName() == op)
- {
+ for (o in mbean.getOperations()) {
+ if (o.getName() == op) {
ops = o
break
}
}
- if(!ops)
- {
+ if (!ops) {
throw new OperationNotFoundException()
}
def sig = []
- for(s in ops.getSignature())
- {
- sig.append(p.getType())
- }
-
- try
- {
+ for (s in ops.getSignature()) {
+ sig.append(s.getType())
+ }
+
+ try {
this.remote.invoke(new
ObjectName(objectName), op, params, sig)
}
- catch(Exception e)
- {
+ catch(Exception e) {
throw new InvokeException()
}
}
}
}
-
- public pwd()
- {
+
+ public pwd() {
def name
- if(this.domain)
- {
+ if (this.domain) {
name = this.domain + ":" +
",".concat(this.mBeansPath.join()) // may need to change this
}
-
+
return name
}
-
}
Modified:
incubator/kitty/trunk/src/org/apache/kitty/client/jmxmp/JMXMPClient.groovy
URL:
http://svn.apache.org/viewvc/incubator/kitty/trunk/src/org/apache/kitty/client/jmxmp/JMXMPClient.groovy?rev=1056696&r1=1056695&r2=1056696&view=diff
==============================================================================
--- incubator/kitty/trunk/src/org/apache/kitty/client/jmxmp/JMXMPClient.groovy
(original)
+++ incubator/kitty/trunk/src/org/apache/kitty/client/jmxmp/JMXMPClient.groovy
Sat Jan 8 12:07:31 2011
@@ -1,25 +1,27 @@
/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.apache.kitty.client.jmxmp
-import javax.management.remote.JMXConnectorFactory
-import org.apache.kitty.client.Client;
+import javax.management.remote.JMXConnectorFactory
+import javax.management.remote.JMXServiceURL
+
+import org.apache.kitty.client.Client
/**
* <pre>
@@ -33,44 +35,29 @@ import org.apache.kitty.client.Client;
*
*/
class JMXMPClient extends Client {
-
- def host
- def port
- def domain
- def mBeansPath
- def remote
- def connector
-
+
@Override
- public connect(def _host, def _port)
- {
- //TODO
- def serviceURL
- if(remote != null)
- {
+ public connect(def _host, def _port) {
+
+ if (this.remote != null) {
disconnect()
}
-
- try
- {
- serviceURL = "service:jmx:jmxmp://$_host:$_port"
- this.url = JMXServiceURL(serviceURL)
- this.connector = JMXConnectorFactory.connect(url)
+
+ try {
+ def serviceURL = "service:jmx:jmxmp://$_host:$_port"
+ this.url = new JMXServiceURL(serviceURL)
+ this.connector = JMXConnectorFactory.connect(this.url)
this.remote = this.connector.getMBeanServerConnection()
}
- catch(IOException e)
- {
- connector = null
- remote = null
+ catch(IOException e) {
+ this.connector = null
+ this.remote = null
}
- finally
- {
- if(this.remote != null)
- {
+ finally {
+ if(this.remote != null) {
this.host = _host
this.port = _port
}
}
}
-
}
Modified: incubator/kitty/trunk/test/org/apache/kitty/test/ClientTest0.groovy
URL:
http://svn.apache.org/viewvc/incubator/kitty/trunk/test/org/apache/kitty/test/ClientTest0.groovy?rev=1056696&r1=1056695&r2=1056696&view=diff
==============================================================================
--- incubator/kitty/trunk/test/org/apache/kitty/test/ClientTest0.groovy
(original)
+++ incubator/kitty/trunk/test/org/apache/kitty/test/ClientTest0.groovy Sat Jan
8 12:07:31 2011
@@ -15,10 +15,10 @@
* limitations under the License.
*/
-
-package org.apache.kitty.test;
-import groovy.util.GroovyTestCase;
+package org.apache.kitty.test
+
+import groovy.util.GroovyTestCase
/**
*
@@ -47,11 +47,11 @@ class ClientTest extends GroovyTestCase
protected void tearDown() throws Exception {
super.tearDown();
}
-}
/**
* Test method for {...@link
org.apache.kitty.client.Client#connect(java.lang.Object, java.lang.Object)}.
*/
- public final void testConnect(){
- fail("Not yet implemented"); // TODO
+ def testConnect() {
+ fail("Not yet implemented"); // TODO
}
+}