use of org.jaffa.persistence.UOW in project jaffa-framework by jaffa-projects.
the class TransactionEngine method updateTransactionStatusToInProcess.
/**
* Updates the input transaction's status to I.
* NOTE: The processing happens within the scope of a local new UOW.
*
* @param transaction the Transaction to update.
* @throws FrameworkException Indicates some system error.
* @throws ApplicationExceptions Indicates application error(s).
*/
public void updateTransactionStatusToInProcess(Transaction transaction) throws FrameworkException, ApplicationExceptions {
UOW uow = null;
try {
uow = new UOW();
transaction.setUOW(uow);
updateTransactionStatusToInProcess(uow, transaction);
uow.commit();
} catch (Exception e) {
throw ExceptionHelper.throwAFR(e);
} finally {
if (uow != null) {
uow.rollback();
}
}
}
use of org.jaffa.persistence.UOW in project jaffa-framework by jaffa-projects.
the class LockingService method checkLock.
/**
* Browses all Transactions looking for the locks, as specified in the transaction-configuration for the input dataBean.
* Creates a new UOW to perform the lock check.
* Throws an ApplicationException, if any matching Transaction is found.
*
* @param dataBean Any serializable object.
* @throws FrameworkException Indicates some system error.
* @throws ApplicationExceptions Indicates application error(s).
*/
public static void checkLock(Object dataBean) throws FrameworkException, ApplicationExceptions {
UOW uow = null;
try {
uow = new UOW();
checkLock(uow, dataBean);
} finally {
if (uow != null) {
try {
uow.rollback();
} catch (Exception e) {
// UOW unable to be rolledback
log.error("UOW unable to be rolled back");
}
}
}
}
use of org.jaffa.persistence.UOW in project jaffa-framework by jaffa-projects.
the class TransactionAdmin method resubmitMessage.
/**
* NOTE: Each graph is expected to contain messageId. It may also contain the optional queueMetaData.queueSystemId and type, which may help optimize the process.
*/
public MessageAdminResponse[] resubmitMessage(MessageGraph[] graphs) {
if (log.isDebugEnabled()) {
log.debug("Input to resubmitMessage: " + Arrays.toString(graphs));
}
Collection<MessageAdminResponse> output = null;
String[] types = TransactionEngine.getInstance().getAccessibleTypeNames();
Arrays.sort(types);
for (MessageGraph graph : graphs) {
if (graph.getQueueMetaData() == null || graph.getQueueMetaData().getQueueSystemId() == null || graph.getQueueMetaData().getQueueSystemId().equals(QUEUE_SYSTEM_ID)) {
if (graph.getType() == null || (types != null && Arrays.binarySearch(types, graph.getType()) >= 0)) {
UOW uow = null;
try {
String graphType = graph.getType();
String messageId = graph.getMessageId();
if (graphType != null && !TransactionEngine.getInstance().hasAdminAccess(graphType)) {
throw new ApplicationExceptions(new ApplicationException("error.Jaffa.Transaction.Transaction.noAdminAccess", new Object[] { graphType }));
}
uow = new UOW();
Transaction transaction = transactionDAO.getTransaction(messageId);
if (transaction != null) {
if (!TransactionEngine.getInstance().hasAdminAccess(transaction.getType())) {
throw new ApplicationExceptions(new ApplicationException("error.Jaffa.Transaction.Transaction.noAdminAccess", new Object[] { transaction.getType() }));
}
if (Transaction.Status.E.toString().equals(transaction.getStatus())) {
if (log.isDebugEnabled()) {
log.debug("Resubmitting ERROR message " + messageId);
}
transaction.setStatus(Transaction.Status.O.toString());
transaction.setErrorMessage(null);
transactionDAO.save(uow, transaction);
if (null != transactionWorkDAO) {
boolean isSingletonType = ConfigurationService.getInstance().isTypeSingleton(transaction.getType());
if (isSingletonType) {
transactionWorkDAO.addToSingletonQueue(transaction.getType(), transaction.getId());
} else {
transactionWorkDAO.addToReadyQueue(transaction.getId());
}
}
uow.commit();
} else {
if (log.isDebugEnabled()) {
log.debug("Resubmission cannot be performed since message " + messageId + " is not in ERROR status anymore");
}
}
} else {
if (log.isDebugEnabled()) {
log.debug("Resubmission cannot be performed since message " + messageId + " not found");
}
}
} catch (Exception e) {
MessageAdminResponse response = new MessageAdminResponse();
response.setSource(graph);
ApplicationExceptions appExps = ExceptionHelper.extractApplicationExceptions(e);
if (appExps != null) {
if (log.isDebugEnabled()) {
log.debug("Error while resubmitting Message " + graph, appExps);
}
response.setErrors(ServiceError.generate(appExps));
} else {
log.error("Internal Error while resubmitting Message " + graph, e);
response.setErrors(ServiceError.generate(e));
}
if (output == null) {
output = new LinkedList<MessageAdminResponse>();
}
output.add(response);
} finally {
if (uow != null) {
try {
uow.rollback();
} catch (Exception ignore) {
}
}
}
} else {
if (log.isDebugEnabled()) {
log.debug("Message " + graph + " will not be resubmitted by this implementation, since the queue does not belong to this implementation");
}
}
} else {
if (log.isDebugEnabled()) {
log.debug("Message " + graph + " will not be resubmitted by this implementation, since the input queueSystemId does not match this system");
}
}
}
if (log.isDebugEnabled()) {
log.debug("Output from resubmitMessage: " + output);
}
return output != null && output.size() > 0 ? output.toArray(new MessageAdminResponse[output.size()]) : null;
}
use of org.jaffa.persistence.UOW in project jaffa-framework by jaffa-projects.
the class TransactionAdmin method invokeHandler.
/**
* Invokes the intended handler. This Handler must implement the IMessageHandler Interface in order to be invoked.
*
* @param uow
* @param transaction
* @param methodName
* @throws JaffaMessagingFrameworkException
*/
private static void invokeHandler(UOW uow, Transaction transaction, String methodName) throws Exception {
try {
TransactionPayload tp = transaction.getTransactionPayloadObject();
Object dataBean = tp != null ? tp.moldInternalPayload() : null;
if (dataBean != null) {
// Load transaction configuration
TransactionInfo transactionInfo = ConfigurationService.getInstance().getTransactionInfo(tp.getInternalMessageClass());
if (transactionInfo == null) {
throw new JaffaMessagingFrameworkException(JaffaTransactionFrameworkException.TRANSACTION_INFO_MISSING, new Object[] { tp.getInternalMessageClass() });
}
// Obtain the handlerClass
if (transactionInfo.getToClass() == null || transactionInfo.getToClass().length() == 0) {
if (log.isDebugEnabled()) {
log.debug(methodName + " toClass is not defined in data bean configuration: " + transactionInfo.getDataBean());
}
return;
}
Class handlerClass = Class.forName(transactionInfo.getToClass());
// Class dataBeanClass = Class.forName(transactionInfo.getDataBean());
if (IMessageHandler.class.isAssignableFrom(handlerClass)) {
// Unmarshals the Message payload into a dataBean using the dataBeanClassName
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();
Map<String, String> headerMap = new HashMap<String, String>();
// Sets the transactionField elements as defined in the configuration file.
TransactionField[] fields = transaction.getTransactionFieldArray();
if (fields != null) {
for (TransactionField field : fields) {
headerMap.put(field.getFieldName(), field.getValue());
}
}
// Invoke the handler
if (log.isDebugEnabled()) {
log.debug("Invoking the handler " + handlerMethod);
}
handlerMethod.invoke(handlerObject, new Object[] { uow, headerMap, dataBean });
}
}
} catch (Exception e) {
// Just log the error
log.error("Exception thrown while deleting the transaction. Transaction was: " + transaction, e);
throw e;
}
}
use of org.jaffa.persistence.UOW in project jaffa-framework by jaffa-projects.
the class TransactionAdmin method deleteMessage.
// ///////////////////////////////// Add in intercept for delete
/**
* NOTE: Each graph is expected to contain messageId. It may also contain the optional queueMetaData.queueSystemId and type, which may help optimize the process.
*/
public MessageAdminResponse[] deleteMessage(MessageGraph[] graphs) {
if (log.isDebugEnabled()) {
log.debug("Input to deleteMessage: " + Arrays.toString(graphs));
}
Collection<MessageAdminResponse> output = null;
String[] types = TransactionEngine.getInstance().getAccessibleTypeNames();
Arrays.sort(types);
for (MessageGraph graph : graphs) {
if (graph.getQueueMetaData() == null || graph.getQueueMetaData().getQueueSystemId() == null || graph.getQueueMetaData().getQueueSystemId().equals(QUEUE_SYSTEM_ID)) {
if (graph.getType() == null || (types != null && Arrays.binarySearch(types, graph.getType()) >= 0)) {
UOW uow = null;
try {
String graphType = graph.getType();
String messageId = graph.getMessageId();
if (graphType != null && !TransactionEngine.getInstance().hasAdminAccess(graphType)) {
throw new ApplicationExceptions(new ApplicationException("error.Jaffa.Transaction.Transaction.noAdminAccess", new Object[] { graphType }));
}
uow = new UOW();
Transaction transaction = transactionDAO.getTransaction(messageId);
if (transaction != null) {
String transactionType = transaction.getType();
if (!TransactionEngine.getInstance().hasAdminAccess(transactionType)) {
throw new ApplicationExceptions(new ApplicationException("error.Jaffa.Transaction.Transaction.noAdminAccess", new Object[] { transactionType }));
}
// Invoke Message Handler class to perform onDelete process
invokeHandler(uow, transaction, "onDelete");
if (log.isDebugEnabled()) {
log.debug("Deleting message " + messageId);
}
transactionDAO.delete(uow, transaction);
uow.commit();
} else {
if (log.isDebugEnabled()) {
log.debug("Delete cannot be performed since message " + messageId + " not found");
}
}
} catch (Exception e) {
MessageAdminResponse response = new MessageAdminResponse();
response.setSource(graph);
ApplicationExceptions appExps = ExceptionHelper.extractApplicationExceptions(e);
if (appExps != null) {
if (log.isDebugEnabled()) {
log.debug("Error while deleting Message " + graph, appExps);
}
response.setErrors(ServiceError.generate(appExps));
} else {
log.error("Internal Error while deleting Message " + graph, e);
response.setErrors(ServiceError.generate(e));
}
if (output == null) {
output = new LinkedList<MessageAdminResponse>();
}
output.add(response);
} finally {
if (uow != null) {
try {
uow.rollback();
} catch (Exception ignore) {
}
}
}
} else {
if (log.isDebugEnabled()) {
log.debug("Message " + graph + " will not be deleted by this implementation, since the queue does not belong to this implementation");
}
}
} else {
if (log.isDebugEnabled()) {
log.debug("Message " + graph + " will not be deleted by this implementation, since the input queueSystemId does not match this system");
}
}
}
if (log.isDebugEnabled()) {
log.debug("Output from deleteMessage: " + output);
}
return output != null && output.size() > 0 ? output.toArray(new MessageAdminResponse[output.size()]) : null;
}
Aggregations