use of nl.nn.adapterframework.core.ITransactionalStorage in project iaf by ibissource.
the class ReceiverBase method moveInProcessToError.
private void moveInProcessToError(String originalMessageId, String correlationId, String message, Date receivedDate, String comments, Object rawMessage, TransactionDefinition txDef) {
cachePoisonMessageId(originalMessageId);
ISender errorSender = getErrorSender();
ITransactionalStorage errorStorage = getErrorStorage();
if (errorSender == null && errorStorage == null) {
log.debug(getLogPrefix() + "has no errorSender or errorStorage, will not move message with id [" + originalMessageId + "] correlationId [" + correlationId + "] to errorSender/errorStorage");
return;
}
throwEvent(RCV_MESSAGE_TO_ERRORSTORE_EVENT);
log.debug(getLogPrefix() + "moves message with id [" + originalMessageId + "] correlationId [" + correlationId + "] to errorSender/errorStorage");
TransactionStatus txStatus = null;
try {
txStatus = txManager.getTransaction(txDef);
} catch (Exception e) {
log.error(getLogPrefix() + "Exception preparing to move input message with id [" + originalMessageId + "] to error sender", e);
// no use trying again to send message on errorSender, will cause same exception!
return;
}
try {
if (errorSender != null) {
errorSender.sendMessage(correlationId, message);
}
Serializable sobj;
if (rawMessage instanceof Serializable) {
sobj = (Serializable) rawMessage;
} else {
try {
sobj = new MessageWrapper(rawMessage, getListener());
} catch (ListenerException e) {
log.error(getLogPrefix() + "could not wrap non serializable message for messageId [" + originalMessageId + "]", e);
sobj = message;
}
}
if (hideRegex != null) {
if (getHideMethod().equalsIgnoreCase("FIRSTHALF")) {
message = Misc.hideFirstHalf(message, hideRegex);
} else {
message = Misc.hideAll(message, hideRegex);
}
sobj = message;
}
if (errorStorage != null) {
errorStorage.storeMessage(originalMessageId, correlationId, receivedDate, comments, null, sobj);
}
txManager.commit(txStatus);
} catch (Exception e) {
log.error(getLogPrefix() + "Exception moving message with id [" + originalMessageId + "] correlationId [" + correlationId + "] to error sender, original message: [" + message + "]", e);
try {
if (!txStatus.isCompleted()) {
txManager.rollback(txStatus);
}
} catch (Exception rbe) {
log.error(getLogPrefix() + "Exception while rolling back transaction for message with id [" + originalMessageId + "] correlationId [" + correlationId + "], original message: [" + message + "]", rbe);
}
}
}
use of nl.nn.adapterframework.core.ITransactionalStorage in project iaf by ibissource.
the class JobDef method cleanupDatabase.
private void cleanupDatabase(IbisManager ibisManager) {
Date date = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String formattedDate = formatter.format(date);
List<String> jmsRealmNames = new ArrayList<String>();
for (Configuration configuration : ibisManager.getConfigurations()) {
List<JobDef> scheduledJobs = configuration.getScheduledJobs();
for (JobDef jobdef : configuration.getScheduledJobs()) {
if (jobdef.getLocker() != null) {
String jmsRealmName = jobdef.getLocker().getJmsRealName();
if (!jmsRealmNames.contains(jmsRealmName)) {
jmsRealmNames.add(jmsRealmName);
}
}
}
}
for (IAdapter adapter : ibisManager.getRegisteredAdapters()) {
if (adapter instanceof Adapter) {
PipeLine pipeLine = ((Adapter) adapter).getPipeLine();
if (pipeLine != null) {
for (IPipe pipe : pipeLine.getPipes()) {
if (pipe instanceof IExtendedPipe) {
IExtendedPipe extendedPipe = (IExtendedPipe) pipe;
if (extendedPipe.getLocker() != null) {
String jmsRealmName = extendedPipe.getLocker().getJmsRealName();
if (!jmsRealmNames.contains(jmsRealmName)) {
jmsRealmNames.add(jmsRealmName);
}
}
}
}
}
}
}
for (Iterator iter = jmsRealmNames.iterator(); iter.hasNext(); ) {
String jmsRealmName = (String) iter.next();
setJmsRealm(jmsRealmName);
DirectQuerySender qs;
qs = (DirectQuerySender) ibisManager.getIbisContext().createBeanAutowireByName(DirectQuerySender.class);
qs.setJmsRealm(jmsRealmName);
String deleteQuery;
if (qs.getDatabaseType() == DbmsSupportFactory.DBMS_MSSQLSERVER) {
deleteQuery = "DELETE FROM IBISLOCK WHERE EXPIRYDATE < CONVERT(datetime, '" + formattedDate + "', 120)";
} else {
deleteQuery = "DELETE FROM IBISLOCK WHERE EXPIRYDATE < TO_TIMESTAMP('" + formattedDate + "', 'YYYY-MM-DD HH24:MI:SS')";
}
setQuery(deleteQuery);
qs = null;
executeQueryJob(ibisManager);
}
List messageLogs = new ArrayList();
for (IAdapter iadapter : ibisManager.getRegisteredAdapters()) {
Adapter adapter = (Adapter) iadapter;
PipeLine pipeline = adapter.getPipeLine();
for (int i = 0; i < pipeline.getPipes().size(); i++) {
IPipe pipe = pipeline.getPipe(i);
if (pipe instanceof MessageSendingPipe) {
MessageSendingPipe msp = (MessageSendingPipe) pipe;
if (msp.getMessageLog() != null) {
ITransactionalStorage transactionStorage = msp.getMessageLog();
if (transactionStorage instanceof JdbcTransactionalStorage) {
JdbcTransactionalStorage messageLog = (JdbcTransactionalStorage) transactionStorage;
String jmsRealmName = messageLog.getJmsRealName();
String expiryDateField = messageLog.getExpiryDateField();
String tableName = messageLog.getTableName();
String keyField = messageLog.getKeyField();
String typeField = messageLog.getTypeField();
MessageLogObject mlo = new MessageLogObject(jmsRealmName, tableName, expiryDateField, keyField, typeField);
if (!messageLogs.contains(mlo)) {
messageLogs.add(mlo);
}
}
}
}
}
}
for (Iterator iter = messageLogs.iterator(); iter.hasNext(); ) {
MessageLogObject mlo = (MessageLogObject) iter.next();
setJmsRealm(mlo.getJmsRealmName());
DirectQuerySender qs;
qs = (DirectQuerySender) ibisManager.getIbisContext().createBeanAutowireByName(DirectQuerySender.class);
qs.setJmsRealm(mlo.getJmsRealmName());
String deleteQuery;
if (qs.getDatabaseType() == DbmsSupportFactory.DBMS_MSSQLSERVER) {
deleteQuery = "DELETE FROM " + mlo.getTableName() + " WHERE " + mlo.getKeyField() + " IN (SELECT " + mlo.getKeyField() + " FROM " + mlo.getTableName() + " WITH (rowlock,updlock,readpast) WHERE " + mlo.getTypeField() + " IN ('" + JdbcTransactionalStorage.TYPE_MESSAGELOG_PIPE + "','" + JdbcTransactionalStorage.TYPE_MESSAGELOG_RECEIVER + "') AND " + mlo.getExpiryDateField() + " < CONVERT(datetime, '" + formattedDate + "', 120))";
} else {
deleteQuery = "DELETE FROM " + mlo.getTableName() + " WHERE " + mlo.getTypeField() + " IN ('" + JdbcTransactionalStorage.TYPE_MESSAGELOG_PIPE + "','" + JdbcTransactionalStorage.TYPE_MESSAGELOG_RECEIVER + "') AND " + mlo.getExpiryDateField() + " < TO_TIMESTAMP('" + formattedDate + "', 'YYYY-MM-DD HH24:MI:SS')";
}
qs = null;
setQuery(deleteQuery);
setQueryTimeout(900);
executeQueryJob(ibisManager);
}
}
use of nl.nn.adapterframework.core.ITransactionalStorage in project iaf by ibissource.
the class ReceiverBase method retryMessage.
public void retryMessage(String messageId) throws ListenerException {
if (getErrorStorage() == null) {
throw new ListenerException(getLogPrefix() + "has no errorStorage, cannot retry messageId [" + messageId + "]");
}
PlatformTransactionManager txManager = getTxManager();
// TransactionStatus txStatus = txManager.getTransaction(TXNEW);
IbisTransaction itx = new IbisTransaction(txManager, TXNEW_PROC, "receiver [" + getName() + "]");
TransactionStatus txStatus = itx.getStatus();
Map threadContext = new HashMap();
Object msg = null;
try {
try {
ITransactionalStorage errorStorage = getErrorStorage();
msg = errorStorage.getMessage(messageId);
processRawMessage(getListener(), msg, threadContext, -1, true);
} catch (Throwable t) {
txStatus.setRollbackOnly();
throw new ListenerException(t);
} finally {
txManager.commit(txStatus);
}
} catch (ListenerException e) {
txStatus = txManager.getTransaction(TXNEW_CTRL);
try {
if (msg instanceof Serializable) {
String correlationId = (String) threadContext.get(IPipeLineSession.businessCorrelationIdKey);
String receivedDateStr = (String) threadContext.get(IPipeLineSession.tsReceivedKey);
if (receivedDateStr == null) {
log.warn(getLogPrefix() + IPipeLineSession.tsReceivedKey + " is unknown, cannot update comments");
} else {
Date receivedDate = DateUtils.parseToDate(receivedDateStr, DateUtils.FORMAT_FULL_GENERIC);
errorStorage.deleteMessage(messageId);
errorStorage.storeMessage(messageId, correlationId, receivedDate, "after retry: " + e.getMessage(), null, (Serializable) msg);
}
} else {
log.warn(getLogPrefix() + "retried message is not serializable, cannot update comments");
}
} catch (SenderException e1) {
txStatus.setRollbackOnly();
log.warn(getLogPrefix() + "could not update comments in errorStorage", e1);
} finally {
txManager.commit(txStatus);
}
throw e;
}
}
use of nl.nn.adapterframework.core.ITransactionalStorage in project iaf by ibissource.
the class MessageSendingPipe method stop.
public void stop() {
if (StringUtils.isEmpty(getStubFileName())) {
log.info(getLogPrefix(null) + "is closing");
try {
getSender().close();
} catch (SenderException e) {
log.warn(getLogPrefix(null) + "exception closing sender", e);
}
if (getListener() != null) {
try {
log.info(getLogPrefix(null) + "is closing; closing listener");
getListener().close();
} catch (ListenerException e) {
log.warn(getLogPrefix(null) + "Exception closing listener", e);
}
}
}
ITransactionalStorage messageLog = getMessageLog();
if (messageLog != null) {
try {
messageLog.close();
} catch (Exception e) {
log.warn(getLogPrefix(null) + "Exception closing messageLog", e);
}
}
}
use of nl.nn.adapterframework.core.ITransactionalStorage in project iaf by ibissource.
the class ShowConfigurationStatus method mapAdapterReceivers.
private ArrayList<Object> mapAdapterReceivers(Adapter adapter, boolean showPendingMsgCount) {
ArrayList<Object> receivers = new ArrayList<Object>();
Iterator<?> recIt = adapter.getReceiverIterator();
if (recIt.hasNext()) {
while (recIt.hasNext()) {
IReceiver receiver = (IReceiver) recIt.next();
Map<String, Object> receiverInfo = new HashMap<String, Object>();
RunStateEnum receiverRunState = receiver.getRunState();
receiverInfo.put("started", receiverRunState.equals(RunStateEnum.STARTED));
receiverInfo.put("state", receiverRunState.toString().toLowerCase().replace("*", ""));
receiverInfo.put("name", receiver.getName());
receiverInfo.put("class", ClassUtils.nameOf(receiver));
Map<String, Object> messages = new HashMap<String, Object>(3);
messages.put("received", receiver.getMessagesReceived());
messages.put("retried", receiver.getMessagesRetried());
messages.put("rejected", receiver.getMessagesRejected());
receiverInfo.put("messages", messages);
ISender sender = null;
if (receiver instanceof ReceiverBase) {
ReceiverBase rb = (ReceiverBase) receiver;
IListener listener = rb.getListener();
receiverInfo.put("listenerClass", ClassUtils.nameOf(listener));
if (listener instanceof HasPhysicalDestination) {
String pd = ((HasPhysicalDestination) rb.getListener()).getPhysicalDestinationName();
receiverInfo.put("listenerDestination", pd);
}
if (listener instanceof HasSender) {
sender = ((HasSender) listener).getSender();
}
// receiverInfo.put("hasInprocessStorage", ""+(rb.getInProcessStorage()!=null));
ITransactionalStorage ts;
ts = rb.getErrorStorage();
receiverInfo.put("hasErrorStorage", (ts != null));
if (ts != null) {
try {
if (showCountErrorStore) {
receiverInfo.put("errorStorageCount", ts.getMessageCount());
} else {
receiverInfo.put("errorStorageCount", "?");
}
} catch (Exception e) {
log.warn(e);
receiverInfo.put("errorStorageCount", "error");
}
}
ts = rb.getMessageLog();
receiverInfo.put("hasMessageLog", (ts != null));
if (ts != null) {
try {
if (showCountMessageLog) {
receiverInfo.put("messageLogCount", ts.getMessageCount());
} else {
receiverInfo.put("messageLogCount", "?");
}
} catch (Exception e) {
log.warn(e);
receiverInfo.put("messageLogCount", "error");
}
}
boolean isRestListener = (listener instanceof RestListener);
receiverInfo.put("isRestListener", isRestListener);
if (isRestListener) {
RestListener rl = (RestListener) listener;
receiverInfo.put("restUriPattern", rl.getRestUriPattern());
receiverInfo.put("isView", (rl.isView() == null ? false : rl.isView()));
}
if ((listener instanceof JmsListenerBase) && showPendingMsgCount) {
JmsListenerBase jlb = (JmsListenerBase) listener;
JmsMessageBrowser jmsBrowser;
if (StringUtils.isEmpty(jlb.getMessageSelector())) {
jmsBrowser = new JmsMessageBrowser();
} else {
jmsBrowser = new JmsMessageBrowser(jlb.getMessageSelector());
}
jmsBrowser.setName("MessageBrowser_" + jlb.getName());
jmsBrowser.setJmsRealm(jlb.getJmsRealName());
jmsBrowser.setDestinationName(jlb.getDestinationName());
jmsBrowser.setDestinationType(jlb.getDestinationType());
String numMsgs;
try {
int messageCount = jmsBrowser.getMessageCount();
numMsgs = String.valueOf(messageCount);
} catch (Throwable t) {
log.warn(t);
numMsgs = "?";
}
receiverInfo.put("pendingMessagesCount", numMsgs);
}
boolean isEsbJmsFFListener = false;
if (listener instanceof EsbJmsListener) {
EsbJmsListener ejl = (EsbJmsListener) listener;
if (ejl.getMessageProtocol().equalsIgnoreCase("FF")) {
isEsbJmsFFListener = true;
}
if (showPendingMsgCount) {
String esbNumMsgs = EsbUtils.getQueueMessageCount(ejl);
if (esbNumMsgs == null) {
esbNumMsgs = "?";
}
receiverInfo.put("esbPendingMessagesCount", esbNumMsgs);
}
}
receiverInfo.put("isEsbJmsFFListener", isEsbJmsFFListener);
}
if (receiver instanceof HasSender) {
ISender rsender = ((HasSender) receiver).getSender();
if (rsender != null) {
// this sender has preference, but avoid overwriting listeners sender with null
sender = rsender;
}
}
if (sender != null) {
receiverInfo.put("senderName", sender.getName());
receiverInfo.put("senderClass", ClassUtils.nameOf(sender));
if (sender instanceof HasPhysicalDestination) {
String pd = ((HasPhysicalDestination) sender).getPhysicalDestinationName();
receiverInfo.put("senderDestination", pd);
}
}
if (receiver instanceof IThreadCountControllable) {
IThreadCountControllable tcc = (IThreadCountControllable) receiver;
if (tcc.isThreadCountReadable()) {
receiverInfo.put("threadCount", tcc.getCurrentThreadCount());
receiverInfo.put("maxThreadCount", tcc.getMaxThreadCount());
}
if (tcc.isThreadCountControllable()) {
receiverInfo.put("threadCountControllable", "true");
}
}
receivers.add(receiverInfo);
}
}
return receivers;
}
Aggregations