Search in sources :

Example 16 with SchemaClassId

use of org.apache.qpid.qmf2.common.SchemaClassId in project qpid by apache.

the class Console method getClasses.

/**
 * Return a list of SchemaClassIds for all available Schema for the specified Agent.
 * @param agent the Agent being queried
 * @return a list of SchemaClassIds for all available Schema for the specified Agent.
 */
public List<SchemaClassId> getClasses(final Agent agent) {
    // First look to see if there are cached results and if there are return those.
    List<SchemaClassId> results = agent.getClasses();
    if (results.size() > 0) {
        return results;
    }
    String agentName = agent.getName();
    results = new ArrayList<SchemaClassId>();
    try {
        MapMessage request = _syncSession.createMapMessage();
        request.setJMSReplyTo(_replyAddress);
        request.setStringProperty("x-amqp-0-10.app-id", "qmf2");
        request.setStringProperty("method", "request");
        request.setStringProperty("qmf.opcode", "_query_request");
        request.setStringProperty("qpid.subject", agentName);
        // Create a QMF Query for an "SCHEMA_ID" target
        request.setObject("_what", "SCHEMA_ID");
        // it would be somewhat unfortunate if their response got interleaved with ours!!
        synchronized (this) {
            _requester.send(request);
            Message response = _responder.receive(_replyTimeout * 1000);
            if (response == null) {
                _log.info("No response received in getClasses()");
                return Collections.emptyList();
            }
            if (AMQPMessage.isAMQPList(response)) {
                List<Map> mapResults = AMQPMessage.getList(response);
                for (Map content : mapResults) {
                    // new SchemaClassId(content).listValues();
                    results.add(new SchemaClassId(content));
                }
            } else if (AMQPMessage.isAMQPMap(response)) {
            // Error responses are returned as MapMessages, though they are being ignored here.
            // System.out.println("Console.getClasses() no results for " + agentName);
            // QmfData exception = new QmfData(AMQPMessage.getMap(response));
            // System.out.println(agentName + " " + exception.getStringValue("error_text"));
            } else {
                _log.info("getClasses() Received response message in incorrect format");
            }
        }
    } catch (JMSException jmse) {
        _log.info("JMSException {} caught in getClasses()", jmse.getMessage());
    }
    agent.setClasses(results);
    return results;
}
Also used : AMQPMessage(org.apache.qpid.qmf2.common.AMQPMessage) MapMessage(javax.jms.MapMessage) Message(javax.jms.Message) MapMessage(javax.jms.MapMessage) JMSException(javax.jms.JMSException) SchemaClassId(org.apache.qpid.qmf2.common.SchemaClassId) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

SchemaClassId (org.apache.qpid.qmf2.common.SchemaClassId)14 SchemaClass (org.apache.qpid.qmf2.common.SchemaClass)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 ArrayList (java.util.ArrayList)5 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)5 JMSException (javax.jms.JMSException)4 ObjectId (org.apache.qpid.qmf2.common.ObjectId)4 MapMessage (javax.jms.MapMessage)3 Message (javax.jms.Message)3 AMQPMessage (org.apache.qpid.qmf2.common.AMQPMessage)3 QmfException (org.apache.qpid.qmf2.common.QmfException)3 QmfQuery (org.apache.qpid.qmf2.common.QmfQuery)3 SchemaObjectClass (org.apache.qpid.qmf2.common.SchemaObjectClass)3 List (java.util.List)2 Destination (javax.jms.Destination)1 Handle (org.apache.qpid.qmf2.common.Handle)1 QmfEvent (org.apache.qpid.qmf2.common.QmfEvent)1 QmfQueryTarget (org.apache.qpid.qmf2.common.QmfQueryTarget)1 SchemaEventClass (org.apache.qpid.qmf2.common.SchemaEventClass)1