Search in sources :

Example 1 with MessageFormatException

use of cz.metacentrum.perun.dispatcher.exceptions.MessageFormatException in project perun by CESNET.

the class SystemQueueProcessor method processDispatcherQueueAndMatchingRule.

protected void processDispatcherQueueAndMatchingRule(String systemMessagetext) throws PerunHornetQServerException, MessageFormatException {
    if (perunHornetQServer.isServerRunning() && perunHornetQServer.getJMSServerManager() != null) {
        if (log.isDebugEnabled()) {
            log.debug("Processing system message:" + systemMessagetext);
        }
        if (null == systemMessagetext) {
            throw new MessageFormatException("Client (Perun-Engine) sent empty message");
        }
        String[] clientIDsplitter = systemMessagetext.split(":", 3);
        if (clientIDsplitter.length < 2) {
            throw new MessageFormatException("Client (Perun-Engine) sent a malformed message [" + systemMessagetext + "]");
        }
        int clientID = 0;
        try {
            clientID = Integer.parseInt(clientIDsplitter[1]);
        } catch (NumberFormatException e) {
            throw new MessageFormatException("Client (Perun-Engine) sent a malformed message [" + systemMessagetext + "]", e);
        }
        if (clientIDsplitter[0].equalsIgnoreCase("register")) {
            // Do we have this queue already?
            DispatcherQueue dispatcherQueue = dispatcherQueuePool.getDispatcherQueueByClient(clientID);
            if (dispatcherQueue != null) {
                // Yes, so we just reload matching rules...
                smartMatcher.reloadRulesFromDBForEngine(clientID);
                // ...and close all tasks that could have been running there
                propagationMaintainer.closeTasksForEngine(clientID);
            } else {
                // No, we have to create the whole JMS queue and load
                // matching
                // rules...
                createDispatcherQueueForClient(clientID);
            }
        } else if (clientIDsplitter[0].equalsIgnoreCase("goodbye")) {
            // engine going down, should mark all tasks as failed
            propagationMaintainer.closeTasksForEngine(clientID);
            dispatcherQueuePool.removeDispatcherQueue(clientID);
        } else if (clientIDsplitter[0].equalsIgnoreCase("task")) {
            clientIDsplitter = systemMessagetext.split(":", 6);
            if (clientIDsplitter.length < 6) {
                throw new MessageFormatException("Client (Perun-Engine) sent a malformed message [" + systemMessagetext + "]");
            }
            // task complete...
            propagationMaintainer.onTaskComplete(Integer.parseInt(clientIDsplitter[2]), clientID, clientIDsplitter[3], clientIDsplitter[4], clientIDsplitter[5]);
        } else if (clientIDsplitter[0].equalsIgnoreCase("taskresult")) {
            // destination complete for task
            if (clientIDsplitter.length < 3) {
                throw new MessageFormatException("Client (Perun-Engine) sent a malformed message [" + systemMessagetext + "]");
            }
            propagationMaintainer.onTaskDestinationComplete(clientID, clientIDsplitter[2]);
        } else {
            throw new MessageFormatException("Client (Perun-Engine) sent a malformed message [" + systemMessagetext + "]");
        }
    } else {
        throw new PerunHornetQServerException("It looks like the HornetQ server is not running or JMSServerManager is fucked up...");
    }
}
Also used : MessageFormatException(cz.metacentrum.perun.dispatcher.exceptions.MessageFormatException) PerunHornetQServerException(cz.metacentrum.perun.dispatcher.exceptions.PerunHornetQServerException)

Example 2 with MessageFormatException

use of cz.metacentrum.perun.dispatcher.exceptions.MessageFormatException in project perun by CESNET.

the class SystemQueueReceiver method run.

@Override
public void run() {
    log.debug("SystemQueueReceiver has started...");
    try {
        // Step 1. Directly instantiate the JMS Queue object.
        log.debug("Creating queue...");
        queue = HornetQJMSClient.createQueue(queueName);
        // Step 9. Create a JMS Message Consumer
        log.debug("Creating consumer...");
        messageConsumer = session.createConsumer(queue);
    } catch (JMSException e) {
        log.error(e.toString(), e);
    } catch (Exception e) {
        log.error(e.toString(), e);
    }
    TextMessage messageReceived = null;
    while (running) {
        // Step 11. Receive the message
        messageReceived = null;
        try {
            log.debug("Gonna call messageConsumer.receive(timeout)...");
            messageReceived = (TextMessage) messageConsumer.receive(timeout);
            if (messageReceived != null) {
                if (log.isDebugEnabled()) {
                    log.debug("System message received[" + messageReceived.getText() + "]");
                }
                try {
                    systemQueueProcessor.processDispatcherQueueAndMatchingRule(messageReceived.getText());
                } catch (MessageFormatException ex) {
                    // engine sent wrongly formatted messages
                    // shouldn't kill whole messaging process
                    log.error(ex.toString(), ex);
                }
                messageReceived.acknowledge();
            }
            if (log.isDebugEnabled()) {
                if (messageReceived == null) {
                    log.debug("No message available...");
                }
            }
        } catch (JMSException e) {
            log.error(e.toString(), e);
            systemQueueProcessor.stopProcessingSystemMessages();
            systemQueueProcessor.startProcessingSystemMessages();
            try {
                Thread.sleep(10000);
            } catch (InterruptedException ex) {
                log.error(ex.toString(), ex);
                stop();
            }
        } catch (Exception e) {
            log.error(e.toString(), e);
            stop();
        }
    }
    try {
        messageConsumer.close();
    } catch (JMSException e) {
        log.error(e.toString(), e);
    }
    messageConsumer = null;
}
Also used : MessageFormatException(cz.metacentrum.perun.dispatcher.exceptions.MessageFormatException) JMSException(javax.jms.JMSException) MessageFormatException(cz.metacentrum.perun.dispatcher.exceptions.MessageFormatException) JMSException(javax.jms.JMSException) TextMessage(javax.jms.TextMessage)

Aggregations

MessageFormatException (cz.metacentrum.perun.dispatcher.exceptions.MessageFormatException)2 PerunHornetQServerException (cz.metacentrum.perun.dispatcher.exceptions.PerunHornetQServerException)1 JMSException (javax.jms.JMSException)1 TextMessage (javax.jms.TextMessage)1