use of org.jaffa.modules.messaging.services.configdomain.MessageInfo in project jaffa-framework by jaffa-projects.
the class LockingService method deleteLockingMessages.
/**
* Browses all messages in all the queues looking for the locks, as specified in the messageInfo for the input payload.
* Deletes the matching messages.
* @param payload Any serializable object.
* @throws FrameworkException Indicates some system error.
* @throws ApplicationExceptions Indicates application error(s).
*/
public static void deleteLockingMessages(Object payload) throws FrameworkException, ApplicationExceptions {
try {
// Reads the MessageConfig for the className of the input payload
MessageInfo messageInfo = ConfigurationService.getInstance().getMessageInfo(payload.getClass().getName());
if (messageInfo == null)
throw new JaffaMessagingFrameworkException(JaffaMessagingFrameworkException.MESSAGE_INFO_MISSING, new Object[] { payload.getClass().getName() });
// Obtain the messages
deleteLockingMessages(payload, messageInfo);
} catch (ClassNotFoundException e) {
log.error("Error in locating the Message info for " + payload.getClass().getName(), e);
throw new JaffaMessagingFrameworkException(JaffaMessagingFrameworkException.MESSAGE_INFO_MISSING, new Object[] { payload.getClass().getName() }, e);
}
}
use of org.jaffa.modules.messaging.services.configdomain.MessageInfo in project jaffa-framework by jaffa-projects.
the class LockingService method checkLock.
/**
* Browses all messages in all the queues looking for the locks, as specified in the messageInfo for the input payload.
* Throws an ApplicationException, if any matching message is found.
* @param payload Any serializable object.
* @throws FrameworkException Indicates some system error.
* @throws ApplicationExceptions Indicates application error(s).
*/
public static void checkLock(Object payload) throws FrameworkException, ApplicationExceptions {
try {
// Reads the MessageConfig for the className of the input payload
MessageInfo messageInfo = ConfigurationService.getInstance().getMessageInfo(payload.getClass().getName());
if (messageInfo == null)
throw new JaffaMessagingFrameworkException(JaffaMessagingFrameworkException.MESSAGE_INFO_MISSING, new Object[] { payload.getClass().getName() });
// Perform the check
checkLock(payload, messageInfo);
} catch (ClassNotFoundException e) {
log.error("Error in locating the Message info for " + payload.getClass().getName(), e);
throw new JaffaMessagingFrameworkException(JaffaMessagingFrameworkException.MESSAGE_INFO_MISSING, new Object[] { payload.getClass().getName() }, e);
}
}
use of org.jaffa.modules.messaging.services.configdomain.MessageInfo in project jaffa-framework by jaffa-projects.
the class JmsBrowser method invokeHandler.
/**
* Invokes the intended handler. This Handler must implement the IMessageHandler Interface in order to be invoked.
*
* @param message
* @param methodName
* @throws JaffaMessagingFrameworkException
*/
private static void invokeHandler(Message message, String methodName) throws JaffaMessagingFrameworkException {
UOW uow = null;
try {
// Reads the MessageConfig from the ConfigurationService, based on the dataBeanClassName
String dataBeanClassName = message.getStringProperty(JmsBrowser.HEADER_DATA_BEAN_CLASS_NAME);
MessageInfo messageInfo = ConfigurationService.getInstance().getMessageInfo(dataBeanClassName);
if (messageInfo == null)
throw new JaffaMessagingFrameworkException(JaffaMessagingFrameworkException.MESSAGE_INFO_MISSING, new Object[] { dataBeanClassName });
// Obtain the handlerClass
Class handlerClass = Class.forName(messageInfo.getToClass());
if (IMessageHandler.class.isAssignableFrom(handlerClass)) {
// Unmarshals the Message payload into a dataBean using the dataBeanClassName
Object payload = JAXBHelper.unmarshalPayload(obtainMessageContents(message), dataBeanClassName);
if (log.isDebugEnabled())
log.debug("Obtained payload for the dataBean " + dataBeanClassName + '\n' + payload);
Method handlerMethod = null;
Object handlerObject = null;
// Obtain the handler method
try {
handlerMethod = handlerClass.getMethod(methodName, new Class[] { UOW.class, Map.class, Object.class });
} catch (NoSuchMethodException e) {
// Hence use the dataBeanClass specified in the messageInfo to get the appropriate handlerMethod
if (log.isDebugEnabled())
log.debug(methodName + " method not found in " + handlerClass.getName());
return;
}
handlerObject = handlerClass.newInstance();
uow = new UOW();
Map<String, String> headerMap = new HashMap<String, String>();
// Sets the header elements as defined in the configuration file.
if (messageInfo.getHeader() != null && messageInfo.getHeader().getParam() != null) {
for (Param param : messageInfo.getHeader().getParam()) {
String headerValue = (String) message.getObjectProperty(param.getName());
headerMap.put(param.getName(), headerValue);
}
}
handlerMethod.invoke(handlerObject, new Object[] { uow, headerMap, payload });
uow.commit();
}
} catch (Exception e) {
// Just log the error
log.error("Exception thrown while deleting the message. Message was: " + message, e);
throw new JaffaMessagingFrameworkException(JaffaMessagingFrameworkException.DELETE_ERROR, null, e);
} finally {
if (uow != null) {
try {
uow.rollback();
} catch (Exception e) {
throw new JaffaMessagingFrameworkException(JaffaMessagingFrameworkException.DELETE_ERROR, null, e);
}
}
}
}
Aggregations