Search in sources :

Example 6 with SchemaClass

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

the class Console method getSchema.

/**
     * Return a list of all available class SchemaClass from a specified Agent.
     * <p>
     * This call will return cached information if it is available.  If not, it will send a query message
     * to the remote agent and block waiting for a response. The timeout argument specifies the maximum time
     * to wait for a response from the agent.
     *
     * @param schemaClassId the SchemaClassId we wish to return schema information for.
     * @param agent the Agent we want to retrieve the schema from
     */
public List<SchemaClass> getSchema(final SchemaClassId schemaClassId, final Agent agent) {
    // First look to see if there are cached results and if there are return those.
    List<SchemaClass> results = agent.getSchema(schemaClassId);
    if (results.size() > 0) {
        return results;
    }
    String agentName = agent.getName();
    //System.out.println("getSchema for agent " + agentName);
    results = new ArrayList<SchemaClass>();
    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" target
        request.setObject("_what", "SCHEMA");
        request.setObject("_schema_id", schemaClassId.mapEncode());
        // 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 getSchema()");
                return Collections.emptyList();
            }
            if (AMQPMessage.isAMQPList(response)) {
                List<Map> mapResults = AMQPMessage.getList(response);
                for (Map content : mapResults) {
                    SchemaClass schema = new SchemaObjectClass(content);
                    if (schema.getClassId().getType().equals("_event")) {
                        schema = new SchemaEventClass(content);
                    }
                    //schema.listValues();
                    results.add(schema);
                }
            } else if (AMQPMessage.isAMQPMap(response)) {
            // Error responses are returned as MapMessages, though they are being ignored here.
            //System.out.println("Console.getSchema() no results for " + agentName);
            //QmfData exception = new QmfData(AMQPMessage.getMap(response));
            //System.out.println(agentName + " " + exception.getStringValue("error_text"));
            } else {
                _log.info("getSchema() Received response message in incorrect format");
            }
        }
    } catch (JMSException jmse) {
        _log.info("JMSException {} caught in getSchema()", jmse.getMessage());
    }
    agent.setSchema(schemaClassId, results);
    return results;
}
Also used : AMQPMessage(org.apache.qpid.qmf2.common.AMQPMessage) MapMessage(javax.jms.MapMessage) Message(javax.jms.Message) SchemaEventClass(org.apache.qpid.qmf2.common.SchemaEventClass) SchemaClass(org.apache.qpid.qmf2.common.SchemaClass) MapMessage(javax.jms.MapMessage) JMSException(javax.jms.JMSException) SchemaObjectClass(org.apache.qpid.qmf2.common.SchemaObjectClass) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 7 with SchemaClass

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

the class Console method getSchema.

// end of onMessage() 
/**
     * Retrieve the schema for a List of classes.
     * This method explicitly retrieves the schema from the remote Agent and is generally used for schema
     * discovery when an Agent is added or updated.
     *
     * @param classes the list of SchemaClassId of the classes who's schema we want to retrieve
     * @param agent the Agent we want to retrieve the schema from
     */
private List<SchemaClass> getSchema(final List<SchemaClassId> classes, final Agent agent) {
    List<SchemaClass> results = new ArrayList<SchemaClass>();
    for (SchemaClassId classId : classes) {
        // Clear Agent's schema value for classId
        agent.setSchema(classId, Collections.<SchemaClass>emptyList());
        results.addAll(getSchema(classId, agent));
    }
    return results;
}
Also used : SchemaClass(org.apache.qpid.qmf2.common.SchemaClass) ArrayList(java.util.ArrayList) SchemaClassId(org.apache.qpid.qmf2.common.SchemaClassId)

Aggregations

SchemaClass (org.apache.qpid.qmf2.common.SchemaClass)7 SchemaClassId (org.apache.qpid.qmf2.common.SchemaClassId)5 ArrayList (java.util.ArrayList)3 ObjectId (org.apache.qpid.qmf2.common.ObjectId)3 SchemaObjectClass (org.apache.qpid.qmf2.common.SchemaObjectClass)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 QmfException (org.apache.qpid.qmf2.common.QmfException)2 List (java.util.List)1 JMSException (javax.jms.JMSException)1 MapMessage (javax.jms.MapMessage)1 Message (javax.jms.Message)1 AMQPMessage (org.apache.qpid.qmf2.common.AMQPMessage)1 QmfQuery (org.apache.qpid.qmf2.common.QmfQuery)1 QmfQueryTarget (org.apache.qpid.qmf2.common.QmfQueryTarget)1 SchemaEventClass (org.apache.qpid.qmf2.common.SchemaEventClass)1 Agent (org.apache.qpid.qmf2.console.Agent)1 AgentAddedWorkItem (org.apache.qpid.qmf2.console.AgentAddedWorkItem)1