diff options
Diffstat (limited to 'qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands')
17 files changed, 2951 insertions, 0 deletions
diff --git a/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/CommandImpl.java b/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/CommandImpl.java new file mode 100644 index 0000000000..6fdae4c0a6 --- /dev/null +++ b/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/CommandImpl.java @@ -0,0 +1,153 @@ +/* + * + * 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.qpid.commands; + +import java.util.Map; + +import org.apache.qpid.Command; +import org.apache.qpid.utils.CommandLineOption; +import org.apache.qpid.utils.JMXinfo; + +public abstract class CommandImpl implements Command +{ + protected JMXinfo info = null; + + private String name; + private String virtualhost = null; + private String object = null; + + private String outputformat = null; + private String seperator = ","; + + public CommandImpl(JMXinfo info) + { + this.info = info; + } + + public CommandImpl() + { + + } + + protected void setName(String name) + { + this.name = name; + } + + public String getName() + { + return this.name; + } + + protected boolean hasName() + { + if (this.name == null) + return false; + + else + return true; + } + + protected void setObject(String object) + { + this.object = object; + } + + public String getObject() + { + return this.object; + } + + protected void setOutputFormat(String outputformat) + { + this.outputformat = outputformat; + } + + protected String getOutputFormat() + { + return outputformat; + } + + protected void setSeperator(String seperator) + { + this.seperator = seperator; + } + + protected String getSeperator() + { + return seperator; + } + + protected void setVirtualhost(String virtualhost) + { + this.virtualhost = virtualhost; + } + + public String getVirtualhost() + { + return this.virtualhost; + } + + public String optionchecker(String option_letter) + { + Map map = info.getCommandLineOptionParser().getAlloptions(); + if (map == null) + return null; + CommandLineOption option = (CommandLineOption) map.get(option_letter); + if (option == null) + return null; + String value = option.getOptionValue(); + return value; + } + + public boolean checkoptionsetting(String option_letter) + { + Map map = info.getCommandLineOptionParser().getAlloptions(); + if (map == null) + return false; + CommandLineOption option = (CommandLineOption) map.get(option_letter); + if (option == null) + return false; + String value = option.getOptionType(); + + if (value != null) + return true; + else + return false; + } + + public void echo(String str) + { + System.out.println(str); + } + + public void unrecognizeoption() + { + echo("list: Unrecognized option"); + echo("Try --help for more information"); + } + + public abstract void execute(); + + public abstract void printusage(); + +} diff --git a/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/Commanddelete.java b/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/Commanddelete.java new file mode 100644 index 0000000000..cdbb8f1d4f --- /dev/null +++ b/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/Commanddelete.java @@ -0,0 +1,199 @@ +/* + * + * 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.qpid.commands; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.Iterator; +import java.util.Set; +import java.util.StringTokenizer; + +import javax.management.MBeanServerConnection; +import javax.management.ObjectName; + +import org.apache.qpid.commands.objects.QueueObject; +import org.apache.qpid.utils.JMXinfo; + +public class Commanddelete extends CommandImpl +{ + private int number = 0; + private QueueObject objname; + private MBeanServerConnection mbsc; + private String method1, method2; + private ObjectName queue; + public static final String COMMAND_NAME = "delete"; + + public Commanddelete(JMXinfo info) + { + super(info); + this.mbsc = info.getmbserverconnector(); + this.objname = new QueueObject(mbsc); + this.method1 = "deleteMessageFromTop"; + this.method2 = "clearQueue"; + + } + + public void deletemessages() + { + Set set = null; + objname.setQueryString(this.getObject(), this.getName(), this.getVirtualhost()); + set = objname.returnObjects(); + + if (objname.getSet().size() != 0) + { + Iterator it = set.iterator(); + this.queue = (ObjectName) it.next(); + try + { + if (this.number == 0) + { + echo(""); + System.out.print("Do you want to delete all the messages from the Queue [Y/N] :"); + InputStreamReader isr = new InputStreamReader(System.in); + BufferedReader br = new BufferedReader(isr); + String s = br.readLine(); + echo(s); + if (s.compareToIgnoreCase("y") == 0) + this.mbsc.invoke(queue, this.method2, null, null); + else + return; + } + else if (objname.getmessagecount(this.queue) < this.number) + { + echo("Given number is Greater than the Queue Depth"); + return; + } + else + { + for (int i = 0; i < this.number; i++) + { + this.mbsc.invoke(queue, this.method1, null, null); + } + } + } + catch (Exception ex) + { + ex.printStackTrace(); + } + + } + else + { + if (hasName()) + { + + echo("The Queue you have specified is not in the current broker"); + echo(""); + } + else + { + printusage(); + } + } + } + + public void execute() + { + /* + * In here you it's easy to handle any number of otpions which are going + * to add with the list command which works with main option object or o + */ + + if (checkoptionsetting("object") || checkoptionsetting("o")) + { + String object = optionchecker("object"); + if (object == null) + { + object = optionchecker("o"); + } + if (object.compareToIgnoreCase("queue") == 0) + setObject(object); + else + { + unrecognizeoption(); + echo("This command is only applicable for delete command so please start with queue"); + } + if (checkoptionsetting("name") || checkoptionsetting("n")) + { + String name = optionchecker("name"); + if (name == null) + name = optionchecker("n"); + + setName(name); + } + if (checkoptionsetting("virtualhost") || checkoptionsetting("v")) + { + String vhost = optionchecker("virtualhost"); + if (vhost == null) + vhost = optionchecker("v"); + setVirtualhost(vhost); + } + if (checkoptionsetting("top") || checkoptionsetting("t")) + { + String number = optionchecker("top"); + if (number == null) + number = optionchecker("t"); + + setnumber(removeSpaces(number)); + } + this.deletemessages(); + } + else if (checkoptionsetting("h") || checkoptionsetting("help")) + printusage(); + else + unrecognizeoption(); + } + + public void printusage() + { + echo(""); + echo("Usage:delete [OPTION] ... [OBJECT TYPE]...\n"); + echo("Delete the top most messages from the given queue object\n"); + echo("To specify the desired queue you have to give the virtualhost name and the queue name with following commands\n"); + echo("Where possible options include:\n"); + echo(" -v --virtualhost Give the virtuallhost name of the desired queue"); + echo(" -n --name Give the queue name of the desired queue you want to do the delete operation"); + echo(" -t --top Give how many number of messages you want to delete from the top (Default = all the messages will be deleted"); + echo(" -h --help Display the help and back to the qpid-cli prompt\n"); + + } + + private void setnumber(String number) + { + Integer i = new Integer(number); + this.number = i.intValue(); + } + + public int getnumber() + { + return this.number; + } + + private static String removeSpaces(String s) + { + StringTokenizer st = new StringTokenizer(s, " ", false); + String t = ""; + while (st.hasMoreElements()) + t += st.nextElement(); + return t; + } +} diff --git a/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/Commandget.java b/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/Commandget.java new file mode 100644 index 0000000000..cb67edeb34 --- /dev/null +++ b/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/Commandget.java @@ -0,0 +1,211 @@ +/* + * + * 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.qpid.commands; + +import org.apache.qpid.commands.objects.ObjectNames; +import org.apache.qpid.commands.objects.QueueObject; +import org.apache.qpid.utils.JMXinfo; + +import javax.management.MBeanServerConnection; +import javax.management.ObjectName; +import java.util.Set; + +public class Commandget extends CommandImpl +{ + + private String _attributeName; + private String _value; + public static final String COMMAND_NAME = "get"; + + public Commandget(JMXinfo info) + { + super(info); + } + + private void getAttribute(String option_value) + { + if (option_value == null) + { + printusage(); + return; + } + MBeanServerConnection mbsc = info.getmbserverconnector(); + Set set = null; + ObjectNames objname = null; + + try + { + if (option_value.compareToIgnoreCase("queue") == 0 || option_value.compareToIgnoreCase("queues") == 0) + { + objname = new QueueObject(mbsc); + } + else + { + printusage(); + echo("Wrong objectName"); + return; + } + + if (_attributeName == null) + { + echo("attribute name not specified. See --help for details"); + return; + } + + objname.setQueryString(this.getObject(), this.getName(), this.getVirtualhost()); + objname.returnObjects(); + + if (objname.getSet().size() != 1) + { + echo("Your query returned more than one object to set was this intended?\n" + objname.getQueryString()); + } + else if (objname.getSet().size() == 1) + { + ObjectName object = (ObjectName) objname.getSet().iterator().next(); + + Object value = objname.getAttribute(object, _attributeName); + + echo(value.toString()); + } + else + { + if (hasName()) + { + + echo("You might be querying wrong " + this.getObject() + " name with --name or -n option "); + echo(""); + echo("No " + this.getObject() + "Type Objects might not in the broker currently"); + echo(""); + } + else + { + printusage(); + } + } + + } + catch (Exception ex) + { + ex.printStackTrace(); + } + + } + + public void execute() + { + /* + * In here you it's easy to handle any number of otpions which are going + * to add with the list command which works with main option object or o + */ + if (checkoptionsetting("output")) + { + setOutputFormat(optionchecker("output")); + if (checkoptionsetting("separator")) + { + setSeperator(optionchecker("separator")); + } + } + if (checkoptionsetting("object") || checkoptionsetting("o")) + { + String object = optionchecker("object"); + if (object == null) + { + object = optionchecker("o"); + } + setObject(object); + + if (checkoptionsetting("name") || checkoptionsetting("n")) + { + String name = optionchecker("name"); + if (name == null) + { + name = optionchecker("n"); + } + + setName(name); + } + + if (checkoptionsetting("attribute") || checkoptionsetting("a")) + { + String name = optionchecker("attribute"); + if (name == null) + { + name = optionchecker("a"); + } + + setAttributeName(name); + } + if (checkoptionsetting("virtualhost") || checkoptionsetting("v")) + { + String vhost = optionchecker("virtualhost"); + if (vhost == null) + { + vhost = optionchecker("v"); + } + setVirtualhost(vhost); + } + getAttribute(this.getObject()); + } + else if (checkoptionsetting("h") || checkoptionsetting("help")) + { + printusage(); + } + else + { + unrecognizeoption(); + } + } + + private void setAttributeName(String name) + { + this._attributeName = name; + } + + public void printusage() + { + echo(""); + echo("Usage:set [OPTION] ... [OBJECT TYPE]...\n"); + echo("List the information about the given object\n"); + echo("Where possible options include:\n"); + echo(" -o --object type of objects which you want to list\n"); + echo(" ex: < list -o queue > : lists all the queues created in the java broker\n"); + echo(" For now list command is supporting following object typse \n"); + echo(" Queue Connection VirtualHost UserMangement Exchange"); + echo(" Or You can specify object type by giving it at the beginning"); + echo(" rather giving it as a argument"); + echo(" Ex:< queue list > this command is equal to list -o queue \n"); + echo(" -v --virtualhost After specifying the object type you can filter output with this option"); + echo(" list objects with the given virtualhost which will help to find "); + echo(" identical queue objects with -n option"); + echo(" ex: queue list -v develop ment"); + echo(" -n --name After specifying what type of objects you want to monitor you can filter"); + echo(" the output using -n option by specifying the name of the object you want "); + echo(" to monitor exactly"); + echo(" ex: <list -o queue -n ping> : list all the queue objects having queue name"); + echo(" of ping"); + echo(" ex: <queue list -n ping -v development> list all the queue objects with name "); + echo(" of ping and virtualhost of developement \n"); + echo(" -a --attribute "); + echo(" -h --help Display the help and back to the qpid-cli prompt\n"); + + } +} diff --git a/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/Commandhelp.java b/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/Commandhelp.java new file mode 100644 index 0000000000..502ac89f74 --- /dev/null +++ b/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/Commandhelp.java @@ -0,0 +1,56 @@ +/* + * + * 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.qpid.commands; + +import org.apache.qpid.utils.JMXinfo; + +public class Commandhelp extends CommandImpl +{ + + public static final String COMMAND_NAME = "help"; + + public Commandhelp(JMXinfo info) + { + } + + public void execute() + { + printusage(); + } + + public void printusage() + { + echo(""); + echo("Current version of qpid CLI is supporting following commands"); + echo(""); + echo("[list] This command is listing limited information about a given type of object"); + echo(" For more information about list command run `list --help`"); + echo("[info] This command is listing All the information about a given type of object"); + echo(" For more information about list command run `info --help`"); + + echo(""); + echo("[exit] This command is disconnect the connection with the Qpid Java broker and go back to normal propmt"); + echo("[quit] This command is disconnect the connection with the Qpid Java broker and go back to normal propmt"); + echo(""); + } + +} diff --git a/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/Commandinfo.java b/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/Commandinfo.java new file mode 100644 index 0000000000..7094a8fc7f --- /dev/null +++ b/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/Commandinfo.java @@ -0,0 +1,206 @@ +/* + * + * 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.qpid.commands; + +import java.util.Set; + +import javax.management.MBeanServerConnection; + +import org.apache.qpid.commands.objects.AllObjects; +import org.apache.qpid.commands.objects.ConnectionObject; +import org.apache.qpid.commands.objects.ExchangeObject; +import org.apache.qpid.commands.objects.ObjectNames; +import org.apache.qpid.commands.objects.QueueObject; +import org.apache.qpid.commands.objects.UserManagementObject; +import org.apache.qpid.commands.objects.VirtualHostObject; +import org.apache.qpid.utils.JMXinfo; + +public class Commandinfo extends CommandImpl +{ + + public static final String COMMAND_NAME = "info"; + + public Commandinfo(JMXinfo info) + { + super(info); + } + + private void listobjects(String option_value) + { + /* + * pring usage if use is not give the correct option letter or no + * options + */ + if (option_value == null) + { + // System.out.println("testing"); + printusage(); + return; + } + MBeanServerConnection mbsc = info.getmbserverconnector(); + Set set = null; + ObjectNames objname = null; + + try + { + if (option_value.compareToIgnoreCase("queue") == 0 || option_value.compareToIgnoreCase("queues") == 0) + { + objname = new QueueObject(mbsc); + + } + else if (option_value.compareToIgnoreCase("Virtualhosts") == 0 + || option_value.compareToIgnoreCase("Virtualhost") == 0) + { + objname = new VirtualHostObject(mbsc); + // this.name = option_value; + } + else if (option_value.compareToIgnoreCase("Exchange") == 0 + || option_value.compareToIgnoreCase("Exchanges") == 0) + { + objname = new ExchangeObject(mbsc); + // this.name = option_value; + } + else if (option_value.compareToIgnoreCase("Connection") == 0 + || option_value.compareToIgnoreCase("Connections") == 0) + { + objname = new ConnectionObject(mbsc); + // this.name = option_value; + } + else if (option_value.compareToIgnoreCase("all") == 0) + { + objname = new AllObjects(mbsc); + // this.name = option_value; + } + else if (option_value.compareToIgnoreCase("Usermanagement") == 0 + || option_value.compareToIgnoreCase("Usermanagmenets") == 0) + { + objname = new UserManagementObject(mbsc); + // this.name = option_value; + } + else + { + printusage(); + echo("Wrong objectName"); + return; + } + objname.setQueryString(this.getObject(), this.getName(), this.getVirtualhost()); + objname.returnObjects(); + if (objname.getSet().size() != 0) + { + objname.displayinfo(this.getOutputFormat(), this.getSeperator()); + + } + else + { + if (hasName()) + { + + echo("You might querying wrong " + this.getObject() + " name with --name or -n option "); + echo(""); + echo("No "+this.getObject() + "Type Objects might not be in the broker currently"); + echo(""); + } + else + { + printusage(); + } + } + + } + catch (Exception ex) + { + ex.printStackTrace(); + } + + } + + public void execute() + { + /* + * In here you it's easy to handle any number of otpions which are going + * to add with the list command which works with main option object or o + */ + if (checkoptionsetting("output")) + { + setOutputFormat(optionchecker("output")); + if (checkoptionsetting("separator")) + setSeperator(optionchecker("separator")); + } + if (checkoptionsetting("object") || checkoptionsetting("o")) + { + String object = optionchecker("object"); + if (object == null) + { + object = optionchecker("o"); + } + setObject(object); + if (checkoptionsetting("name") || checkoptionsetting("n")) + { + String name = optionchecker("name"); + if (name == null) + name = optionchecker("n"); + + setName(name); + } + if (checkoptionsetting("virtualhost") || checkoptionsetting("v")) + { + String vhost = optionchecker("virtualhost"); + if (vhost == null) + vhost = optionchecker("v"); + setVirtualhost(vhost); + } + listobjects(this.getObject()); + } + else if (checkoptionsetting("h") || checkoptionsetting("help")) + printusage(); + else + unrecognizeoption(); + } + + public void printusage() + { + echo(""); + echo("Usage:info [OPTION] ... [OBJECT TYPE]...\n"); + echo("Give ALL the information about the given object\n"); + echo("Where possible options include:\n"); + echo(" -o --object type of objects which you want to list\n"); + echo(" ex: < list -o queue > : lists all the queues created in the java broker\n"); + echo(" For now list command is supporting following object typse \n"); + echo(" Queue Connection VirtualHost UserMangement Exchange"); + echo(" Or You can specify object type by giving it at the beginning rather giving "); + echo(" it as a argument"); + echo(" Ex:< queue info > this command is equal to <info -o queue> command \n"); + echo(" -v --virtualhost After specifying the object type you can filter output with this option"); + echo(" list objects with the given virtualhost which will help to find identical"); + echo(" queue objects with -n option"); + echo(" ex: queue info -v developement"); + echo(" -output Specify which output format you want to get the ouput"); + echo(" Although the option is there current version supports only for CSV output format"); + echo(" -separator This option use with output option to specify which separator you want to get the CSV output (default seperator is comma"); + echo(" -h --help Display the help and back to the qpid-cli prompt\n"); + echo(" -n --name After specifying what type of objects you want to monitor you can filter"); + echo(" the output using -n option by specifying the name of the object you want"); + echo(" to monitor exactly"); + echo(" ex: <queue info -n ping> : Give all the information about queue objects "); + echo(" having queue name of ping\n"); + } +} diff --git a/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/Commandlist.java b/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/Commandlist.java new file mode 100644 index 0000000000..68ee593ba0 --- /dev/null +++ b/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/Commandlist.java @@ -0,0 +1,232 @@ +/* + * + * 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.qpid.commands; + +import java.util.Set; + +import javax.management.MBeanServerConnection; + +import org.apache.qpid.commands.objects.AllObjects; +import org.apache.qpid.commands.objects.ConnectionObject; +import org.apache.qpid.commands.objects.ExchangeObject; +import org.apache.qpid.commands.objects.ObjectNames; +import org.apache.qpid.commands.objects.QueueObject; +import org.apache.qpid.commands.objects.UserManagementObject; +import org.apache.qpid.commands.objects.VirtualHostObject; +import org.apache.qpid.utils.JMXinfo; + +public class Commandlist extends CommandImpl +{ + + public static final String COMMAND_NAME = "list"; + + public Commandlist(JMXinfo info) + { + super(info); + } + + private void listobjects(String option_value) + { + /* + * pring usage if use is not give the correct option letter or no + * options + */ + if (option_value == null) + { + // System.out.println("testing"); + printusage(); + return; + } + MBeanServerConnection mbsc = info.getmbserverconnector(); + Set set = null; + ObjectNames objname = null; + + try + { + if (option_value.compareToIgnoreCase("queue") == 0 || option_value.compareToIgnoreCase("queues") == 0) + { + objname = new QueueObject(mbsc); + + } + else if (option_value.compareToIgnoreCase("Virtualhosts") == 0 + || option_value.compareToIgnoreCase("Virtualhost") == 0) + { + objname = new VirtualHostObject(mbsc); + // this.name = option_value; + } + else if (option_value.compareToIgnoreCase("Exchange") == 0 + || option_value.compareToIgnoreCase("Exchanges") == 0) + { + objname = new ExchangeObject(mbsc); + // this.name = option_value; + } + else if (option_value.compareToIgnoreCase("Connection") == 0 + || option_value.compareToIgnoreCase("Connections") == 0) + { + objname = new ConnectionObject(mbsc); + // this.name = option_value; + } + else if (option_value.compareToIgnoreCase("all") == 0) + { + objname = new AllObjects(mbsc); + // this.name = option_value; + } + else if (option_value.compareToIgnoreCase("Usermanagement") == 0 + || option_value.compareToIgnoreCase("Usermanagmenets") == 0) + { + objname = new UserManagementObject(mbsc); + // this.name = option_value; + } + else + { + printusage(); + echo("Wrong objectName"); + return; + } + objname.setQueryString(this.getObject(), this.getName(), this.getVirtualhost()); + objname.returnObjects(); + if (objname.getSet().size() != 0) + { + if (this.getObject().compareToIgnoreCase("queue") == 0 + || this.getObject().compareToIgnoreCase("queues") == 0) + objname.displayqueues(this.getOutputFormat(), this.getSeperator()); + else + objname.displayobjects(this.getOutputFormat(), this.getSeperator()); + } + else + { + if (hasName()) + { + + echo("You might quering wrong " + this.getObject() + " name with --name or -n option "); + echo(""); + echo(this.getObject() + "Type Objects might not in the broker currently"); + echo(""); + } + else + { + printusage(); + } + } + + } + catch (Exception ex) + { + ex.printStackTrace(); + } + + } + + public void listdomains() + { + MBeanServerConnection mbsc = info.getmbserverconnector(); + try + { + String[] domains = mbsc.getDomains(); + echo("DOMAINS"); + for (int i = 0; i < domains.length; i++) + echo("\tDomain[" + i + "] = " + domains[i]); + + } + catch (Exception ex) + { + ex.printStackTrace(); + } + } + + public void execute() + { + /* + * In here you it's easy to handle any number of otpions which are going + * to add with the list command which works with main option object or o + */ + if (checkoptionsetting("output")) + { + setOutputFormat(optionchecker("output")); + if (checkoptionsetting("separator")) + setSeperator(optionchecker("separator")); + } + if (checkoptionsetting("object") || checkoptionsetting("o")) + { + String object = optionchecker("object"); + if (object == null) + { + object = optionchecker("o"); + } + setObject(object); + if (checkoptionsetting("name") || checkoptionsetting("n")) + { + String name = optionchecker("name"); + if (name == null) + name = optionchecker("n"); + + setName(name); + } + if (checkoptionsetting("virtualhost") || checkoptionsetting("v")) + { + String vhost = optionchecker("virtualhost"); + if (vhost == null) + vhost = optionchecker("v"); + setVirtualhost(vhost); + } + listobjects(this.getObject()); + } + else if (checkoptionsetting("domain") || checkoptionsetting("d")) + listdomains(); + else if (checkoptionsetting("h") || checkoptionsetting("help")) + printusage(); + else + unrecognizeoption(); + } + + public void printusage() + { + echo(""); + echo("Usage:list [OPTION] ... [OBJECT TYPE]...\n"); + echo("List the information about the given object\n"); + echo("Where possible options include:\n"); + echo(" -o --object type of objects which you want to list\n"); + echo(" ex: < list -o queue > : lists all the queues created in the java broker\n"); + echo(" For now list command is supporting following object typse \n"); + echo(" Queue Connection VirtualHost UserMangement Exchange"); + echo(" Or You can specify object type by giving it at the beginning"); + echo(" rather giving it as a argument"); + echo(" Ex:< queue list > this command is equal to list -o queue \n"); + echo(" -d --domain list all the domains of objects available for remote monitoring\n"); + echo(" -v --virtualhost After specifying the object type you can filter output with this option"); + echo(" list objects with the given virtualhost which will help to find "); + echo(" identical queue objects with -n option"); + echo(" ex: queue list -v develop ment"); + echo(" -output Specify which output format you want to get the ouput"); + echo(" Although the option is there current version supports only for CSV output format"); + echo(" -separator This option use with output option to specify which separator you want to get the CSV output (default seperator is comma"); + echo(" -h --help Display the help and back to the qpid-cli prompt\n"); + echo(" -n --name After specifying what type of objects you want to monitor you can filter"); + echo(" the output using -n option by specifying the name of the object you want "); + echo(" to monitor exactly"); + echo(" ex: <list -o queue -n ping> : list all the queue objects having queue name"); + echo(" of ping"); + echo(" ex: <queue list -n ping -v development> list all the queue objects with name "); + echo(" of ping and virtualhost of developement \n"); + + } +} diff --git a/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/Commandmove.java b/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/Commandmove.java new file mode 100644 index 0000000000..6d1803409b --- /dev/null +++ b/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/Commandmove.java @@ -0,0 +1,259 @@ +/* + * + * 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.qpid.commands; + +import java.util.Iterator; +import java.util.Set; +import java.util.StringTokenizer; + +import javax.management.MBeanServerConnection; +import javax.management.ObjectName; + +import org.apache.qpid.commands.objects.QueueObject; +import org.apache.qpid.utils.JMXinfo; + +public class Commandmove extends CommandImpl +{ + + public static final String COMMAND_NAME = "move"; + + private String name1 = null, name2 = null, vhost1 = null, vhost2 = null, method1 = null, method2 = null; // target + // and + // starting + // queue + // specifications + // happen + // with + // these + // options + private QueueObject queue1; + private MBeanServerConnection mbsc; + private ObjectName queue; + private int fmid = 0, tmid = 0; + + public Commandmove(JMXinfo info) + { + super(info); + + this.mbsc = info.getmbserverconnector(); + this.queue1 = new QueueObject(mbsc); + this.method1 = "moveMessages"; + this.method2 = "getMessagesOnTheQueue"; + + } + + public void movemessages() + { + Set set = null; + queue1.setQueryString(this.getObject(), this.name1, this.vhost1); + set = queue1.returnObjects(); + if (queue1.getSet().size() != 0) + { // find the queue + Iterator it = set.iterator(); + this.queue = (ObjectName) it.next(); + } + else + { + if (isname1() || isname2()) + { // if the specified queue is not there in the broker + + echo("The Queue you have specified is not in the current broker"); + echo(""); + } + else + { + printusage(); + } + } + try + { + Object[] params1 = { getfmid(), gettmid(), this.name2 }; + String[] signature1 = { new String("long"), new String("long"), new String("java.lang.String") }; + this.mbsc.invoke(this.queue, this.method1, params1, signature1); + + } + catch (Exception ex) + { + ex.printStackTrace(); + echo("Given messageId's might be wrong please run the view command and check messageId's you have given\n"); + echo("From MessageId should be greater than 0 and should less than To messageId"); + } + + } + + public void execute() + { + /* + * In here you it's easy to handle any number of otpions which are going + * to add with the list command which works with main option object or o + */ + + if (checkoptionsetting("object") || checkoptionsetting("o")) + { + String object = optionchecker("object"); + if (object == null) + { + object = optionchecker("o"); + } + if (object.compareToIgnoreCase("queue") == 0) + setObject(object); + else + { + unrecognizeoption(); + echo("This command is only applicable for queue command so please start with queue"); + } + if (checkoptionsetting("n2") && checkoptionsetting("n1")) + { + setname1(optionchecker("n1")); + setname2(optionchecker("n2")); + } + else + { + echo("You have to specify both n1 and n2 option value to move a message"); /* + * when + * user + * forget + * to + * specify + * target + * or + * starting + * queue + * name + */ + return; + } + + if (checkoptionsetting("v1")) + { + + setvhost1(optionchecker("v1")); + } + if (checkoptionsetting("tmid") && checkoptionsetting("fmid")) + { + String tmid = optionchecker("tmid"); + String fmid = optionchecker("fmid"); + + settomessageIdandfrommessageId(removeSpaces(tmid), removeSpaces(fmid)); + } + else + { + echo("You have to set from MessageId and to MessageId in order to move messages between queues"); + echo("To view MessageId's use <view> command with -n and -v options"); + return; + } + this.movemessages(); + + } + else if (checkoptionsetting("h") || checkoptionsetting("help")) + printusage(); + else + unrecognizeoption(); + } + + public void printusage() + { + echo(""); + echo("Usage:move [OPTION] ... [OBJECT TYPE]...\n"); + echo("Move the top most messages from the given queue object to the given destination object\n"); + echo("To specify the desired queues you have to give the virtualhost name and the queue name with following commands\n"); + echo("Where possible options include:\n"); + echo(" -v1 Give the virtuallhost name from which queue you want to move messages"); + echo(" -n1 Give the queue name which you want to move messages from"); + echo(" -n2 Give the queue name of the destination queue"); + echo(" -tmid Give From MessageId you want to move from the Queue"); + echo(" -fmid Give To MessageId you want to move from the Queue"); + echo(" -h --help Display the help and back to the qpid-cli prompt\n"); + + } + + private void setname1(String name) + { + this.name1 = name; + } + + private void setname2(String name) + { + this.name2 = name; + } + + private boolean isname1() + { + if (this.name1 == null) + return false; + + else + return true; + } + + private boolean isname2() + { + if (this.name2 == null) + return false; + + else + return true; + } + + private void setvhost1(String vhost) + { + this.vhost1 = vhost; + } + + private static String removeSpaces(String s) + { + StringTokenizer st = new StringTokenizer(s, " ", false); + String t = ""; + while (st.hasMoreElements()) + t += st.nextElement(); + return t; + } + + private void settomessageIdandfrommessageId(String tmid, String fmid) + { + Integer i = new Integer(tmid); + Integer j = new Integer(fmid); + this.tmid = i.intValue(); + this.fmid = j.intValue(); + } + + public int gettmid() + { + return this.tmid; + } + + public int getfmid() + { + return this.fmid; + } + + public String getname1() + { + return this.name1; + } + + public String getname2() + { + return this.name2; + } + +} diff --git a/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/Commandset.java b/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/Commandset.java new file mode 100644 index 0000000000..e70b7b17ad --- /dev/null +++ b/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/Commandset.java @@ -0,0 +1,260 @@ +/* + * + * 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.qpid.commands; + +import org.apache.qpid.commands.objects.ObjectNames; +import org.apache.qpid.commands.objects.QueueObject; +import org.apache.qpid.utils.JMXinfo; + +import javax.management.Attribute; +import javax.management.MBeanServerConnection; +import javax.management.ObjectName; +import java.util.Set; + +public class Commandset extends CommandImpl +{ + private String _attributeName; + private String _value; + public static final String COMMAND_NAME = "set"; + + public Commandset(JMXinfo info) + { + super(info); + } + + private void setAttribute(String option_value) + { + /* + * print usage if use is not give the correct option letter or no + * options + */ + if (option_value == null) + { + printusage(); + return; + } + MBeanServerConnection mbsc = info.getmbserverconnector(); + Set set = null; + ObjectNames objname = null; + + try + { + if (option_value.compareToIgnoreCase("queue") == 0 || option_value.compareToIgnoreCase("queues") == 0) + { + objname = new QueueObject(mbsc); + } + else + { + printusage(); + echo("Wrong objectName"); + return; + } + + if (_attributeName == null) + { + echo("attribute name not specified. See --help for details"); + return; + } + + if (_value == null) + { + echo("new value not specified. See --help for details"); + return; + } + + objname.setQueryString(this.getObject(), this.getName(), this.getVirtualhost()); + objname.returnObjects(); + + if (objname.getSet().size() != 1) + { + echo("Your query returned more than one object to set was this intended?" + objname.getQueryString()); + } + else if (objname.getSet().size() == 1) + { + ObjectName object = (ObjectName) objname.getSet().iterator().next(); + + Object value = objname.getAttribute(object, _attributeName); + + Object attributeValue = _value; + + try + { + if (value instanceof Integer) + { + attributeValue = Integer.valueOf(_value); + } + else if (value instanceof Long) + { + attributeValue = Long.valueOf(_value); + } + } + catch (NumberFormatException nfe) + { + echo("Value(" + _attributeName + ") should be of type " + value.getClass().getName()); + return; + } + + Attribute attribute = new Attribute(_attributeName, attributeValue); + + objname.setAttribute(object, attribute); + } + else + { + if (hasName()) + { + + echo("You might be querying wrong " + this.getObject() + " name with --name or -n option "); + echo(""); + echo("No " + this.getObject() + "Type Objects might not in the broker currently"); + echo(""); + } + else + { + printusage(); + } + } + + } + catch (Exception ex) + { + ex.printStackTrace(); + } + + } + + public void execute() + { + /* + * In here you it's easy to handle any number of otpions which are going + * to add with the list command which works with main option object or o + */ + if (checkoptionsetting("output")) + { + setOutputFormat(optionchecker("output")); + if (checkoptionsetting("separator")) + { + setSeperator(optionchecker("separator")); + } + } + if (checkoptionsetting("object") || checkoptionsetting("o")) + { + String object = optionchecker("object"); + if (object == null) + { + object = optionchecker("o"); + } + setObject(object); + + if (checkoptionsetting("name") || checkoptionsetting("n")) + { + String name = optionchecker("name"); + if (name == null) + { + name = optionchecker("n"); + } + + setName(name); + } + + if (checkoptionsetting("attribute") || checkoptionsetting("a")) + { + String name = optionchecker("attribute"); + if (name == null) + { + name = optionchecker("a"); + } + + setAttributeName(name); + } + + if (checkoptionsetting("set") || checkoptionsetting("s")) + { + String value = optionchecker("set"); + if (value == null) + { + value = optionchecker("s"); + } + + setAttributeValue(value); + } + + if (checkoptionsetting("virtualhost") || checkoptionsetting("v")) + { + String vhost = optionchecker("virtualhost"); + if (vhost == null) + { + vhost = optionchecker("v"); + } + setVirtualhost(vhost); + } + setAttribute(this.getObject()); + } + else if (checkoptionsetting("h") || checkoptionsetting("help")) + { + printusage(); + } + else + { + unrecognizeoption(); + } + } + + private void setAttributeValue(String value) + { + _value = value; + } + + private void setAttributeName(String name) + { + this._attributeName = name; + } + + public void printusage() + { + echo(""); + echo("Usage:set [OPTION] ... [OBJECT TYPE]...\n"); + echo("List the information about the given object\n"); + echo("Where possible options include:\n"); + echo(" -o --object type of objects which you want to list\n"); + echo(" ex: < list -o queue > : lists all the queues created in the java broker\n"); + echo(" For now list command is supporting following object typse \n"); + echo(" Queue Connection VirtualHost UserMangement Exchange"); + echo(" Or You can specify object type by giving it at the beginning"); + echo(" rather giving it as a argument"); + echo(" Ex:< queue list > this command is equal to list -o queue \n"); + echo(" -v --virtualhost After specifying the object type you can filter output with this option"); + echo(" list objects with the given virtualhost which will help to find "); + echo(" identical queue objects with -n option"); + echo(" ex: queue list -v develop ment"); + echo(" -n --name After specifying what type of objects you want to monitor you can filter"); + echo(" the output using -n option by specifying the name of the object you want "); + echo(" to monitor exactly"); + echo(" ex: <list -o queue -n ping> : list all the queue objects having queue name"); + echo(" of ping"); + echo(" ex: <queue list -n ping -v development> list all the queue objects with name "); + echo(" of ping and virtualhost of developement \n"); + echo(" -a --attribute "); + echo(" -h --help Display the help and back to the qpid-cli prompt\n"); + + } + +} diff --git a/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/Commandview.java b/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/Commandview.java new file mode 100644 index 0000000000..e3bcc7e543 --- /dev/null +++ b/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/Commandview.java @@ -0,0 +1,255 @@ +/* + * + * 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.qpid.commands; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.StringTokenizer; + +import javax.management.MBeanServerConnection; +import javax.management.ObjectName; +import javax.management.openmbean.CompositeData; +import javax.management.openmbean.TabularDataSupport; + +import org.apache.qpid.commands.objects.QueueObject; +import org.apache.qpid.utils.JMXinfo; + +public class Commandview extends CommandImpl +{ + + public static final String COMMAND_NAME = "view"; + + private int number = 0; + private QueueObject objname; + private MBeanServerConnection mbsc; + private String method1; + private ObjectName queue; + + public Commandview(JMXinfo info) + { + super(info); + this.mbsc = info.getmbserverconnector(); + this.objname = new QueueObject(mbsc); + this.method1 = "viewMessages"; + + } + + public void viewmessages() + { + objname.setQueryString(this.getObject(), this.getName(), this.getVirtualhost()); + Set set = objname.returnObjects(); + String header = "", temp_header = "", message_data = "", outline = ""; + + if (objname.getSet().size() != 0) + { + Iterator it = set.iterator(); + this.queue = (ObjectName) it.next(); + try + { + if (objname.getmessagecount(this.queue) == 0) + { + echo("Selected Queue doesn't contain any messages"); + return; + } + if (this.number == 0) + this.number = objname.getmessagecount(this.queue); + + if (objname.getmessagecount(this.queue) < this.number) + { + echo("Given number is Greater than the Queue Depth"); + return; + } + else + { + Object[] params = { 1, this.number }; + String[] signature = { new String("int"), new String("int") }; + TabularDataSupport data = (TabularDataSupport) this.mbsc.invoke(queue, this.method1, params, + signature); + + Set entrySet = data.entrySet(); + ArrayList<Map.Entry> list = new ArrayList<Map.Entry>(entrySet); + if (list.size() != 0) + {// no data} + for (int i = 0; i < list.size(); i++) + { + CompositeData compositedata = (CompositeData) (list.get(i)).getValue(); + List<String> itemNames = new ArrayList<String>(compositedata.getCompositeType().keySet()); + if (i == 0) // display the table headers + { + for (int j = 0; j < itemNames.size(); j++) + { + temp_header = ""; + if (j != 1) // skipping header information + { + temp_header = itemNames.get(j); + while (temp_header.length() < 15) + temp_header = " " + temp_header; + + header = header + temp_header + "|"; + } + else + continue; + } + echo(header); + while (outline.length() < header.length()) + outline = outline + "-"; + echo(outline); + } + + for (int j = 0; j < itemNames.size(); j++) + { + temp_header = ""; + if (j != 1) + { + temp_header = String.valueOf(compositedata.get(itemNames.get(j))); + while (temp_header.length() < 15) + temp_header = " " + temp_header; + message_data = message_data + temp_header + "|"; + } + else + // header information is not displaying + // unless user specify header information is + // needed + continue; + + } + echo(message_data); + header = ""; + message_data = ""; + } + } + else + { + System.out.println("No Data to Display"); + } + } + } + catch (Exception ex) + { + ex.printStackTrace(); + } + + } + else + { + if (hasName()) + { + + echo("The Queue you have specified is not in the current broker"); + echo(""); + } + else + { + printusage(); + } + } + } + + public void execute() + { + /* + * In here you it's easy to handle any number of otpions which are going + * to add with the list command which works with main option object or o + */ + + if (checkoptionsetting("object") || checkoptionsetting("o")) + { + String object = optionchecker("object"); + if (object == null) + { + object = optionchecker("o"); + } + if (object.compareToIgnoreCase("queue") == 0) + setObject(object); + else + { + unrecognizeoption(); + echo("This command is only applicable for delete command so please start with queue"); + } + if (checkoptionsetting("name") || checkoptionsetting("n")) + { + String name = optionchecker("name"); + if (name == null) + name = optionchecker("n"); + + setName(name); + } + if (checkoptionsetting("virtualhost") || checkoptionsetting("v")) + { + String vhost = optionchecker("virtualhost"); + if (vhost == null) + vhost = optionchecker("v"); + setVirtualhost(vhost); + } + if (checkoptionsetting("top") || checkoptionsetting("t")) + { + String number = optionchecker("top"); + if (number == null) + number = optionchecker("t"); + + setnumber(removeSpaces(number)); + } + this.viewmessages(); + } + else if (checkoptionsetting("h") || checkoptionsetting("help")) + printusage(); + else + unrecognizeoption(); + } + + public void printusage() + { + echo(""); + echo("Usage:view [OPTION] ... [OBJECT TYPE]...\n"); + echo("view the information about given number of messages from the given queue object\n"); + echo("To specify the desired queue you have to give the virtualhost name and the queue name with following commands\n"); + echo("Where possible options include:\n"); + echo(" -v --virtualhost Give the virtuallhost name of the desired queue"); + echo(" -n --name Give the queue name of the desired queue you want to view messages"); + echo(" -t --top Give how many number of messages you want to delete from the top (Default = all the messages will be deleted"); + echo(" -h --help Display the help and back to the qpid-cli prompt\n"); + + } + + private void setnumber(String number) + { + Integer i = new Integer(number); + this.number = i.intValue(); + } + + private static String removeSpaces(String s) + { + StringTokenizer st = new StringTokenizer(s, " ", false); + String t = ""; + while (st.hasMoreElements()) + t += st.nextElement(); + return t; + } + + public int getnumber() + { + return number; + } +} diff --git a/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/Commandviewcontent.java b/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/Commandviewcontent.java new file mode 100644 index 0000000000..d1ae1c1893 --- /dev/null +++ b/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/Commandviewcontent.java @@ -0,0 +1,248 @@ +/* + * + * 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.qpid.commands; + +import java.nio.charset.Charset; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Set; +import java.util.StringTokenizer; + +import javax.management.MBeanServerConnection; +import javax.management.ObjectName; +import javax.management.openmbean.CompositeData; + +import org.apache.qpid.commands.objects.QueueObject; +import org.apache.qpid.utils.JMXinfo; + +public class Commandviewcontent extends CommandImpl +{ + + public static final String COMMAND_NAME = "viewcontent"; + + private long number = 0; + private QueueObject objname; + private MBeanServerConnection mbsc; + private String method1; + private ObjectName queue; + + public Commandviewcontent(JMXinfo info) + { + super(info); + this.mbsc = info.getmbserverconnector(); + this.objname = new QueueObject(mbsc); + this.method1 = "viewMessageContent"; + + } + + public void viewcontent() + { + objname.setQueryString(getObject(), getName(), getVirtualhost()); + Set set = objname.returnObjects(); + String temp_header = "", header = "", message_data = "", encoding = null; + + if (objname.getSet().size() != 0) + { + Iterator it = set.iterator(); + this.queue = (ObjectName) it.next(); + try + { + if (objname.getmessagecount(this.queue) == 0) + { + echo("Selected Queue doesn't contain any messages"); + return; + } + if (this.number == 0) + { + echo("You haven't selected a MessageId Please use -id and give a message id"); + echo("Or run view command with same arguemnts to view messageId list for the queue"); + } + else + { + Object[] params = { this.number }; + String[] signature = { new String("long") }; + CompositeData data = (CompositeData) this.mbsc.invoke(queue, this.method1, params, signature); + List<String> itemNames = new ArrayList<String>(data.getCompositeType().keySet()); + for (int j = 0; j < itemNames.size(); j++) + { + temp_header = ""; + temp_header = itemNames.get(j); + while (temp_header.length() < 15) + temp_header = " " + temp_header; + + header = header + temp_header + "|"; + } + echo(header); + encoding = String.valueOf(data.get(itemNames.get(2))); // set + // the + // encoding + // at + // the + // beginning + // because + // encoding + // comes + // later + // in + // the + // loop + if (encoding == null || encoding.length() == 0) + { + encoding = Charset.defaultCharset().name(); + + } + for (int j = 0; j < itemNames.size(); j++) + { + temp_header = ""; + if (j != 1) + { + temp_header = String.valueOf(data.get(itemNames.get(j))); + while (temp_header.length() < 15) + temp_header = " " + temp_header; + } + else + { + Byte[] arrayItems = (Byte[]) data.get(itemNames.get(j)); + byte[] byteArray = new byte[arrayItems.length]; + for (int i = 0; i < arrayItems.length; i++) + { + byteArray[i] = arrayItems[i]; + temp_header = new String(byteArray, encoding); + while (temp_header.length() < 15) + temp_header = " " + temp_header; + } + } + message_data = message_data + temp_header + "|"; + + } + echo(message_data); + } + } + catch (Exception ex) + { + echo("Given MessageId is invalid, There's no message with the given messageId"); + ex.printStackTrace(); + return; + } + + } + else + { + if (hasName()) + { + + echo("The Queue you have specified is not in the current broker"); + echo(""); + } + else + { + printusage(); + } + } + } + + public void execute() + { + /* + * In here you it's easy to handle any number of otpions which are going + * to add with the list command which works with main option object or o + */ + + if (checkoptionsetting("object") || checkoptionsetting("o")) + { + String object = optionchecker("object"); + if (object == null) + { + object = optionchecker("o"); + } + if (object.compareToIgnoreCase("queue") == 0) + setObject(object); + else + { + unrecognizeoption(); + echo("This command is only applicable for delete command so please start with queue"); + } + if (checkoptionsetting("name") || checkoptionsetting("n")) + { + String name = optionchecker("name"); + if (name == null) + name = optionchecker("n"); + + setName(name); + } + if (checkoptionsetting("virtualhost") || checkoptionsetting("v")) + { + String vhost = optionchecker("virtualhost"); + if (vhost == null) + vhost = optionchecker("v"); + setVirtualhost(vhost); + } + if (checkoptionsetting("messageid") || checkoptionsetting("id")) + { + String number = optionchecker("id"); + if (number == null) + number = optionchecker("id"); + + setnumber(removeSpaces(number)); + } + this.viewcontent(); + } + else if (checkoptionsetting("h") || checkoptionsetting("help")) + printusage(); + else + unrecognizeoption(); + } + + public void printusage() + { + echo(""); + echo("Usage:viewcontent [OPTION] ... [OBJECT TYPE]...\n"); + echo("view the information about given number of messages from the given queue object\n"); + echo("To specify the desired queue you have to give the virtualhost name and the queue name with following commands\n"); + echo("Where possible options include:\n"); + echo(" -v --virtualhost Give the virtuallhost name of the desired queue"); + echo(" -n --name Give the queue name of the desired queue you want to view messages"); + echo(" -id Give the messageId of the required message you want to view the content"); + echo(" -h --help Display the help and back to the qpid-cli prompt\n"); + + } + + private void setnumber(String number) + { + this.number = Long.valueOf(number); + } + + private static String removeSpaces(String s) + { + StringTokenizer st = new StringTokenizer(s, " ", false); + String t = ""; + while (st.hasMoreElements()) + t += st.nextElement(); + return t; + } + + public long getnumber() + { + return this.number; + } + +} diff --git a/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/objects/AllObjects.java b/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/objects/AllObjects.java new file mode 100644 index 0000000000..8b2099f3e0 --- /dev/null +++ b/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/objects/AllObjects.java @@ -0,0 +1,38 @@ +/* + * + * 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.qpid.commands.objects; + +import javax.management.MBeanServerConnection; + +public class AllObjects extends ObjectNames +{ + + public AllObjects(MBeanServerConnection mbsc) + { + super(mbsc); + } + + public void setQueryString(String object, String name) + { + querystring = "org.apache.qpid:*"; + } +} diff --git a/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/objects/ConnectionObject.java b/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/objects/ConnectionObject.java new file mode 100644 index 0000000000..2746b2016f --- /dev/null +++ b/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/objects/ConnectionObject.java @@ -0,0 +1,46 @@ +/* + * + * 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.qpid.commands.objects; + +import javax.management.MBeanServerConnection; + +public class ConnectionObject extends ObjectNames +{ + public ConnectionObject(MBeanServerConnection mbsc) + { + /* calling parent classes constructor */ + super(mbsc); + } + + public void setQueryString(String object, String name, String vhost) + { + if (name != null && vhost == null) + querystring = "org.apache.qpid:type=Connection,name=" + name + ",*"; + else if (name != null && vhost != null) + querystring = "org.apache.qpid:type=Connection,VirtualHost=" + vhost + ",name=" + name + ",*"; + else if (name == null && vhost != null) + querystring = "org.apache.qpid:type=Connection,VirtualHost=" + vhost + ",*"; + else + querystring = "org.apache.qpid:type=Connection,*"; + + } +} diff --git a/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/objects/ExchangeObject.java b/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/objects/ExchangeObject.java new file mode 100644 index 0000000000..96d7e6e5dc --- /dev/null +++ b/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/objects/ExchangeObject.java @@ -0,0 +1,45 @@ +/* + * + * 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.qpid.commands.objects; + +import javax.management.MBeanServerConnection; + +public class ExchangeObject extends ObjectNames +{ + public ExchangeObject(MBeanServerConnection mbsc) + { + super(mbsc); + } + + public void setQueryString(String object, String name, String vhost) + { + if (name != null && vhost == null) + querystring = "org.apache.qpid:type=VirtualHost.Exchange,name=" + name + ",*"; + else if (name != null && vhost != null) + querystring = "org.apache.qpid:type=VirtualHost.Exchange,VirtualHost=" + vhost + ",name=" + name + ",*"; + else if (name == null && vhost != null) + querystring = "org.apache.qpid:type=VirtualHost.Exchange,VirtualHost=" + vhost + ",*"; + else + querystring = "org.apache.qpid:type=VirtualHost.Exchange,*"; + + } +} diff --git a/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/objects/ObjectNames.java b/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/objects/ObjectNames.java new file mode 100644 index 0000000000..1432f18018 --- /dev/null +++ b/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/objects/ObjectNames.java @@ -0,0 +1,591 @@ +/* + * + * 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.qpid.commands.objects; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import javax.management.Attribute; +import javax.management.MBeanAttributeInfo; +import javax.management.MBeanInfo; +import javax.management.MBeanServerConnection; +import javax.management.ObjectName; + +import org.apache.qpid.management.common.mbeans.ManagedQueue; + +public class ObjectNames +{ + public String querystring = null; + public MBeanServerConnection mbsc; + public Set<ObjectName> set = null; + public String attributes = ""; + public String attributevalues = "";// = null; + + private static final Map<String,Integer> QUEUE_ATTRIBUTES = new HashMap<String,Integer>(); + static + { + QUEUE_ATTRIBUTES.put(ManagedQueue.ATTR_NAME, 1); + QUEUE_ATTRIBUTES.put(ManagedQueue.ATTR_DURABLE, 2); + QUEUE_ATTRIBUTES.put(ManagedQueue.ATTR_ACTIVE_CONSUMER_COUNT, 3); + QUEUE_ATTRIBUTES.put(ManagedQueue.ATTR_MSG_COUNT, 4); + QUEUE_ATTRIBUTES.put(ManagedQueue.ATTR_RCVD_MSG_COUNT, 5); + } + + public ObjectNames(MBeanServerConnection mbsc) + { + this.mbsc = mbsc; + } + + public Set<ObjectName> returnObjects() + { + try + { + set = mbsc.queryNames(new ObjectName(querystring), null); + } + catch (Exception ex) + { + ex.printStackTrace(); + } + return set; + } + + public void echo(String str) + { + System.out.println(str); + } + + /* display appropriate objects according to the ojbect type */ + + public void displayobjects(String output, String seperator) + { + Iterator it = set.iterator(); + String line = ""; + String temp2 = ""; + int iterator = 0; + try + { + do + { + ObjectName temp_object = null; + if (it.hasNext()) + { + temp_object = (ObjectName) it.next(); + if (temp_object == null) + System.out.println("null test"); + } + // echo(temp_object.getCanonicalKeyPropertyListString()); + MBeanInfo bean_info = mbsc.getMBeanInfo(temp_object); + MBeanAttributeInfo[] attr_info = bean_info.getAttributes(); + if (attr_info == null) + { + echo(temp_object.toString()); + String temp = ""; + while (temp_object.toString().length() > temp.length()) + temp = "=" + temp; + if (output == null) + echo(temp); + + } + else + { + for (MBeanAttributeInfo attr : attr_info) + { + Object toWrite = null; + + try + { + String temp1 = attr.getName(); + if (output == null) + { + while (temp1.length() < 15) + temp1 = " " + temp1; + attributes = attributes + temp1 + "|"; + } + else if (output.compareToIgnoreCase("csv") == 0) + attributes = attributes + temp1 + seperator; + else + { + echo("Wrong output format current version is supporting only for CSV"); + return; + } + } + catch (Exception x) + { + x.printStackTrace(); + } + } + if (attributes.equalsIgnoreCase("")) + { + echo(temp_object.toString()); + String temp = ""; + while (temp_object.toString().length() > temp.length()) + temp = "=" + temp; + echo(temp); + echo("There are no attributes for this object Type"); + continue; + } + for (MBeanAttributeInfo attr : attr_info) + { + Object toWrite = null; + temp2 = null; + try + { + toWrite = mbsc.getAttribute(temp_object, attr.getName()); + } + catch (Exception x) + { + temp2 = "-"; + } + if (toWrite != null) + temp2 = toWrite.toString(); + else + temp2 = "-"; + if (output == null) + { + + while (temp2.length() < 15) + temp2 = " " + temp2; + + attributevalues = attributevalues + temp2 + "|"; + } + else if (output.compareToIgnoreCase("csv") == 0) + attributevalues = attributevalues + temp2 + seperator; + + // echo(temp1 + " " + temp2 + " " + temp3); + + } + } + iterator++; + if (iterator == 1) + { + echo(attributes); + for (int i = 0; i < attributes.length(); i++) + line = line + "-"; + if (output == null) + echo(line); + } + echo(attributevalues); + line = ""; + attributes = ""; + attributevalues = ""; + } while (it.hasNext()); + } + catch (Exception ex) + { + ex.printStackTrace(); + } + + } + + public void reportgenerator(String output, String seperator, List<String> column) + { + Iterator it = set.iterator(); + String line = ""; + String temp2 = ""; + int iterator = 0; + try + { + do + { + ObjectName temp_object = null; + if (it.hasNext()) + { + temp_object = (ObjectName) it.next(); + if (temp_object == null) + System.out.println("null test"); + } + // echo(temp_object.getCanonicalKeyPropertyListString()); + MBeanInfo bean_info = mbsc.getMBeanInfo(temp_object); + MBeanAttributeInfo[] attr_info = bean_info.getAttributes(); + if (attr_info == null) + { + echo(temp_object.toString()); + String temp = ""; + while (temp_object.toString().length() > temp.length()) + temp = "=" + temp; + if (output == null) + echo(temp); + + } + else + { + for (MBeanAttributeInfo attr : attr_info) + { + Object toWrite = null; + + try + { + String temp1 = attr.getName(); + if (column.contains(temp1)) + { + if (output == null) + { + while (temp1.length() < 15) + temp1 = " " + temp1; + attributes = attributes + temp1 + "|"; + } + else if (output.compareToIgnoreCase("csv") == 0) + attributes = attributes + temp1 + seperator; + else + { + echo("Wrong output format current version is supporting only for CSV"); + return; + } + } + } + catch (Exception x) + { + x.printStackTrace(); + } + } + if (attributes.equalsIgnoreCase("")) + { + echo(temp_object.toString()); + String temp = ""; + while (temp_object.toString().length() > temp.length()) + temp = "=" + temp; + echo(temp); + echo("There are no attributes for this object Type"); + return; + } + for (MBeanAttributeInfo attr : attr_info) + { + Object toWrite = null; + temp2 = null; + if (column.contains(attr.getName())) + { + try + { + toWrite = mbsc.getAttribute(temp_object, attr.getName()); + } + catch (Exception x) + { + temp2 = "-"; + } + if (toWrite != null) + temp2 = toWrite.toString(); + else + temp2 = "-"; + if (output == null) + { + + while (temp2.length() < 15) + temp2 = " " + temp2; + + attributevalues = attributevalues + temp2 + "|"; + } + else if (output.compareToIgnoreCase("csv") == 0) + attributevalues = attributevalues + temp2 + seperator; + + // echo(temp1 + " " + temp2 + " " + temp3); + + } + + } + } + iterator++; + if (iterator == 1) + { + echo(attributes); + for (int i = 0; i < attributes.length(); i++) + line = line + "-"; + if (output == null) + echo(line); + } + echo(attributevalues); + line = ""; + attributes = ""; + attributevalues = ""; + } while (it.hasNext()); + } + catch (Exception ex) + { + ex.printStackTrace(); + } + + } + + public void displayqueues(String output, String seperator) + { + Iterator it = set.iterator(); + String line = ""; + int iterator = 0; + String temp1 = ""; + String temp2 = ""; + try + { + do + { + ObjectName temp_object = null; + if (it.hasNext()) + { + temp_object = (ObjectName) it.next(); + } + // echo(temp_object.getCanonicalKeyPropertyListString()); + MBeanInfo bean_info = mbsc.getMBeanInfo(temp_object); + MBeanAttributeInfo[] attr_info = bean_info.getAttributes(); + if (attr_info == null) + { + echo(temp_object.toString()); + String temp = ""; + while (temp_object.toString().length() > temp.length()) + temp = "=" + temp; + if (output == null) + echo(temp); + + } + else + { + for (MBeanAttributeInfo attr : attr_info) + { + Object toWrite = null; + Integer attr_count = QUEUE_ATTRIBUTES.get(attr.getName()); + + if(attr_count == null) + { + continue; + } + + try + { + toWrite = mbsc.getAttribute(temp_object, attr.getName()); + if (output == null) + { + switch (attr_count) + { + case 1: + case 2: + temp1 = attr.getName(); + while (temp1.length() < 10) + temp1 = " " + temp1; + attributes = attributes + temp1 + "|"; + temp2 = toWrite.toString(); + while (temp2.length() < 10) + temp2 = " " + temp2; + attributevalues = attributevalues + temp2 + "|"; + break; + case 3: + temp1 = attr.getName(); + while (temp1.length() < 20) + temp1 = " " + temp1; + attributes = attributes + temp1 + "|"; + temp2 = toWrite.toString(); + while (temp2.length() < 20) + temp2 = " " + temp2; + attributevalues = attributevalues + temp2 + "|"; + break; + case 4: + temp1 = attr.getName(); + while (temp1.length() < 13) + temp1 = " " + temp1; + attributes = attributes + temp1 + "|"; + temp2 = toWrite.toString(); + while (temp2.length() < 13) + temp2 = " " + temp2; + attributevalues = attributevalues + temp2 + "|"; + break; + case 5: + temp1 = attr.getName(); + while (temp1.length() < 20) + temp1 = " " + temp1; + attributes = attributes + temp1 + "|"; + temp2 = toWrite.toString(); + while (temp2.length() < 20) + temp2 = " " + temp2; + attributevalues = attributevalues + temp2 + "|"; + break; + } + } + else if (output.compareToIgnoreCase("csv") == 0) + { + temp1 = attr.getName(); + attributes = attributes + temp1 + seperator; + temp2 = toWrite.toString(); + attributevalues = attributevalues + temp2 + seperator; + } + else + { + echo("Wrong output format specified currently CLI supports only csv output format"); + return; + } + + } + catch (Exception x) + { + x.printStackTrace(); + } + + } + } + iterator++; + if (iterator == 1) + { + for (int i = 0; i < attributes.length(); i++) + line = line + "-"; + if (output == null) + echo(line); + echo(attributes); + if (output == null) + echo(line); + } + echo(attributevalues); + line = ""; + attributes = ""; + attributevalues = ""; + } while (it.hasNext()); + } + catch (Exception ex) + { + ex.printStackTrace(); + } + } + + public void displayinfo(String output, String seperator) + { + Iterator it = set.iterator(); + String temp1, temp2 = ""; + try + { + do + { + + ObjectName temp_object = null; + if (it.hasNext()) + { + temp_object = (ObjectName) it.next(); + } + // echo(temp_object.getCanonicalKeyPropertyListString()); + MBeanInfo bean_info = mbsc.getMBeanInfo(temp_object); + MBeanAttributeInfo[] attr_info = bean_info.getAttributes(); + if (attr_info == null) + { + echo(temp_object.toString()); + String temp = ""; + while (temp_object.toString().length() > temp.length()) + temp = "=" + temp; + echo(temp); + + } + else + { + echo(temp_object.toString()); + String temp = ""; + while (temp_object.toString().length() > temp.length()) + temp = "=" + temp; + echo(temp); + + for (MBeanAttributeInfo attr : attr_info) + { + Object toWrite = null; + + try + { + toWrite = mbsc.getAttribute(temp_object, attr.getName()); + } + catch (Exception x) + { + temp2 = "-"; + } + temp1 = attr.getName(); + if (toWrite != null) + temp2 = toWrite.toString(); + + if (output == null) + { + while (temp1.length() < 35) + temp1 = " " + temp1; + + while (temp2.length() < 35) + temp2 = " " + temp2; + echo(temp1 + " " + temp2); + } + else if (output.compareToIgnoreCase("csv") == 0) + echo(temp1 + seperator + temp2); + else + { + echo("Wrong output format specified currently CLI supports only csv output format"); + return; + } + } + echo(""); + echo(""); + + } + } while (it.hasNext()); + } + catch (Exception ex) + { + ex.printStackTrace(); + } + + } + + public void setQueryString(String object, String name, String vhost) + { + + } + + public void setQueryStringforinfo(String object, String name, String virtualhost) + { + + } + + public String getQueryString() + { + return querystring; + } + + public Set getSet() + { + return set; + } + + public Object getAttribute(ObjectName object, String attribute) + { + try + { + return mbsc.getAttribute(object, attribute); + } + catch (Exception e) + { + e.printStackTrace(); + } + + return null; + } + + public void setAttribute(ObjectName object, Attribute attribute) + { + try + { + mbsc.setAttribute(object, attribute); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + +} diff --git a/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/objects/QueueObject.java b/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/objects/QueueObject.java new file mode 100644 index 0000000000..fcf0464ced --- /dev/null +++ b/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/objects/QueueObject.java @@ -0,0 +1,67 @@ +/* + * + * 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.qpid.commands.objects; + +import javax.management.MBeanServerConnection; +import javax.management.ObjectName; + +import org.apache.qpid.management.common.mbeans.ManagedQueue; + +public class QueueObject extends ObjectNames +{ + public QueueObject(MBeanServerConnection mbsc) + { + super(mbsc); + } + + public void setQueryString(String object, String name, String vhost) + { + if (name != null && vhost == null) + querystring = "org.apache.qpid:type=VirtualHost.Queue,name=" + name + ",*"; + else if (name != null && vhost != null) + querystring = "org.apache.qpid:type=VirtualHost.Queue,VirtualHost=" + vhost + ",name=" + name + ",*"; + else if (name == null && vhost != null) + querystring = "org.apache.qpid:type=VirtualHost.Queue,VirtualHost=" + vhost + ",*"; + else + querystring = "org.apache.qpid:type=VirtualHost.Queue,*"; + } + + public int getmessagecount(ObjectName queue) + { + Number depth = null; + + try + { + depth = (Number) mbsc.getAttribute(queue, ManagedQueue.ATTR_MSG_COUNT); + + } + catch (Exception ex) + { + ex.printStackTrace(); + } + if (depth != null) + return depth.intValue(); + else + return -1; + } + +} diff --git a/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/objects/UserManagementObject.java b/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/objects/UserManagementObject.java new file mode 100644 index 0000000000..fd5bc0ca72 --- /dev/null +++ b/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/objects/UserManagementObject.java @@ -0,0 +1,38 @@ +/* + * + * 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.qpid.commands.objects; + +import javax.management.MBeanServerConnection; + +public class UserManagementObject extends ObjectNames +{ + public UserManagementObject(MBeanServerConnection mbsc) + { + super(mbsc); + } + + public void setQueryString(String object, String name, String vhost) + { + querystring = "org.apache.qpid:type=UserManagement,*"; + } + +} diff --git a/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/objects/VirtualHostObject.java b/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/objects/VirtualHostObject.java new file mode 100644 index 0000000000..77f8b66ac0 --- /dev/null +++ b/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/objects/VirtualHostObject.java @@ -0,0 +1,47 @@ +/* + * + * 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.qpid.commands.objects; + +import javax.management.MBeanServerConnection; + +public class VirtualHostObject extends ObjectNames +{ + + public VirtualHostObject(MBeanServerConnection mbsc) + { + super(mbsc); + } + + public void setQueryString(String object, String name, String vhost) + { + if (name != null && vhost == null) + querystring = "org.apache.qpid:type=VirtualHost.VirtualHostManager,name=" + name + ",*"; + else if (name != null && vhost != null) + querystring = "org.apache.qpid:type=VirtualHost.VirtualHostManager,VirtualHost=" + vhost + ",name=" + name + + ",*"; + else if (name == null && vhost != null) + querystring = "org.apache.qpid:type=VirtualHost.VirtualHostManager,VirtualHost=" + vhost + ",*"; + else + querystring = "org.apache.qpid:type=VirtualHost.VirtualHostManager,*"; + + } +} |