MethodCallParams methodCallParams = item.getMethodCallParams();
String methodName = methodCallParams.getName();
ObjectId objectId = methodCallParams.getObjectId();
String userId = methodCallParams.getUserId();
userId = userId.equals("") ? "anonymous" : userId;
QmfData inArgs = methodCallParams.getArgs();
ObjectId controlAddress = _control.getObjectId();
System.out.println("Method Call User ID = " + userId);
try
{
if (objectId == null)
{
// Method invoked directly on Agent
if (methodName.equals("toString"))
{
QmfData outArgs = new QmfData();
outArgs.setValue("string", _agent.toString());
_agent.methodResponse(methodName, item.getHandle(), outArgs, null);
}
}
else if (objectId.equals(controlAddress))
{
if (methodName.equals("stop"))
{
System.out.println("Invoked stop method");
String message = inArgs.getStringValue("message");
System.out.println("Stopping: message = " + message);
_agent.methodResponse(methodName, item.getHandle(), null, null);
_agent.destroy();
System.exit(1);
}
else if (methodName.equals("echo"))
{
System.out.println("Invoked echo method");
_agent.methodResponse(methodName, item.getHandle(), inArgs, null);
}
else if (methodName.equals("event"))
{
System.out.println("Invoked event method");
QmfEvent event = new QmfEvent(_eventSchema);
event.setSeverity((int)inArgs.getLongValue("severity"));
event.setValue("text", inArgs.getStringValue("text"));
_agent.raiseEvent(event);
_agent.methodResponse(methodName, item.getHandle(), null, null);
}
else if (methodName.equals("fail"))
{
System.out.println("Invoked fail method");
QmfData error = new QmfData();
if (inArgs.getBooleanValue("useString"))
{
error.setValue("error_text", inArgs.getStringValue("stringVal"));
}
else
{
error.setValue("whatHappened", "It Failed");
error.setValue("howBad", 75);
error.setValue("details", inArgs.getValue("details"));
}
_agent.methodResponse(methodName, item.getHandle(), null, error);
}
else if (methodName.equals("create_child"))
{
System.out.println("Invoked create_child method");
String childName = inArgs.getStringValue("name");
System.out.println("childName = " + childName);
QmfAgentData child = new QmfAgentData(_childSchema);
child.setValue("name", childName);
_agent.addObject(child);
QmfData outArgs = new QmfData();
outArgs.setRefValue("childAddr", child.getObjectId(), "reference"); // Set subtype just to test
_agent.methodResponse(methodName, item.getHandle(), outArgs, null);
}
}
}
catch (QmfException qmfe)
{
System.err.println("QmfException " + qmfe.getMessage() + " caught: AgentTest failed");
QmfData error = new QmfData();
error.setValue("error_text", qmfe.getMessage());
_agent.methodResponse(methodName, item.getHandle(), null, error);
}
}
}