use of org.apache.qpid.qmf2.common.Handle in project qpid by apache.
the class Agent method raiseException.
/**
* Send an exception back to the Console.
* @param handle the reply handle that contains the replyTo Address.
* @param message the exception message.
*/
public final void raiseException(final Handle handle, final String message) {
try {
MapMessage response = _syncSession.createMapMessage();
response.setJMSCorrelationID(handle.getCorrelationId());
response.setStringProperty("x-amqp-0-10.app-id", "qmf2");
response.setStringProperty("method", "response");
response.setStringProperty("qmf.opcode", "_exception");
response.setStringProperty("qmf.agent", _name);
response.setStringProperty("qpid.subject", handle.getRoutingKey());
QmfData exception = new QmfData();
exception.setValue("error_text", message);
response.setObject("_values", exception.mapEncode());
sendResponse(handle, response);
} catch (JMSException jmse) {
_log.info("JMSException {} caught in handleLocateRequest()", jmse.getMessage());
}
}
use of org.apache.qpid.qmf2.common.Handle in project qpid by apache.
the class Console method getObjects.
/**
* Perform a query for QmfConsoleData objects. Returns a list (possibly empty) of matching objects.
* If replyHandle is null this method will block until the agent replies, or the timeout expires.
* Once the timeout expires, all data retrieved to date is returned. If replyHandle is non-null an
* asynchronous request is performed
*
* @param agent the Agent being queried
* @param query the ObjectId or SchemaClassId being queried for.
* @param replyHandle the correlation handle used to tie asynchronous method requests with responses
* @param timeout the time to wait for a reply from the Agent, a value of -1 means use the default timeout
* @return a List of QMF Objects describing that class
*/
private List<QmfConsoleData> getObjects(final Agent agent, final QmfData query, final String replyHandle, int timeout) {
String agentName = agent.getName();
timeout = (timeout < 1) ? _replyTimeout : timeout;
List<QmfConsoleData> results = Collections.emptyList();
try {
Destination destination = (replyHandle == null) ? _replyAddress : _asyncReplyAddress;
MapMessage request = _syncSession.createMapMessage();
request.setJMSReplyTo(destination);
request.setJMSCorrelationID(replyHandle);
request.setStringProperty("x-amqp-0-10.app-id", "qmf2");
request.setStringProperty("method", "request");
request.setStringProperty("qmf.opcode", "_query_request");
request.setStringProperty("qpid.subject", agentName);
// Create a QMF Query for an "OBJECT" target using either a schema ID or object ID
String queryType = (query instanceof SchemaClassId) ? "_schema_id" : "_object_id";
request.setObject("_what", "OBJECT");
request.setObject(queryType, query.mapEncode());
// it would be somewhat unfortunate if their response got interleaved with ours!!
synchronized (this) {
_requester.send(request);
if (replyHandle == null) {
boolean lastResult = true;
ArrayList<QmfConsoleData> partials = new ArrayList<QmfConsoleData>();
do {
// Wrap in a do/while loop to cater for the case where the Agent may send partial results.
Message response = _responder.receive(timeout * 1000);
if (response == null) {
_log.info("No response received in getObjects()");
return partials;
}
lastResult = !response.propertyExists("partial");
if (AMQPMessage.isAMQPList(response)) {
List<Map> mapResults = AMQPMessage.getList(response);
partials.ensureCapacity(partials.size() + mapResults.size());
for (Map content : mapResults) {
partials.add(new QmfConsoleData(content, agent));
}
} else if (AMQPMessage.isAMQPMap(response)) {
// Error responses are returned as MapMessages, though they are being ignored here.
// QmfData exception = new QmfData(AMQPMessage.getMap(response));
// System.out.println(agentName + " " + exception.getStringValue("error_text"));
} else {
_log.info("getObjects() Received response message in incorrect format");
}
} while (!lastResult);
results = partials;
}
}
} catch (JMSException jmse) {
_log.info("JMSException {} caught in getObjects()", jmse.getMessage());
}
return results;
}
use of org.apache.qpid.qmf2.common.Handle in project qpid by apache.
the class Console method refreshSubscription.
/**
* Renews a subscription identified by SubscriptionId.
* <p>
* The Console may request a new subscription duration by providing a requested lifetime. This method may be called
* asynchronously by providing a replyHandle argument.
* <p>
* When called asynchronously, the result of this method call is returned in a SUBSCRIBE_RESPONSE WorkItem.
* <p>
* Timeout can be used to override the console's default reply timeout.
* <p>
* When called synchronously, this method returns a class SubscribeParams object containing the result of the
* subscription request.
*
* @param subscriptionId the ID of the subscription to be refreshed
* @param options a String representation of a Map containing the options in the form
* <pre>"{lifetime:<value>, replyHandle:<value>, timeout:<value>}"</pre>
* they are optional and may appear in any order.
* <pre>
* <b>lifetime</b> requests a new subscription duration.
* <b>replyHandle</b> the correlation handle used to tie asynchronous method requests with responses.
* <b>timeout</b> the time to wait for a reply from the Agent.
* </pre>
*/
public SubscribeParams refreshSubscription(String subscriptionId, final String options) throws QmfException {
if (subscriptionId == null) {
throw new QmfException("Called refreshSubscription() with null subscriptionId");
}
SubscriptionManager subscription = _subscriptionById.get(subscriptionId);
if (subscription == null) {
throw new QmfException("Called refreshSubscription() with invalid subscriptionId");
}
String consoleHandle = subscription.getConsoleHandle();
Agent agent = subscription.getAgent();
if (!agent.isActive()) {
throw new QmfException("Called refreshSubscription() with inactive agent");
}
String agentName = agent.getName();
// Initialise optional values to defaults;
long lifetime = 0;
long timeout = _replyTimeout;
String replyHandle = null;
if (options != null) {
// We wrap the Map in a QmfData object to avoid potential class cast issues with the parsed options
QmfData optMap = new QmfData(new AddressParser(options).map());
if (optMap.hasValue("lifetime")) {
lifetime = optMap.getLongValue("lifetime");
}
if (optMap.hasValue("timeout")) {
timeout = optMap.getLongValue("timeout");
}
if (optMap.hasValue("replyHandle")) {
replyHandle = optMap.getStringValue("replyHandle");
}
}
try {
Destination destination = (replyHandle == null) ? _replyAddress : _asyncReplyAddress;
MapMessage request = _syncSession.createMapMessage();
request.setJMSReplyTo(destination);
request.setJMSCorrelationID(replyHandle);
request.setStringProperty("x-amqp-0-10.app-id", "qmf2");
request.setStringProperty("method", "request");
request.setStringProperty("qmf.opcode", "_subscribe_refresh_indication");
request.setStringProperty("qpid.subject", agentName);
request.setObject("_subscription_id", subscriptionId);
if (lifetime > 0) {
request.setObject("_duration", lifetime);
}
// it would be somewhat unfortunate if their response got interleaved with ours!!
synchronized (this) {
if (_subscriptionEmulationEnabled && agentName.equals(_brokerAgentName)) {
// If the Agent is the broker Agent we emulate the Subscription on the Console
subscription.refresh();
final SubscribeParams params = new SubscribeParams(consoleHandle, subscription.mapEncode());
if (replyHandle == null) {
return params;
} else {
final String handle = replyHandle;
Thread thread = new Thread() {
public void run() {
_eventListener.onEvent(new SubscribeResponseWorkItem(new Handle(handle), params));
}
};
thread.start();
}
return null;
}
_requester.send(request);
if (replyHandle == null) {
// If this is an synchronous request get the response
Message response = _responder.receive(timeout * 1000);
if (response == null) {
subscription.cancel();
_log.info("No response received in refreshSubscription()");
throw new QmfException("No response received for Console.refreshSubscription()");
}
SubscribeParams result = new SubscribeParams(consoleHandle, AMQPMessage.getMap(response));
subscriptionId = result.getSubscriptionId();
if (subscriptionId == null) {
subscription.cancel();
} else {
subscription.setDuration(result.getLifetime());
subscription.refresh();
}
return result;
}
}
// If this is an asynchronous request return without waiting for a response
return null;
} catch (JMSException jmse) {
_log.info("JMSException {} caught in refreshSubscription()", jmse.getMessage());
throw new QmfException(jmse.getMessage());
}
}
use of org.apache.qpid.qmf2.common.Handle in project qpid by apache.
the class Agent method registerEventClass.
/**
* Register a schema for an event class with the Agent.
* <p>
* The Agent must have a registered schema for an event class before it can handle events of that class.
*
* @param schema the SchemaEventClass to be registered
*/
public final void registerEventClass(final SchemaEventClass schema) {
SchemaClassId classId = schema.getClassId();
_schemaCache.put(classId, schema);
}
Aggregations