Search in sources :

Example 1 with ObjectId

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);
                    }
                }
            }
        }
    }
}
Also used : ObjectId(org.apache.qpid.qmf2.common.ObjectId) QmfConsoleData(org.apache.qpid.qmf2.console.QmfConsoleData) Map(java.util.Map)

Example 2 with ObjectId

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);
}
Also used : ObjectId(org.apache.qpid.qmf2.common.ObjectId) SchemaClass(org.apache.qpid.qmf2.common.SchemaClass) SchemaObjectClass(org.apache.qpid.qmf2.common.SchemaObjectClass) SchemaClassId(org.apache.qpid.qmf2.common.SchemaClassId) QmfException(org.apache.qpid.qmf2.common.QmfException)

Example 3 with ObjectId

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;
}
Also used : ObjectId(org.apache.qpid.qmf2.common.ObjectId) ArrayList(java.util.ArrayList) QmfConsoleData(org.apache.qpid.qmf2.console.QmfConsoleData) QmfAgentData(org.apache.qpid.qmf2.agent.QmfAgentData)

Example 4 with ObjectId

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);
            }
        }
    }
}
Also used : ObjectId(org.apache.qpid.qmf2.common.ObjectId) QmfConsoleData(org.apache.qpid.qmf2.console.QmfConsoleData) Date(java.util.Date)

Example 5 with ObjectId

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();
        }
    }
}
Also used : ObjectId(org.apache.qpid.qmf2.common.ObjectId) QmfConsoleData(org.apache.qpid.qmf2.console.QmfConsoleData) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ObjectId (org.apache.qpid.qmf2.common.ObjectId)28 QmfConsoleData (org.apache.qpid.qmf2.console.QmfConsoleData)15 Map (java.util.Map)10 HashMap (java.util.HashMap)8 QmfException (org.apache.qpid.qmf2.common.QmfException)7 QmfAgentData (org.apache.qpid.qmf2.agent.QmfAgentData)6 QmfData (org.apache.qpid.qmf2.common.QmfData)6 SchemaClassId (org.apache.qpid.qmf2.common.SchemaClassId)6 ArrayList (java.util.ArrayList)5 QmfEvent (org.apache.qpid.qmf2.common.QmfEvent)5 Agent (org.apache.qpid.qmf2.console.Agent)5 MethodCallParams (org.apache.qpid.qmf2.agent.MethodCallParams)4 MethodCallWorkItem (org.apache.qpid.qmf2.agent.MethodCallWorkItem)4 AgentHeartbeatWorkItem (org.apache.qpid.qmf2.console.AgentHeartbeatWorkItem)4 MethodResult (org.apache.qpid.qmf2.console.MethodResult)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 QmfQuery (org.apache.qpid.qmf2.common.QmfQuery)3 SchemaClass (org.apache.qpid.qmf2.common.SchemaClass)3 EventReceivedWorkItem (org.apache.qpid.qmf2.console.EventReceivedWorkItem)3 MethodResponseWorkItem (org.apache.qpid.qmf2.console.MethodResponseWorkItem)3