use of org.apache.qpid.qmf2.common.QmfData in project qpid by apache.
the class JSON method fromQmfData.
/**
* Serialise a QmfData Object to JSON. If the Object is a QmfConsoleData we serialise the ObjectId as a String
* which is the same encoding used for the various "ref" properies in fromObject().
* @param data the QmfData that we wish to serialise to JSON.
* @return the JSON String encoding.
*/
public static final String fromQmfData(final QmfData data) {
String consoleDataInfo = "";
if (data instanceof QmfConsoleData) {
QmfConsoleData consoleData = (QmfConsoleData) data;
SchemaClassId sid = consoleData.getSchemaClassId();
long[] ts = consoleData.getTimestamps();
String objectId = "\"_object_id\":\"" + consoleData.getObjectId().toString() + "\",";
String schemaId = "\"_schema_id\":{" + "\"_package_name\":\"" + sid.getPackageName() + "\",\"_class_name\":\"" + sid.getClassName() + "\",\"_type\":\"" + sid.getType() + "\",\"_hash\":\"" + sid.getHashString() + "\"},";
String timestamps = "\"_update_ts\":" + ts[0] + "," + "\"_create_ts\":" + ts[1] + "," + "\"_delete_ts\":" + ts[2] + ",";
consoleDataInfo = objectId + schemaId + timestamps;
}
return "{" + consoleDataInfo + encodeMapContents(data.mapEncode()) + "}";
}
use of org.apache.qpid.qmf2.common.QmfData in project qpid by apache.
the class AgentTest method onEvent.
public void onEvent(WorkItem wi) {
System.out.println("WorkItem type: " + wi.getType());
_control.incValue("methodCount", 1);
if (wi.getType() == METHOD_CALL) {
MethodCallWorkItem item = (MethodCallWorkItem) wi;
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();
// Set subtype just to test
outArgs.setRefValue("childAddr", child.getObjectId(), "reference");
_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);
}
}
}
use of org.apache.qpid.qmf2.common.QmfData in project qpid by apache.
the class BigPayloadAgentTest method onEvent.
public void onEvent(WorkItem wi) {
System.out.println("WorkItem type: " + wi.getType());
if (wi.getType() == METHOD_CALL) {
MethodCallWorkItem item = (MethodCallWorkItem) wi;
MethodCallParams methodCallParams = item.getMethodCallParams();
String methodName = methodCallParams.getName();
ObjectId objectId = methodCallParams.getObjectId();
QmfData inArgs = methodCallParams.getArgs();
ObjectId controlAddress = _control.getObjectId();
if (objectId.equals(controlAddress)) {
if (methodName.equals("processPayload")) {
System.out.println("Invoked processPayload method");
byte[] parameter = inArgs.getValue("parameter");
System.out.println("payload size = " + parameter.length);
QmfData outArgs = new QmfData();
outArgs.setValue("return", parameter);
_agent.methodResponse(methodName, item.getHandle(), outArgs, null);
}
}
}
}
use of org.apache.qpid.qmf2.common.QmfData in project qpid by apache.
the class QpidConfig method delExchange.
/**
* Remove an exchange using the QMF "delete" method.
* @param args the exchange name is the first argument.
* The remaining QMF method properties are populated form config parsed from the command line.
*/
private void delExchange(final String[] args) {
if (args.length < 1) {
usage();
}
QmfData arguments = new QmfData();
arguments.setValue("type", "exchange");
arguments.setValue("name", args[0]);
try {
_broker.invokeMethod("delete", arguments);
} catch (QmfException e) {
System.out.println(e.getMessage());
}
}
use of org.apache.qpid.qmf2.common.QmfData in project qpid by apache.
the class QpidConfig method delQueue.
/**
* Remove a queue using the QMF "delete" method.
* @param args the queue name is the first argument.
* The remaining QMF method properties are populated form config parsed from the command line.
*/
private void delQueue(final String[] args) {
if (args.length < 1) {
usage();
}
if (_ifEmpty || _ifUnused) {
// Check the selected queue object to see if it is not empty or is in use
List<QmfConsoleData> queues = _console.getObjects("org.apache.qpid.broker", "queue");
for (QmfConsoleData queue : queues) {
ObjectId queueId = queue.getObjectId();
String name = queue.getStringValue("name");
if (name.equals(args[0])) {
long msgDepth = queue.getLongValue("msgDepth");
if (_ifEmpty == true && msgDepth > 0) {
System.out.println("Cannot delete queue " + name + "; queue not empty");
return;
}
long consumerCount = queue.getLongValue("consumerCount");
if (_ifUnused == true && consumerCount > 0) {
System.out.println("Cannot delete queue " + name + "; queue in use");
return;
}
}
}
}
QmfData arguments = new QmfData();
arguments.setValue("type", "queue");
arguments.setValue("name", args[0]);
try {
_broker.invokeMethod("delete", arguments);
} catch (QmfException e) {
System.out.println(e.getMessage());
}
}
Aggregations