use of javax.jms.MapMessage in project wildfly by wildfly.
the class TestEnvEntryMDBean method onMessage.
public void onMessage(Message msg) {
log.trace("OnMessage working...");
try {
Destination destination = msg.getJMSReplyTo();
Connection conn = connectionFactory.createConnection();
try {
Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer replyProducer = session.createProducer(destination);
MapMessage replyMsg = session.createMapMessage();
replyMsg.setJMSCorrelationID(msg.getJMSMessageID());
replyMsg.setInt("maxExceptions", maxExceptions);
replyMsg.setInt("numExceptions", numExceptions);
replyMsg.setInt("minExceptions", minExceptions);
// System.err.println("reply to: " + destination);
// System.err.println("maxExceptions: " + maxExceptions);
// System.err.println("numExceptions: " + numExceptions);
// System.err.println("minExceptions: " + minExceptions);
replyProducer.send(replyMsg);
} finally {
conn.close();
}
} catch (JMSException e) {
throw new RuntimeException(e);
}
}
use of javax.jms.MapMessage in project qpid by apache.
the class Agent method subscriptionResponse.
/**
* If the subscription request is successful, the Agent application must provide a unique subscriptionId.
* <p>
* If replying to a sucessful subscription refresh, the original subscriptionId must be supplied.
* <p>
* If the subscription or refresh fails, the subscriptionId should be set to null and error may be set to
* an application-specific QmfData instance that describes the error.
* <p>
* Should a refresh request fail, the consoleHandle may be set to null if unknown.
*
* @param handle the handle from the WorkItem.
* @param consoleHandle the console reply handle.
* @param subscriptionId a unique handle for the subscription supplied by the Agent.
* @param lifetime should be set to the duration of the subscription in seconds.
* @param publishInterval should be set to the time interval in seconds between successive publications
* on this subscription.
* @param error an application-specific QmfData instance that describes the error.
*/
public final void subscriptionResponse(final Handle handle, final Handle consoleHandle, final String subscriptionId, final long lifetime, final long publishInterval, final QmfData error) {
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", "_subscribe_response");
response.setStringProperty("qmf.agent", _name);
response.setStringProperty("qpid.subject", handle.getRoutingKey());
if (error == null) {
response.setObject("_subscription_id", subscriptionId);
response.setObject("_duration", lifetime);
response.setObject("_interval", publishInterval);
} else {
Map<String, Object> errorMap = error.mapEncode();
for (Map.Entry<String, Object> entry : errorMap.entrySet()) {
response.setObject(entry.getKey(), entry.getValue());
}
}
sendResponse(handle, response);
} catch (JMSException jmse) {
_log.info("JMSException {} caught in subscriptionResponse()", jmse.getMessage());
}
}
use of javax.jms.MapMessage 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 javax.jms.MapMessage in project qpid by apache.
the class Console method getClasses.
/**
* Return a list of SchemaClassIds for all available Schema for the specified Agent.
* @param agent the Agent being queried
* @return a list of SchemaClassIds for all available Schema for the specified Agent.
*/
public List<SchemaClassId> getClasses(final Agent agent) {
// First look to see if there are cached results and if there are return those.
List<SchemaClassId> results = agent.getClasses();
if (results.size() > 0) {
return results;
}
String agentName = agent.getName();
results = new ArrayList<SchemaClassId>();
try {
MapMessage request = _syncSession.createMapMessage();
request.setJMSReplyTo(_replyAddress);
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 "SCHEMA_ID" target
request.setObject("_what", "SCHEMA_ID");
// it would be somewhat unfortunate if their response got interleaved with ours!!
synchronized (this) {
_requester.send(request);
Message response = _responder.receive(_replyTimeout * 1000);
if (response == null) {
_log.info("No response received in getClasses()");
return Collections.emptyList();
}
if (AMQPMessage.isAMQPList(response)) {
List<Map> mapResults = AMQPMessage.getList(response);
for (Map content : mapResults) {
//new SchemaClassId(content).listValues();
results.add(new SchemaClassId(content));
}
} else if (AMQPMessage.isAMQPMap(response)) {
// Error responses are returned as MapMessages, though they are being ignored here.
//System.out.println("Console.getClasses() no results for " + agentName);
//QmfData exception = new QmfData(AMQPMessage.getMap(response));
//System.out.println(agentName + " " + exception.getStringValue("error_text"));
} else {
_log.info("getClasses() Received response message in incorrect format");
}
}
} catch (JMSException jmse) {
_log.info("JMSException {} caught in getClasses()", jmse.getMessage());
}
agent.setClasses(results);
return results;
}
use of javax.jms.MapMessage in project qpid by apache.
the class Console method getSchema.
/**
* Return a list of all available class SchemaClass from a specified Agent.
* <p>
* This call will return cached information if it is available. If not, it will send a query message
* to the remote agent and block waiting for a response. The timeout argument specifies the maximum time
* to wait for a response from the agent.
*
* @param schemaClassId the SchemaClassId we wish to return schema information for.
* @param agent the Agent we want to retrieve the schema from
*/
public List<SchemaClass> getSchema(final SchemaClassId schemaClassId, final Agent agent) {
// First look to see if there are cached results and if there are return those.
List<SchemaClass> results = agent.getSchema(schemaClassId);
if (results.size() > 0) {
return results;
}
String agentName = agent.getName();
//System.out.println("getSchema for agent " + agentName);
results = new ArrayList<SchemaClass>();
try {
MapMessage request = _syncSession.createMapMessage();
request.setJMSReplyTo(_replyAddress);
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 "SCHEMA" target
request.setObject("_what", "SCHEMA");
request.setObject("_schema_id", schemaClassId.mapEncode());
// it would be somewhat unfortunate if their response got interleaved with ours!!
synchronized (this) {
_requester.send(request);
Message response = _responder.receive(_replyTimeout * 1000);
if (response == null) {
_log.info("No response received in getSchema()");
return Collections.emptyList();
}
if (AMQPMessage.isAMQPList(response)) {
List<Map> mapResults = AMQPMessage.getList(response);
for (Map content : mapResults) {
SchemaClass schema = new SchemaObjectClass(content);
if (schema.getClassId().getType().equals("_event")) {
schema = new SchemaEventClass(content);
}
//schema.listValues();
results.add(schema);
}
} else if (AMQPMessage.isAMQPMap(response)) {
// Error responses are returned as MapMessages, though they are being ignored here.
//System.out.println("Console.getSchema() no results for " + agentName);
//QmfData exception = new QmfData(AMQPMessage.getMap(response));
//System.out.println(agentName + " " + exception.getStringValue("error_text"));
} else {
_log.info("getSchema() Received response message in incorrect format");
}
}
} catch (JMSException jmse) {
_log.info("JMSException {} caught in getSchema()", jmse.getMessage());
}
agent.setSchema(schemaClassId, results);
return results;
}
Aggregations