+ public void onMessage(final Message message) {
+ final String query;
+ final String correlationId;
+ try {
+ query = message.getStringProperty(PROPERTY_QUERY);
+ correlationId = message.getJMSCorrelationID();
+ } catch (JMSException e1) {
+ throw new SlcException("Cannot analyze incoming message " + message);
+ }
+
+ final Object response;
+ final Destination destinationSend;
+ if (QUERY_PING_ALL.equals(query)) {
+ ReferenceList refList = (ReferenceList) convertFrom(message);
+ if (!refList.getReferences().contains(agentDescriptor.getUuid())) {
+ response = agentDescriptor;
+ destinationSend = agentRegister;
+ log.info("Agent #" + agentDescriptor.getUuid()
+ + " registering to " + agentRegister
+ + " in reply to a " + QUERY_PING_ALL + " query");
+ } else {
+ return;
+ }
+ } else {
+ response = process(query, message);
+ destinationSend = responseDestination;
+ }
+
+ // Send response
+ if (log.isTraceEnabled())
+ log.trace("About to send response " + response.getClass());
+ jmsTemplate.convertAndSend(destinationSend, response,
+ new MessagePostProcessor() {
+ public Message postProcessMessage(Message messageToSend)
+ throws JMSException {
+ messageToSend.setStringProperty(PROPERTY_QUERY, query);
+ messageToSend.setStringProperty(
+ MsgConstants.PROPERTY_SLC_AGENT_ID,
+ agentDescriptor.getUuid());
+ messageToSend.setJMSCorrelationID(correlationId);
+ return messageToSend;
+ }
+ });
+ if (log.isTraceEnabled())
+ log.debug("Sent response to query '" + query
+ + "' with correlationId " + correlationId);