Search in sources :

Example 1 with SchemaEventClass

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

the class AgentExternalTest method setupSchema.

public void setupSchema() throws QmfException {
    System.out.println("*** AgentExternalTest initialising the various Schema classes ***");
    // Create and register schema for this agent.
    String packageName = "com.profitron.gizmo";
    // Declare a schema for a structured exception that can be used in failed method invocations.
    _exceptionSchema = new SchemaObjectClass(packageName, "exception");
    _exceptionSchema.addProperty(new SchemaProperty("whatHappened", QmfType.TYPE_STRING));
    _exceptionSchema.addProperty(new SchemaProperty("howBad", QmfType.TYPE_INT));
    _exceptionSchema.addProperty(new SchemaProperty("details", QmfType.TYPE_MAP));
    // Declare a control object to test methods against.
    _controlSchema = new SchemaObjectClass(packageName, "control");
    _controlSchema.addProperty(new SchemaProperty("state", QmfType.TYPE_STRING));
    _controlSchema.addProperty(new SchemaProperty("methodCount", QmfType.TYPE_INT));
    _controlSchema.addProperty(new SchemaProperty("offset", QmfType.TYPE_INT));
    _controlSchema.setIdNames("state");
    SchemaMethod stopMethod = new SchemaMethod("stop", "Stop Agent");
    stopMethod.addArgument(new SchemaProperty("message", QmfType.TYPE_STRING, "{dir:IN}"));
    _controlSchema.addMethod(stopMethod);
    SchemaMethod echoMethod = new SchemaMethod("echo", "Echo Arguments");
    echoMethod.addArgument(new SchemaProperty("message", QmfType.TYPE_STRING, "{dir:INOUT}"));
    _controlSchema.addMethod(echoMethod);
    SchemaMethod eventMethod = new SchemaMethod("event", "Raise an Event");
    eventMethod.addArgument(new SchemaProperty("text", QmfType.TYPE_STRING, "{dir:IN}"));
    eventMethod.addArgument(new SchemaProperty("severity", QmfType.TYPE_INT, "{dir:IN}"));
    _controlSchema.addMethod(eventMethod);
    SchemaMethod failMethod = new SchemaMethod("fail", "Expected to Fail");
    failMethod.addArgument(new SchemaProperty("useString", QmfType.TYPE_BOOL, "{dir:IN}"));
    failMethod.addArgument(new SchemaProperty("stringVal", QmfType.TYPE_STRING, "{dir:IN}"));
    failMethod.addArgument(new SchemaProperty("details", QmfType.TYPE_MAP, "{dir:IN}"));
    _controlSchema.addMethod(failMethod);
    SchemaMethod createMethod = new SchemaMethod("create_child", "Create Child Object");
    createMethod.addArgument(new SchemaProperty("name", QmfType.TYPE_STRING, "{dir:IN}"));
    createMethod.addArgument(new SchemaProperty("childAddr", QmfType.TYPE_MAP, "{dir:OUT}"));
    _controlSchema.addMethod(createMethod);
    // Declare the child class
    _childSchema = new SchemaObjectClass(packageName, "child");
    _childSchema.addProperty(new SchemaProperty("name", QmfType.TYPE_STRING));
    _childSchema.setIdNames("name");
    // Declare the event class
    _eventSchema = new SchemaEventClass(packageName, "event");
    _eventSchema.addProperty(new SchemaProperty("text", QmfType.TYPE_STRING));
    System.out.println("AgentExternalTest Schema classes initialised OK");
    _agent.registerObjectClass(_exceptionSchema);
    _agent.registerObjectClass(_controlSchema);
    _agent.registerObjectClass(_childSchema);
    _agent.registerEventClass(_eventSchema);
    System.out.println("AgentExternalTest Schema classes registered OK");
}
Also used : SchemaProperty(org.apache.qpid.qmf2.common.SchemaProperty) SchemaMethod(org.apache.qpid.qmf2.common.SchemaMethod) SchemaEventClass(org.apache.qpid.qmf2.common.SchemaEventClass) SchemaObjectClass(org.apache.qpid.qmf2.common.SchemaObjectClass)

Example 2 with SchemaEventClass

use of org.apache.qpid.qmf2.common.SchemaEventClass 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 3 with SchemaEventClass

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

the class Agent method registerEventClass.

/**
 * Register a schema for an event class with the Agent.
 * <p>
 * The Agent must have a registered schema for an event class before it can handle events of that class.
 *
 * @param schema the SchemaEventClass to be registered
 */
public final void registerEventClass(final SchemaEventClass schema) {
    SchemaClassId classId = schema.getClassId();
    _schemaCache.put(classId, schema);
}
Also used : SchemaClassId(org.apache.qpid.qmf2.common.SchemaClassId)

Example 4 with SchemaEventClass

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

the class AgentTest method setupSchema.

public void setupSchema() throws QmfException {
    System.out.println("*** AgentTest initialising the various Schema classes ***");
    // Create and register schema for this agent.
    String packageName = "com.profitron.gizmo";
    // Declare a schema for a structured exception that can be used in failed method invocations.
    _exceptionSchema = new SchemaObjectClass(packageName, "exception");
    _exceptionSchema.addProperty(new SchemaProperty("whatHappened", QmfType.TYPE_STRING));
    _exceptionSchema.addProperty(new SchemaProperty("howBad", QmfType.TYPE_INT));
    _exceptionSchema.addProperty(new SchemaProperty("details", QmfType.TYPE_MAP));
    // Declare a control object to test methods against.
    _controlSchema = new SchemaObjectClass(packageName, "control");
    _controlSchema.addProperty(new SchemaProperty("state", QmfType.TYPE_STRING));
    _controlSchema.addProperty(new SchemaProperty("methodCount", QmfType.TYPE_INT));
    _controlSchema.addProperty(new SchemaProperty("offset", QmfType.TYPE_INT));
    _controlSchema.setIdNames("state");
    SchemaMethod stopMethod = new SchemaMethod("stop", "Stop Agent");
    stopMethod.addArgument(new SchemaProperty("message", QmfType.TYPE_STRING, "{dir:IN}"));
    _controlSchema.addMethod(stopMethod);
    SchemaMethod echoMethod = new SchemaMethod("echo", "Echo Arguments");
    echoMethod.addArgument(new SchemaProperty("message", QmfType.TYPE_STRING, "{dir:INOUT}"));
    _controlSchema.addMethod(echoMethod);
    SchemaMethod eventMethod = new SchemaMethod("event", "Raise an Event");
    eventMethod.addArgument(new SchemaProperty("text", QmfType.TYPE_STRING, "{dir:IN}"));
    eventMethod.addArgument(new SchemaProperty("severity", QmfType.TYPE_INT, "{dir:IN}"));
    _controlSchema.addMethod(eventMethod);
    SchemaMethod failMethod = new SchemaMethod("fail", "Expected to Fail");
    failMethod.addArgument(new SchemaProperty("useString", QmfType.TYPE_BOOL, "{dir:IN}"));
    failMethod.addArgument(new SchemaProperty("stringVal", QmfType.TYPE_STRING, "{dir:IN}"));
    failMethod.addArgument(new SchemaProperty("details", QmfType.TYPE_MAP, "{dir:IN}"));
    _controlSchema.addMethod(failMethod);
    SchemaMethod createMethod = new SchemaMethod("create_child", "Create Child Object");
    createMethod.addArgument(new SchemaProperty("name", QmfType.TYPE_STRING, "{dir:IN}"));
    createMethod.addArgument(new SchemaProperty("childAddr", QmfType.TYPE_MAP, "{dir:OUT}"));
    _controlSchema.addMethod(createMethod);
    // Declare the child class
    _childSchema = new SchemaObjectClass(packageName, "child");
    _childSchema.addProperty(new SchemaProperty("name", QmfType.TYPE_STRING));
    _childSchema.setIdNames("name");
    // Declare the event class
    _eventSchema = new SchemaEventClass(packageName, "event");
    _eventSchema.addProperty(new SchemaProperty("text", QmfType.TYPE_STRING));
    System.out.println("AgentTest Schema classes initialised OK");
    _agent.registerObjectClass(_exceptionSchema);
    _agent.registerObjectClass(_controlSchema);
    _agent.registerObjectClass(_childSchema);
    _agent.registerEventClass(_eventSchema);
    System.out.println("AgentTest Schema classes registered OK");
}
Also used : SchemaProperty(org.apache.qpid.qmf2.common.SchemaProperty) SchemaMethod(org.apache.qpid.qmf2.common.SchemaMethod) SchemaEventClass(org.apache.qpid.qmf2.common.SchemaEventClass) SchemaObjectClass(org.apache.qpid.qmf2.common.SchemaObjectClass)

Aggregations

SchemaEventClass (org.apache.qpid.qmf2.common.SchemaEventClass)3 SchemaObjectClass (org.apache.qpid.qmf2.common.SchemaObjectClass)3 SchemaMethod (org.apache.qpid.qmf2.common.SchemaMethod)2 SchemaProperty (org.apache.qpid.qmf2.common.SchemaProperty)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 JMSException (javax.jms.JMSException)1 MapMessage (javax.jms.MapMessage)1 Message (javax.jms.Message)1 AMQPMessage (org.apache.qpid.qmf2.common.AMQPMessage)1 SchemaClass (org.apache.qpid.qmf2.common.SchemaClass)1 SchemaClassId (org.apache.qpid.qmf2.common.SchemaClassId)1