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