Search in sources :

Example 1 with SchemaObjectClass

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

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

the class Test4 method registerObjectClass.

public void registerObjectClass(SchemaObjectClass schema) {
    SchemaClassId classId = schema.getClassId();
    _schemaCache.put(classId, schema);
}
Also used : SchemaClassId(org.apache.qpid.qmf2.common.SchemaClassId)

Example 3 with SchemaObjectClass

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

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

the class BigPayloadAgentTest method setupSchema.

public void setupSchema() throws QmfException {
    System.out.println("*** BigPayloadAgentTest initialising the various Schema classes ***");
    // Create and register schema for this agent.
    String packageName = "com.test.bigagent";
    // Declare a control object to test methods against.
    _controlSchema = new SchemaObjectClass(packageName, "control");
    _controlSchema.addProperty(new SchemaProperty("name", QmfType.TYPE_STRING));
    _controlSchema.setIdNames("name");
    SchemaMethod createMethod = new SchemaMethod("processPayload", "Process a large payload");
    createMethod.addArgument(new SchemaProperty("parameter", QmfType.TYPE_STRING, "{dir:IN}"));
    createMethod.addArgument(new SchemaProperty("return", QmfType.TYPE_STRING, "{dir:OUT}"));
    _controlSchema.addMethod(createMethod);
    System.out.println("BigPayloadAgentTest Schema classes initialised OK");
    _agent.registerObjectClass(_controlSchema);
    System.out.println("BigPayloadAgentTest Schema classes registered OK");
}
Also used : SchemaProperty(org.apache.qpid.qmf2.common.SchemaProperty) SchemaMethod(org.apache.qpid.qmf2.common.SchemaMethod) SchemaObjectClass(org.apache.qpid.qmf2.common.SchemaObjectClass)

Example 5 with SchemaObjectClass

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

the class Agent method registerObjectClass.

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

Aggregations

SchemaObjectClass (org.apache.qpid.qmf2.common.SchemaObjectClass)6 SchemaClassId (org.apache.qpid.qmf2.common.SchemaClassId)4 SchemaClass (org.apache.qpid.qmf2.common.SchemaClass)3 SchemaEventClass (org.apache.qpid.qmf2.common.SchemaEventClass)3 SchemaMethod (org.apache.qpid.qmf2.common.SchemaMethod)3 SchemaProperty (org.apache.qpid.qmf2.common.SchemaProperty)3 ObjectId (org.apache.qpid.qmf2.common.ObjectId)2 QmfException (org.apache.qpid.qmf2.common.QmfException)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 QmfQuery (org.apache.qpid.qmf2.common.QmfQuery)1