use of org.apache.qpid.qmf2.console.Agent 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");
}
use of org.apache.qpid.qmf2.console.Agent in project qpid by apache.
the class AgentTestConsole method onEvent.
public void onEvent(WorkItem wi) {
System.out.println("WorkItem type: " + wi.getType());
if (wi.getType() == AGENT_ADDED) {
AgentAddedWorkItem item = (AgentAddedWorkItem) wi;
Agent agent = item.getAgent();
// If this is the gizmo Agent we notify the main thread so processing can continue.
if (agent.getProduct().equals("gizmo")) {
synchronized (this) {
_gizmo = agent;
notify();
}
}
}
if (wi.getType() == AGENT_HEARTBEAT) {
AgentHeartbeatWorkItem item = (AgentHeartbeatWorkItem) wi;
Agent agent = item.getAgent();
System.out.println(agent.getName());
}
if (wi.getType() == EVENT_RECEIVED) {
EventReceivedWorkItem item = (EventReceivedWorkItem) wi;
Agent agent = item.getAgent();
QmfEvent event = item.getEvent();
String className = event.getSchemaClassId().getClassName();
System.out.println("Event: " + className);
//event.listValues();
}
if (wi.getType() == METHOD_RESPONSE) {
MethodResponseWorkItem item = (MethodResponseWorkItem) wi;
MethodResult result = item.getMethodResult();
String correlationId = item.getHandle().getCorrelationId();
System.out.println("correlationId = " + correlationId);
System.out.println(result.getStringValue("message"));
}
if (wi.getType() == OBJECT_UPDATE) {
ObjectUpdateWorkItem item = (ObjectUpdateWorkItem) wi;
QmfConsoleData object = item.getQmfConsoleData();
ObjectId objectId = object.getObjectId();
String correlationId = item.getHandle().getCorrelationId();
System.out.println("correlationId = " + correlationId);
System.out.println("objectId = " + objectId);
System.out.println("MethodCount = " + object.getLongValue("methodCount"));
}
}
use of org.apache.qpid.qmf2.console.Agent in project qpid by apache.
the class BigPayloadAgentTestConsole method onEvent.
public void onEvent(WorkItem wi) {
if (wi.getType() == AGENT_HEARTBEAT) {
AgentHeartbeatWorkItem item = (AgentHeartbeatWorkItem) wi;
Agent agent = item.getAgent();
System.out.println(agent.getName());
}
}
use of org.apache.qpid.qmf2.console.Agent in project qpid by apache.
the class BrokerSubscriptionTestConsole method onEvent.
public void onEvent(WorkItem wi) {
System.out.println("WorkItem type: " + wi.getType());
if (wi.getType() == AGENT_HEARTBEAT) {
AgentHeartbeatWorkItem item = (AgentHeartbeatWorkItem) wi;
Agent agent = item.getAgent();
System.out.println(agent.getName());
}
if (wi.getType() == EVENT_RECEIVED) {
EventReceivedWorkItem item = (EventReceivedWorkItem) wi;
Agent agent = item.getAgent();
QmfEvent event = item.getEvent();
String className = event.getSchemaClassId().getClassName();
System.out.println("Event: " + className);
//event.listValues();
}
if (wi.getType() == METHOD_RESPONSE) {
MethodResponseWorkItem item = (MethodResponseWorkItem) wi;
MethodResult result = item.getMethodResult();
String correlationId = item.getHandle().getCorrelationId();
System.out.println("correlationId = " + correlationId);
System.out.println(result.getStringValue("message"));
}
if (wi.getType() == OBJECT_UPDATE) {
ObjectUpdateWorkItem item = (ObjectUpdateWorkItem) wi;
QmfConsoleData object = item.getQmfConsoleData();
ObjectId objectId = object.getObjectId();
String correlationId = item.getHandle().getCorrelationId();
System.out.println("correlationId = " + correlationId);
System.out.println("objectId = " + objectId);
System.out.println("MethodCount = " + object.getLongValue("methodCount"));
}
if (wi.getType() == SUBSCRIBE_RESPONSE) {
SubscribeResponseWorkItem item = (SubscribeResponseWorkItem) wi;
SubscribeParams params = item.getSubscribeParams();
System.out.println("duration = " + params.getLifetime());
System.out.println("interval = " + params.getPublishInterval());
System.out.println("subscriptionId = " + params.getSubscriptionId());
System.out.println("consoleHandle = " + params.getConsoleHandle());
String correlationId = item.getHandle().getCorrelationId();
System.out.println("correlationId = " + correlationId);
}
if (wi.getType() == SUBSCRIPTION_INDICATION) {
SubscriptionIndicationWorkItem item = (SubscriptionIndicationWorkItem) wi;
SubscribeIndication indication = item.getSubscribeIndication();
String correlationId = indication.getConsoleHandle();
System.out.println("correlationId = " + correlationId);
List<QmfConsoleData> objects = indication.getData();
for (QmfConsoleData object : objects) {
if (object.isDeleted()) {
System.out.println("object has been deleted");
}
String className = object.getSchemaClassId().getClassName();
System.out.println("object class = " + className);
if (className.equals("queue") || className.equals("exchange")) {
if (object.hasValue("name")) {
System.out.println("property update, name = " + object.getStringValue("name"));
} else {
_objectId = object.getObjectId();
System.out.println("statistic update, oid = " + _objectId);
}
}
}
}
}
use of org.apache.qpid.qmf2.console.Agent in project qpid by apache.
the class AgentExternalTest method onEvent.
public void onEvent(WorkItem wi) {
System.out.println("WorkItem type: " + wi.getType());
if (wi.getType() == METHOD_CALL) {
_control.incValue("methodCount", 1);
MethodCallWorkItem item = (MethodCallWorkItem) wi;
MethodCallParams methodCallParams = item.getMethodCallParams();
String methodName = methodCallParams.getName();
ObjectId objectId = methodCallParams.getObjectId();
String userId = methodCallParams.getUserId();
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);
addObject(child);
QmfData outArgs = new QmfData();
// Set suptype 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: AgentExternalTest failed");
QmfData error = new QmfData();
error.setValue("error_text", qmfe.getMessage());
_agent.methodResponse(methodName, item.getHandle(), null, error);
}
}
if (wi.getType() == QUERY) {
QueryWorkItem item = (QueryWorkItem) wi;
QmfQuery query = item.getQmfQuery();
System.out.println("Query User ID = " + item.getUserId());
if (query.getObjectId() != null) {
// Look up a QmfAgentData object by the ObjectId obtained from the query
ObjectId objectId = query.getObjectId();
QmfAgentData object = _objectIndex.get(objectId);
if (object != null && !object.isDeleted()) {
_agent.queryResponse(item.getHandle(), object);
}
_agent.queryComplete(item.getHandle(), 0);
} else {
// taken by the C++ broker ManagementAgent, so if it's a problem here........
for (QmfAgentData object : _objectIndex.values()) {
if (!object.isDeleted() && query.evaluate(object)) {
_agent.queryResponse(item.getHandle(), object);
}
}
_agent.queryComplete(item.getHandle(), 0);
}
}
if (wi.getType() == SUBSCRIBE_REQUEST) {
SubscribeRequestWorkItem item = (SubscribeRequestWorkItem) wi;
SubscriptionParams params = item.getSubscriptionParams();
Handle handle = item.getHandle();
System.out.println("Subscribe Request User ID = " + params.getUserId());
try {
Subscription subscription = new Subscription(this, params);
_subscriptions.put(subscription.getSubscriptionId(), subscription);
_timer.schedule(subscription, 0, params.getPublishInterval());
if (subscription == null) {
System.out.println("Requested Subscription has already expired or been cancelled");
QmfData error = new QmfData();
error.setValue("error_text", "Requested Subscription has already expired or been cancelled");
_agent.subscriptionResponse(handle, subscription.getConsoleHandle(), null, 0, 0, error);
} else {
_agent.subscriptionResponse(handle, subscription.getConsoleHandle(), subscription.getSubscriptionId(), subscription.getDuration(), subscription.getInterval(), null);
}
} catch (QmfException qmfe) {
_agent.raiseException(handle, "Subscribe Request failed, invalid Query: " + qmfe.getMessage());
}
}
if (wi.getType() == RESUBSCRIBE_REQUEST) {
ResubscribeRequestWorkItem item = (ResubscribeRequestWorkItem) wi;
ResubscribeParams params = item.getResubscribeParams();
Handle handle = item.getHandle();
System.out.println("Resubscribe Request User ID = " + params.getUserId());
String subscriptionId = params.getSubscriptionId();
Subscription subscription = _subscriptions.get(subscriptionId);
if (subscription != null) {
subscription.refresh(params);
_agent.subscriptionResponse(handle, subscription.getConsoleHandle(), subscription.getSubscriptionId(), subscription.getDuration(), subscription.getInterval(), null);
} else {
System.out.println("Requested Subscription has already expired or been cancelled");
QmfData error = new QmfData();
error.setValue("error_text", "Requested Subscription has already expired or been cancelled");
_agent.subscriptionResponse(handle, subscription.getConsoleHandle(), null, 0, 0, error);
}
}
if (wi.getType() == UNSUBSCRIBE_REQUEST) {
UnsubscribeRequestWorkItem item = (UnsubscribeRequestWorkItem) wi;
String subscriptionId = item.getSubscriptionId();
System.out.println("Received cancellation request for " + subscriptionId);
Subscription subscription = _subscriptions.get(subscriptionId);
if (subscription != null) {
subscription.cancel();
}
}
}
Aggregations