use of org.apache.qpid.qmf2.common.ObjectId in project qpid by apache.
the class ConnectionLogger method logQueueInformation.
/**
* For every queue list the bindings (equivalent of qpid-config -b queues)
*
* More or less a direct Java port of QueueListRecurse in qpid-config, which handles qpid-config -b queues
*
* @param ref If ref is null list info about all queues else list info about queue referenced by ObjectID
*/
private void logQueueInformation(final ObjectId ref) {
List<QmfConsoleData> queues = _console.getObjects("org.apache.qpid.broker", "queue");
List<QmfConsoleData> bindings = _console.getObjects("org.apache.qpid.broker", "binding");
List<QmfConsoleData> exchanges = _console.getObjects("org.apache.qpid.broker", "exchange");
for (QmfConsoleData queue : queues) {
ObjectId queueId = queue.getObjectId();
if (ref == null || ref.equals(queueId)) {
System.out.printf(" Queue '%s'\n", queue.getStringValue("name"));
System.out.println(" arguments " + (Map) queue.getValue("arguments"));
for (QmfConsoleData binding : bindings) {
ObjectId queueRef = binding.getRefValue("queueRef");
if (queueRef.equals(queueId)) {
ObjectId exchangeRef = binding.getRefValue("exchangeRef");
QmfConsoleData exchange = findById(exchanges, exchangeRef);
String exchangeName = "<unknown>";
if (exchange != null) {
exchangeName = exchange.getStringValue("name");
if (exchangeName.equals("")) {
exchangeName = "''";
}
}
String bindingKey = binding.getStringValue("bindingKey");
Map arguments = (Map) binding.getValue("arguments");
if (arguments.isEmpty()) {
System.out.printf(" bind [%s] => %s\n", bindingKey, exchangeName);
} else {
// If there are binding arguments then it's a headers exchange
System.out.printf(" bind [%s] => %s %s\n", bindingKey, exchangeName, arguments);
}
}
}
}
}
}
use of org.apache.qpid.qmf2.common.ObjectId 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.ObjectId in project qpid by apache.
the class Test4 method evaluateDataQuery.
public List<QmfConsoleData> evaluateDataQuery(QmfQuery query) {
List<QmfConsoleData> results = new ArrayList<QmfConsoleData>();
if (query.getObjectId() != null) {
// Look up a QmfAgentData object by the ObjectId obtained from the query
ObjectId objectId = query.getObjectId();
QmfAgentData object = _objectIndex.get(objectId);
if (object != null && !object.isDeleted()) {
results.add(new QmfConsoleData(object.mapEncode(), null));
}
} else {
for (QmfAgentData object : _objectIndex.values()) {
if (!object.isDeleted() && query.evaluate(object)) {
results.add(new QmfConsoleData(object.mapEncode(), null));
}
}
}
return results;
}
use of org.apache.qpid.qmf2.common.ObjectId in project qpid by apache.
the class ConnectionAudit method validateQueue.
/**
* Looks up the exchange and binding information from the supplied queuename then calls the main validateQueue()
* @param queueName the name of the queue that we want to check against the whitelists.
* @param address the connection address information for the subscription.
* @param timestamp the timestamp of the subscription.
*/
private void validateQueue(final String queueName, final String address, final String timestamp) {
ObjectId queueId = null;
List<QmfConsoleData> queues = _console.getObjects("org.apache.qpid.broker", "queue");
for (QmfConsoleData queue : queues) {
// We first have to find the ObjectId of the queue called queueName.
if (queue.getStringValue("name").equals(queueName)) {
queueId = queue.getObjectId();
break;
}
}
if (queueId == null) {
System.out.printf("%s ERROR ConnectionAudit.validateQueue() %s reference couldn't be found\n", new Date().toString(), queueName);
} else {
// If we've got the queue's ObjectId we then find the binding that references it.
List<QmfConsoleData> bindings = _console.getObjects("org.apache.qpid.broker", "binding");
for (QmfConsoleData binding : bindings) {
ObjectId queueRef = binding.getRefValue("queueRef");
if (queueRef.equals(queueId)) {
// We've found a binding that matches queue queueName so look up the associated exchange and validate.
QmfConsoleData exchange = dereference(binding.getRefValue("exchangeRef"));
String exchangeName = exchange.getStringValue("name");
validateQueue(queueName, exchangeName, binding, address, timestamp);
}
}
}
}
use of org.apache.qpid.qmf2.common.ObjectId in project qpid by apache.
the class QpidConfig method exchangeList.
/**
* For every exchange list detailed info (equivalent of qpid-config exchanges).
*
* More or less a direct Java port of ExchangeList in qpid-config, which handles qpid-config exchanges.
*
* @param filter specifies the exchange name to display info for, if set to "" displays info for every exchange.
*/
private void exchangeList(final String filter) {
List<QmfConsoleData> exchanges = _console.getObjects("org.apache.qpid.broker", "exchange");
String caption1 = "Type ";
String caption2 = "Exchange Name";
int maxNameLen = caption2.length();
for (QmfConsoleData exchange : exchanges) {
String name = exchange.getStringValue("name");
if (filter.equals("") || filter.equals(name)) {
if (name.length() > maxNameLen) {
maxNameLen = name.length();
}
}
}
System.out.printf("%s%-" + maxNameLen + "s Attributes\n", caption1, caption2);
StringBuilder buf = new StringBuilder();
for (int i = 0; i < (((maxNameLen + caption1.length()) / 5) + 5); i++) {
buf.append("=====");
}
String line = buf.toString();
System.out.println(line);
for (QmfConsoleData exchange : exchanges) {
String name = exchange.getStringValue("name");
if (filter.equals("") || filter.equals(name)) {
System.out.printf("%-10s%-" + maxNameLen + "s ", exchange.getStringValue("type"), name);
Map args = (Map) exchange.getValue("arguments");
args = (args == null) ? Collections.EMPTY_MAP : args;
if (exchange.getBooleanValue("durable")) {
System.out.printf("--durable ");
}
if (args.containsKey(MSG_SEQUENCE) && QmfData.getLong(args.get(MSG_SEQUENCE)) == 1) {
System.out.printf("--sequence ");
}
if (args.containsKey(IVE) && QmfData.getLong(args.get(IVE)) == 1) {
System.out.printf("--ive ");
}
if (exchange.hasValue("altExchange")) {
ObjectId altExchangeRef = exchange.getRefValue("altExchange");
QmfConsoleData altExchange = findById(exchanges, altExchangeRef);
if (altExchange != null) {
System.out.printf("--alternate-exchange=%s", altExchange.getStringValue("name"));
}
}
System.out.println();
}
}
}
Aggregations