use of org.apache.qpid.qmf2.console.QmfConsoleData in project qpid by apache.
the class QpidConfig method queueList.
/**
* For every queue list detailed info (equivalent of qpid-config queues).
*
* More or less a direct Java port of QueueList in qpid-config, which handles qpid-config queues.
*
* @param filter specifies the queue name to display info for, if set to "" displays info for every queue.
*/
private void queueList(final String filter) {
List<QmfConsoleData> queues = _console.getObjects("org.apache.qpid.broker", "queue");
String caption = "Queue Name";
int maxNameLen = caption.length();
for (QmfConsoleData queue : queues) {
String name = queue.getStringValue("name");
if (filter.equals("") || filter.equals(name)) {
if (name.length() > maxNameLen) {
maxNameLen = name.length();
}
}
}
System.out.printf("%-" + maxNameLen + "s Attributes\n", caption);
StringBuilder buf = new StringBuilder();
for (int i = 0; i < ((maxNameLen / 5) + 5); i++) {
buf.append("=====");
}
String line = buf.toString();
System.out.println(line);
for (QmfConsoleData queue : queues) {
String name = queue.getStringValue("name");
if (filter.equals("") || filter.equals(name)) {
System.out.printf("%-" + maxNameLen + "s ", name);
Map<String, Object> args = queue.<Map<String, Object>>getValue("arguments");
args = (args == null) ? Collections.EMPTY_MAP : args;
/*System.out.println(args);
for (Map.Entry<String, Object> entry : args.entrySet()) {
System.out.println(entry.getKey() + " " + entry.getValue().getClass().getCanonicalName());
}*/
if (queue.getBooleanValue("durable")) {
System.out.printf("--durable ");
}
if (queue.getBooleanValue("autoDelete")) {
System.out.printf("auto-del ");
}
if (queue.getBooleanValue("exclusive")) {
System.out.printf("excl ");
}
if (args.containsKey(FILESIZE)) {
System.out.printf("--file-size=%d ", QmfData.getLong(args.get(FILESIZE)));
}
if (args.containsKey(FILECOUNT)) {
System.out.printf("--file-count=%d ", QmfData.getLong(args.get(FILECOUNT)));
}
if (args.containsKey(MAX_QUEUE_SIZE)) {
System.out.printf("--max-queue-size=%d ", QmfData.getLong(args.get(MAX_QUEUE_SIZE)));
}
if (args.containsKey(MAX_QUEUE_COUNT)) {
System.out.printf("--max-queue-count=%d ", QmfData.getLong(args.get(MAX_QUEUE_COUNT)));
}
if (args.containsKey(POLICY_TYPE)) {
System.out.printf("--limit-policy=%s ", (QmfData.getString(args.get(POLICY_TYPE))).replace("_", "-"));
}
if (args.containsKey(LVQ) && QmfData.getLong(args.get(LVQ)) == 1) {
System.out.printf("--order lvq ");
}
if (args.containsKey(LVQNB) && QmfData.getLong(args.get(LVQNB)) == 1) {
System.out.printf("--order lvq-no-browse ");
}
if (queue.hasValue("altExchange")) {
ObjectId altExchangeRef = queue.getRefValue("altExchange");
List<QmfConsoleData> altExchanges = _console.getObjects(altExchangeRef);
if (altExchanges.size() == 1) {
QmfConsoleData altExchange = altExchanges.get(0);
System.out.printf("--alternate-exchange=%s", altExchange.getStringValue("name"));
}
}
if (args.containsKey(FLOW_STOP_SIZE)) {
System.out.printf("--flow-stop-size=%d ", QmfData.getLong(args.get(FLOW_STOP_SIZE)));
}
if (args.containsKey(FLOW_RESUME_SIZE)) {
System.out.printf("--flow-resume-size=%d ", QmfData.getLong(args.get(FLOW_RESUME_SIZE)));
}
if (args.containsKey(FLOW_STOP_COUNT)) {
System.out.printf("--flow-stop-count=%d ", QmfData.getLong(args.get(FLOW_STOP_COUNT)));
}
if (args.containsKey(FLOW_RESUME_COUNT)) {
System.out.printf("--flow-resume-count=%d ", QmfData.getLong(args.get(FLOW_RESUME_COUNT)));
}
for (Map.Entry<String, Object> entry : args.entrySet()) {
// Display generic queue arguments
if (!SPECIAL_ARGS.contains(entry.getKey())) {
System.out.printf("--argument %s=%s ", entry.getKey(), entry.getValue());
}
}
System.out.println();
}
}
}
use of org.apache.qpid.qmf2.console.QmfConsoleData in project qpid by apache.
the class QpidConfig method delQueue.
/**
* Remove a queue using the QMF "delete" method.
* @param args the queue name is the first argument.
* The remaining QMF method properties are populated form config parsed from the command line.
*/
private void delQueue(final String[] args) {
if (args.length < 1) {
usage();
}
if (_ifEmpty || _ifUnused) {
// Check the selected queue object to see if it is not empty or is in use
List<QmfConsoleData> queues = _console.getObjects("org.apache.qpid.broker", "queue");
for (QmfConsoleData queue : queues) {
ObjectId queueId = queue.getObjectId();
String name = queue.getStringValue("name");
if (name.equals(args[0])) {
long msgDepth = queue.getLongValue("msgDepth");
if (_ifEmpty == true && msgDepth > 0) {
System.out.println("Cannot delete queue " + name + "; queue not empty");
return;
}
long consumerCount = queue.getLongValue("consumerCount");
if (_ifUnused == true && consumerCount > 0) {
System.out.println("Cannot delete queue " + name + "; queue in use");
return;
}
}
}
}
QmfData arguments = new QmfData();
arguments.setValue("type", "queue");
arguments.setValue("name", args[0]);
try {
_broker.invokeMethod("delete", arguments);
} catch (QmfException e) {
System.out.println(e.getMessage());
}
}
use of org.apache.qpid.qmf2.console.QmfConsoleData in project qpid by apache.
the class QpidConfig method bind.
/**
* Add a binding using the QMF "create" method.
* @param args the exchange name is the first argument, the queue name is the second argument and the binding key
* is the third argument.
* The remaining QMF method properties are populated form config parsed from the command line.
*/
private void bind(final String[] args) {
if (args.length < 2) {
usage();
}
// Look up exchange objects to find the type of the selected exchange
String exchangeType = null;
List<QmfConsoleData> exchanges = _console.getObjects("org.apache.qpid.broker", "exchange");
for (QmfConsoleData exchange : exchanges) {
String name = exchange.getStringValue("name");
if (args[0].equals(name)) {
exchangeType = exchange.getStringValue("type");
break;
}
}
if (exchangeType == null) {
System.out.println("Exchange " + args[0] + " is invalid");
return;
}
Map<String, Object> properties = new HashMap<String, Object>();
if (exchangeType.equals("xml")) {
if (_file == null) {
System.out.println("Invalid args to bind xml: need an input file or stdin");
return;
}
String xquery = null;
if (_file.equals("-")) {
// Read xquery off stdin
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
try {
StringBuilder buf = new StringBuilder();
String line;
while (// read until eof
(line = in.readLine()) != null) {
buf.append(line + "\n");
}
xquery = buf.toString();
} catch (IOException ioe) {
System.out.println("Exception " + ioe + " while reading stdin");
return;
}
} else {
// Read xquery from input file
File file = new File(_file);
try {
FileInputStream fin = new FileInputStream(file);
try {
byte[] content = new byte[(int) file.length()];
fin.read(content);
xquery = new String(content);
} finally {
fin.close();
}
} catch (FileNotFoundException e) {
System.out.println("File " + _file + " not found");
return;
} catch (IOException ioe) {
System.out.println("Exception " + ioe + " while reading " + _file);
return;
}
}
properties.put("xquery", xquery);
} else if (exchangeType.equals("headers")) {
if (args.length < 5) {
System.out.println("Invalid args to bind headers: need 'any'/'all' plus conditions");
return;
}
String op = args[3];
if (op.equals("all") || op.equals("any")) {
properties.put("x-match", op);
String[] bindings = Arrays.copyOfRange(args, 4, args.length);
for (String binding : bindings) {
if (binding.contains("=")) {
binding = binding.split(",")[0];
String[] kv = binding.split("=");
properties.put(kv[0], kv[1]);
}
}
} else {
System.out.println("Invalid condition arg to bind headers, need 'any' or 'all', not '" + op + "'");
return;
}
}
String bindingIdentifier = args[0] + "/" + args[1];
if (args.length > 2) {
bindingIdentifier = bindingIdentifier + "/" + args[2];
}
QmfData arguments = new QmfData();
arguments.setValue("type", "binding");
arguments.setValue("name", bindingIdentifier);
arguments.setValue("properties", properties);
try {
_broker.invokeMethod("create", arguments);
} catch (QmfException e) {
System.out.println(e.getMessage());
}
}
use of org.apache.qpid.qmf2.console.QmfConsoleData in project qpid by apache.
the class QpidConfig method overview.
/**
* Provide a basic overview of the number and type of queues and exchanges.
*/
private void overview() {
List<QmfConsoleData> exchanges = _console.getObjects("org.apache.qpid.broker", "exchange");
List<QmfConsoleData> queues = _console.getObjects("org.apache.qpid.broker", "queue");
System.out.printf("Total Exchanges: %d\n", exchanges.size());
Map<String, AtomicInteger> etype = new HashMap<String, AtomicInteger>();
for (QmfConsoleData exchange : exchanges) {
String exchangeType = exchange.getStringValue("type");
AtomicInteger n = etype.get(exchangeType);
if (n == null) {
etype.put(exchangeType, new AtomicInteger(1));
} else {
n.getAndIncrement();
}
}
for (Map.Entry<String, AtomicInteger> entry : etype.entrySet()) {
System.out.printf("%15s: %s\n", entry.getKey(), entry.getValue());
}
System.out.println();
System.out.printf(" Total Queues: %d\n", queues.size());
int durable = 0;
for (QmfConsoleData queue : queues) {
boolean isDurable = queue.getBooleanValue("durable");
if (isDurable) {
durable++;
}
}
System.out.printf(" durable: %d\n", durable);
System.out.printf(" non-durable: %d\n", queues.size() - durable);
}
use of org.apache.qpid.qmf2.console.QmfConsoleData in project qpid by apache.
the class QpidConfig method exchangeListRecurse.
/**
* For every exchange list the bindings (equivalent of qpid-config -b exchanges).
*
* More or less a direct Java port of ExchangeListRecurse in qpid-config, which handles qpid-config -b exchanges.
*
* @param filter specifies the exchange name to display info for, if set to "" displays info for every exchange.
*/
private void exchangeListRecurse(final String filter) {
List<QmfConsoleData> exchanges = _console.getObjects("org.apache.qpid.broker", "exchange");
List<QmfConsoleData> bindings = _console.getObjects("org.apache.qpid.broker", "binding");
List<QmfConsoleData> queues = _console.getObjects("org.apache.qpid.broker", "queue");
for (QmfConsoleData exchange : exchanges) {
ObjectId exchangeId = exchange.getObjectId();
String name = exchange.getStringValue("name");
if (filter.equals("") || filter.equals(name)) {
System.out.printf("Exchange '%s' (%s)\n", name, exchange.getStringValue("type"));
for (QmfConsoleData binding : bindings) {
ObjectId exchangeRef = binding.getRefValue("exchangeRef");
if (exchangeRef.equals(exchangeId)) {
ObjectId queueRef = binding.getRefValue("queueRef");
QmfConsoleData queue = findById(queues, queueRef);
String queueName = "<unknown>";
if (queue != null) {
queueName = queue.getStringValue("name");
if (queueName.equals("")) {
queueName = "''";
}
}
String bindingKey = binding.getStringValue("bindingKey");
Map arguments = (Map) binding.getValue("arguments");
if (arguments == null || arguments.isEmpty()) {
System.out.printf(" bind [%s] => %s\n", bindingKey, queueName);
} else {
// If there are binding arguments then it's a headers exchange
System.out.printf(" bind [%s] => %s %s\n", bindingKey, queueName, arguments);
}
}
}
}
}
}
Aggregations