use of org.apache.qpid.qmf2.common.QmfException 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.common.QmfException 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.common.QmfException in project qpid by apache.
the class QpidConfig method delExchange.
/**
* Remove an exchange using the QMF "delete" method.
* @param args the exchange name is the first argument.
* The remaining QMF method properties are populated form config parsed from the command line.
*/
private void delExchange(final String[] args) {
if (args.length < 1) {
usage();
}
QmfData arguments = new QmfData();
arguments.setValue("type", "exchange");
arguments.setValue("name", args[0]);
try {
_broker.invokeMethod("delete", arguments);
} catch (QmfException e) {
System.out.println(e.getMessage());
}
}
use of org.apache.qpid.qmf2.common.QmfException in project qpid by apache.
the class QpidConfig method addQueue.
/**
* Add a queue using the QMF "create" 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 addQueue(final String[] args) {
if (args.length < 1) {
usage();
}
Map<String, Object> properties = new HashMap<String, Object>();
for (String a : extraArguments) {
String[] r = a.split("=");
String value = r.length == 2 ? r[1] : null;
properties.put(r[0], value);
}
if (_durable) {
properties.put("durable", true);
properties.put(FILECOUNT, _fileCount);
properties.put(FILESIZE, _fileSize);
}
if (_maxQueueSize > 0) {
properties.put(MAX_QUEUE_SIZE, _maxQueueSize);
}
if (_maxQueueCount > 0) {
properties.put(MAX_QUEUE_COUNT, _maxQueueCount);
}
if (_limitPolicy.equals("reject")) {
properties.put(POLICY_TYPE, "reject");
} else if (_limitPolicy.equals("flow-to-disk")) {
properties.put(POLICY_TYPE, "flow_to_disk");
} else if (_limitPolicy.equals("ring")) {
properties.put(POLICY_TYPE, "ring");
} else if (_limitPolicy.equals("ring-strict")) {
properties.put(POLICY_TYPE, "ring_strict");
}
if (_order.equals("lvq")) {
properties.put(LVQ, 1l);
} else if (_order.equals("lvq-no-browse")) {
properties.put(LVQNB, 1l);
}
if (_altExchange != null) {
properties.put("alternate-exchange", _altExchange);
}
if (_flowStopSize > 0) {
properties.put(FLOW_STOP_SIZE, _flowStopSize);
}
if (_flowResumeSize > 0) {
properties.put(FLOW_RESUME_SIZE, _flowResumeSize);
}
if (_flowStopCount > 0) {
properties.put(FLOW_STOP_COUNT, _flowStopCount);
}
if (_flowResumeCount > 0) {
properties.put(FLOW_RESUME_COUNT, _flowResumeCount);
}
QmfData arguments = new QmfData();
arguments.setValue("type", "queue");
arguments.setValue("name", args[0]);
arguments.setValue("properties", properties);
try {
_broker.invokeMethod("create", arguments);
} catch (QmfException e) {
System.out.println(e.getMessage());
}
// passive queue creation not implemented yet (not sure how to do it using QMF2)
}
use of org.apache.qpid.qmf2.common.QmfException in project qpid by apache.
the class AgentExternalTest method populateData.
public void populateData() throws QmfException {
System.out.println("*** AgentExternalTest creating a control object ***");
_control = new QmfAgentData(_controlSchema);
_control.setValue("state", "OPERATIONAL");
_control.setValue("methodCount", 0);
addObject(_control);
System.out.println("AgentExternalTest Schema control object added OK");
}
Aggregations