use of cz.metacentrum.perun.dispatcher.exceptions.PerunHornetQServerException 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...");
}
}
use of cz.metacentrum.perun.dispatcher.exceptions.PerunHornetQServerException in project perun by CESNET.
the class EngineMessageProcessor method processEngineMessage.
/**
* Process content of JMS message received from Engine. This is called by SystemQueueReceiver
* for each message.
*
* Expected message format is:
*
* Register engine message
* register
*
* Good bye engine message
* goodbye
*
* Task status change message
* task:y:status:timestamp
* y is an Integer that represents task ID
* status is string representation of task status
* timestamp is a string representation of timestamp (long)
*
* Task result message
* taskresult:object
* object is serialized TaskResult object sent from Engine
*
* @see EngineMessageConsumer
*
* @param message Message to be parsed a processed
* @throws PerunHornetQServerException When HornetQ server is not running
* @throws MessageFormatException When Engine sent malformed JMS message
*/
protected void processEngineMessage(String message) throws PerunHornetQServerException, MessageFormatException {
if (perunHornetQServer.isServerRunning() && perunHornetQServer.getJMSServerManager() != null) {
log.debug("Processing JMS message: " + message);
if (null == message || message.isEmpty()) {
throw new MessageFormatException("Engine sent empty message");
}
String[] clientMessageSplitter = message.split(":", 2);
// process expected messages
EngineMessageProducer engineMessageProducer;
if (clientMessageSplitter[0].equalsIgnoreCase("register")) {
// Do we have this queue already?
engineMessageProducer = engineMessageProducerFactory.getProducer();
if (engineMessageProducer != null) {
// ...and close all tasks that could have been running there
schedulingPool.closeTasksForEngine();
} else {
// No, we have to create the whole JMS queue and load matching rules...
createDispatcherQueueForClient();
}
} else if (clientMessageSplitter[0].equalsIgnoreCase("goodbye")) {
// engine is going down, should mark all tasks as failed
schedulingPool.closeTasksForEngine();
engineMessageProducerFactory.removeProducer();
} else if (clientMessageSplitter[0].equalsIgnoreCase("task")) {
clientMessageSplitter = message.split(":", 4);
if (clientMessageSplitter.length < 4) {
throw new MessageFormatException("Engine sent a malformed message, not enough params [" + message + "]");
}
try {
schedulingPool.onTaskStatusChange(Integer.parseInt(clientMessageSplitter[1]), clientMessageSplitter[2], clientMessageSplitter[3]);
} catch (NumberFormatException e) {
throw new MessageFormatException("Engine sent a malformed message, could not parse client ID", e);
}
} else if (clientMessageSplitter[0].equalsIgnoreCase("taskresult")) {
if (clientMessageSplitter.length < 2) {
throw new MessageFormatException("Engine sent a malformed message, not enough params [" + message + "]");
}
schedulingPool.onTaskDestinationComplete(clientMessageSplitter[1]);
} else {
throw new MessageFormatException("Engine sent a malformed message, unknown type of message [" + message + "]");
}
} else {
throw new PerunHornetQServerException("HornetQ server is not running or JMSServerManager is fucked up...");
}
}
Aggregations