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;
}
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;
}
Aggregations