use of org.apache.qpid.qmf2.common.QmfException in project qpid by apache.
the class Test4 method addObject.
public void addObject(QmfAgentData object) throws QmfException {
SchemaClassId classId = object.getSchemaClassId();
SchemaClass schema = _schemaCache.get(classId);
// Try to create an objectName using the set of property names that have been specified as idNames in the schema
StringBuilder buf = new StringBuilder();
if (schema != null && schema instanceof SchemaObjectClass) {
String[] idNames = ((SchemaObjectClass) schema).getIdNames();
for (String name : idNames) {
buf.append(object.getStringValue(name));
}
}
String objectName = buf.toString();
// If the schema hasn't given any help we use a UUID
if (objectName.length() == 0)
objectName = UUID.randomUUID().toString();
// Finish up the name by incorporating package and class names
objectName = classId.getPackageName() + ":" + classId.getClassName() + ":" + objectName;
// Now we've got a good name for the object we create it's ObjectId and add that to the object
ObjectId addr = new ObjectId("test", /*name*/
objectName, 0);
object.setObjectId(addr);
if (_objectIndex.get(addr) != null) {
throw new QmfException("Duplicate QmfAgentData Address");
}
_objectIndex.put(addr, object);
}
use of org.apache.qpid.qmf2.common.QmfException in project qpid by apache.
the class QpidConfig method addExchange.
/**
* Add an exchange using the QMF "create" method.
* @param args the exchange type is the first argument and the exchange name is the second argument.
* The remaining QMF method properties are populated form config parsed from the command line.
*/
private void addExchange(final String[] args) {
if (args.length < 2) {
usage();
}
Map<String, Object> properties = new HashMap<String, Object>();
if (_durable) {
properties.put("durable", true);
}
properties.put("exchange-type", args[0]);
if (_msgSequence) {
properties.put(MSG_SEQUENCE, 1l);
}
if (_ive) {
properties.put(IVE, 1l);
}
if (_altExchange != null) {
properties.put("alternate-exchange", _altExchange);
}
QmfData arguments = new QmfData();
arguments.setValue("type", "exchange");
arguments.setValue("name", args[1]);
arguments.setValue("properties", properties);
try {
_broker.invokeMethod("create", arguments);
} catch (QmfException e) {
System.out.println(e.getMessage());
}
// passive exchange 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 QpidConfig method unbind.
/**
* Remove a binding using the QMF "delete" 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 unbind(final String[] args) {
if (args.length < 2) {
usage();
}
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);
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 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());
}
}
Aggregations