@Override
public void run()
{
Message msg = null;
try
{
logger.log(Level.INFO,
"Responder compute implementation starting: {0}", responderId);
hostname = getRuntime().getNodeInfo().getHostname();
// responderId = getProcess().getResponder().getTaskTypeGuid();
/*
* Responder-specific job queue
*/
queue = new JobQueue(responderId);
//Local reference to central message database
messageDao = getRuntime().getMessageDao();
//Responder-specific message processing log
processingLog = new MessageStateLogImpl(getRuntime().getNotificationDB());
queue.acquireLock();
try
{
//Determine if any work is available
msg = queue.poll();
if (msg == null)
{
logger.log(Level.INFO,
"Responder: {0}: no work available. Quitting.", responderId);
return;
}
//If a job was aquired from the queue, then mark it as PROCESSING
logger.log(Level.INFO, "Responder: {0}: acquired job from queue: {1}",
new Object[]{responderId, msg.getGuid()});
updateMessageState(msg, State.PROCESSING);
}
finally
{
queue.releaseLock();
}
}
/*
* Any Exceptions that occur are NOT the job implementation's fault - they
* are a Microbase problem.
*/
catch (MessageStateLogException e)
{
logger.log(Level.INFO,
"Responder: {0} failed to update state flag for message:{1}",
new Object[]{responderId, msg.getGuid()});
e.printStackTrace();
}
catch (DBException e)
{
logger.log(Level.INFO,
"Responder: {0} failed to update state flag for message:{1}",
new Object[]{responderId, msg.getGuid()});
e.printStackTrace();
}
catch(Exception e)
{
logger.log(Level.INFO,
"Responder: {0} failed for an unanticipated reason", responderId);
e.printStackTrace();
}
/*
* Now actually process the message
*/
try
{
try
{
logger.log(Level.INFO,
"Responder: {0}: checking job for incomplete results and "
+ "performing cleanup as required: {1}",
new Object[]{responderId, msg.getGuid()});
cleanupPreviousResults(msg);
logger.log(Level.INFO, "Responder: {0}: processing job: {1}",
new Object[]{responderId, msg.getGuid()});
processMessage(msg);
logger.log(Level.INFO, "Responder: {0}: marking job complete: {1}",
new Object[]{responderId, msg.getGuid()});
updateMessageState(msg, State.FINISHED_SUCCEEDED);
publishSuccessMessage(msg);
logger.log(Level.INFO, "Responder: {0}: finished with job: {1}",
new Object[]{responderId, msg.getGuid()});
}
/*
* Message processing failed.
* Most problems here are likely to do with the job implementation
* itself rather than Microbase
*/
catch(MessageProcessingException e)
{
logger.log(Level.INFO,
"Responder: {0}: cleanup OR processing failed for message: {1}",
new Object[]{responderId, msg.getGuid()});
e.printStackTrace();
formatErrorAndPublishFailure(msg, e);
}
catch(Error e)
{
logger.log(Level.INFO,
"Responder: {0}: cleanup OR processing failed for message: {1} "
+ "due to an Error, rather than a typical "
+ MessageProcessingException.class.getName()
+". Please ensure that your environment is configured correctly, "
+ "including checking sufficient RAM is available, correct classes "
+ "and/or jars are available, etc.",
new Object[]{responderId, msg.getGuid()});
e.printStackTrace();
formatErrorAndPublishFailure(msg, e);
}
}
/*
* Some Microbase process failed
*/
catch (MessageStateLogException e)
{
logger.log(Level.INFO,
"Responder: {0} failed to update state flag for message:{1}",
new Object[]{responderId, msg.getGuid()});
e.printStackTrace();
}
catch (DBException e)
{
logger.log(Level.INFO,
"Responder: {0} either failed to update a message''s state({1}"
+"), or failed to publish a "
+ "success / failure message. See stack trace for details.",
new Object[]{responderId, msg.getGuid()});
e.printStackTrace();
}
catch(Exception e)
{
logger.log(Level.INFO,