public CommandHandler getHandler() throws IllegalAccessException, IOException, InstantiationException, ClassNotFoundException { if (handler == null) { handler = createHandler(); } return handler; }
public MessageProducer getProducer() throws JMSException { if (producer == null) { producer = getSession().createProducer(null); } return producer; }
public void onMessage(Message message) { if (LOG.isDebugEnabled()) { LOG.debug("Received command: " + message); } if (message instanceof TextMessage) { TextMessage request = (TextMessage)message; try { Destination replyTo = message.getJMSReplyTo(); if (replyTo == null) { LOG.warn("Ignored message as no JMSReplyTo set: " + message); return; } Message response = processCommand(request); addReplyHeaders(request, response); getProducer().send(replyTo, response); } catch (Exception e) { LOG.error("Failed to process message due to: " + e + ". Message: " + message, e); } } else { LOG.warn("Ignoring invalid message: " + message); } }
/** * Processes an incoming JMS message returning the response message */ public Message processCommand(TextMessage request) throws Exception { TextMessage response = session.createTextMessage(); getHandler().processCommand(request, response); return response; }
/** * * @throws Exception * @org.apache.xbean.InitMethod */ @PostConstruct public void start() throws Exception { session = getConnection().createSession(false, Session.AUTO_ACKNOWLEDGE); listener = new CommandMessageListener(session); Destination destination = getCommandDestination(); if (LOG.isDebugEnabled()) { LOG.debug("Agent subscribing to control destination: " + destination); } consumer = session.createConsumer(destination); consumer.setMessageListener(listener); }
/** * Processes an incoming command from a console and returning the text to * output */ public String processCommandText(String line) throws Exception { TextMessage request = new ActiveMQTextMessage(); request.setText(line); TextMessage response = new ActiveMQTextMessage(); getHandler().processCommand(request, response); return response.getText(); }