use of org.apache.qpid.qmf2.common.QmfEvent 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();
}
}
}
use of org.apache.qpid.qmf2.common.QmfEvent in project qpid by apache.
the class Binding method createBindEvent.
/**
* Factory method to create a Bind Event Object with timestamp of now.
* @return the newly created Bind Event Object.
*/
public QmfEvent createBindEvent() {
QmfEvent bind = new QmfEvent(_bindSchema);
bind.setSeverity("info");
bind.setValue("args", _binding.getArguments());
bind.setValue("exName", _binding.getExchange().getName());
bind.setValue("key", _binding.getName());
bind.setValue("qName", _binding.getQueue().getName());
//bind.setValue("user", getStringValue("authIdentity"));
return bind;
}
use of org.apache.qpid.qmf2.common.QmfEvent in project qpid by apache.
the class Binding method createUnbindEvent.
/**
* Factory method to create an Unbind Event Object with timestamp of now.
* @return the newly created Unbind Event Object.
*/
public QmfEvent createUnbindEvent() {
QmfEvent unbind = new QmfEvent(_unbindSchema);
unbind.setSeverity("info");
unbind.setValue("exName", _binding.getExchange().getName());
unbind.setValue("key", _binding.getName());
unbind.setValue("qName", _binding.getQueue().getName());
//unbind.setValue("user", getStringValue("authIdentity"));
return unbind;
}
use of org.apache.qpid.qmf2.common.QmfEvent in project qpid by apache.
the class Queue method createQueueDeclareEvent.
/**
* Factory method to create a Queue Declare Event Object with timestamp of now.
* @return the newly created Queue Declare Event Object.
*/
public QmfEvent createQueueDeclareEvent() {
QmfEvent queueDeclare = new QmfEvent(_queueDeclareSchema);
queueDeclare.setSeverity("info");
// TODO the _alternateExchangeName gets set some time after the Constructor - how do I get its value for
// the queueDeclareEvent???!!!
queueDeclare.setValue("altEx", _alternateExchangeName);
// TODO
queueDeclare.setValue("args", Collections.EMPTY_MAP);
queueDeclare.setValue("autoDel", getBooleanValue("autoDelete"));
queueDeclare.setValue("disp", "created");
queueDeclare.setValue("durable", getBooleanValue("durable"));
queueDeclare.setValue("excl", getBooleanValue("exclusive"));
queueDeclare.setValue("qName", getStringValue("name"));
//queueDeclare.setValue("user", getStringValue("authIdentity"));
return queueDeclare;
}
use of org.apache.qpid.qmf2.common.QmfEvent in project qpid by apache.
the class Queue method createQueueDeleteEvent.
/**
* Factory method to create a Queue Delete Event Object with timestamp of now.
* @return the newly created Queue Delete Event Object.
*/
public QmfEvent createQueueDeleteEvent() {
QmfEvent queueDelete = new QmfEvent(_queueDeleteSchema);
queueDelete.setSeverity("info");
queueDelete.setValue("qName", getStringValue("name"));
//queueDelete.setValue("user", getStringValue("authIdentity"));
return queueDelete;
}
Aggregations