use of nl.nn.adapterframework.core.ISender 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.ISender in project iaf by ibissource.
the class SenderSeries method configure.
public void configure() throws ConfigurationException {
for (Iterator<ISender> it = getSenderIterator(); it.hasNext(); ) {
ISender sender = it.next();
if (sender instanceof PipeAware) {
((PipeAware) sender).setPipe(getPipe());
}
sender.configure();
}
super.configure();
}
use of nl.nn.adapterframework.core.ISender in project iaf by ibissource.
the class ShadowSender method doSendMessage.
/**
* We override this from the parallel sender as we should only execute the original and shadowsenders here!
*/
@Override
public String doSendMessage(String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
Guard guard = new Guard();
Map<ISender, ParallelSenderExecutor> executorMap = new HashMap<ISender, ParallelSenderExecutor>();
TaskExecutor executor = createTaskExecutor();
for (Iterator<ISender> it = getExecutableSenders(); it.hasNext(); ) {
ISender sender = it.next();
// Create a new ParameterResolutionContext to be thread safe, see
// documentation on constructor of ParameterResolutionContext
// (parameter cacheXmlSource).
// Testing also showed that disabling caching is better for
// performance. At least when testing with a lot of large messages
// in parallel. This might be due to the fact that objects can be
// garbage collected earlier. OutOfMemoryErrors occur much
// faster when caching is enabled. Testing was done by sending 10
// messages of 1 MB concurrently to a pipeline which will process
// the message in parallel with 10 SenderWrappers (containing a
// XsltSender and IbisLocalSender).
ParameterResolutionContext newPrc = new ParameterResolutionContext(prc.getInput(), prc.getSession(), prc.isNamespaceAware(), prc.isXslt2(), false);
guard.addResource();
ParallelSenderExecutor pse = new ParallelSenderExecutor(sender, correlationID, message, newPrc, guard, getStatisticsKeeper(sender));
executorMap.put(sender, pse);
executor.execute(pse);
}
try {
guard.waitForAllResources();
} catch (InterruptedException e) {
throw new SenderException(getLogPrefix() + "was interupted", e);
}
ParallelSenderExecutor originalSender = null;
XmlBuilder resultsXml = new XmlBuilder("results");
resultsXml.addAttribute("correlationID", correlationID);
resultsXml.addAttribute("adapter", getPipe().getAdapter().getName());
XmlBuilder originalMessageXml = new XmlBuilder("originalMessage");
originalMessageXml.setValue(XmlUtils.skipXmlDeclaration(message), false);
resultsXml.addSubElement(originalMessageXml);
// First loop through all (Shadow)Senders and handle their results
for (Iterator<ISender> it = getExecutableSenders(); it.hasNext(); ) {
ISender sender = it.next();
ParallelSenderExecutor pse = (ParallelSenderExecutor) executorMap.get(sender);
XmlBuilder resultXml;
if (sender.getName() != null && sender.getName().equalsIgnoreCase(getOriginalSender())) {
originalSender = pse;
resultXml = new XmlBuilder("originalResult");
} else {
resultXml = new XmlBuilder("shadowResult");
}
StatisticsKeeper sk = getStatisticsKeeper(sender);
resultXml.addAttribute("duration", sk.getLast() + sk.getUnits());
resultXml.addAttribute("count", sk.getCount());
resultXml.addAttribute("senderClass", ClassUtils.nameOf(sender));
resultXml.addAttribute("senderName", sender.getName());
Throwable throwable = pse.getThrowable();
if (throwable == null) {
Object result = pse.getReply();
if (result == null) {
resultXml.addAttribute("type", "null");
} else {
resultXml.addAttribute("type", ClassUtils.nameOf(result));
resultXml.setValue(XmlUtils.skipXmlDeclaration(result.toString()), false);
}
} else {
resultXml.addAttribute("type", ClassUtils.nameOf(throwable));
resultXml.setValue(throwable.getMessage());
}
resultsXml.addSubElement(resultXml);
}
// cause an SenderException regardless of the results of the ShadowSenders.
if (originalSender == null) {
// In theory this should never happen!
throw new SenderException("no originalSender found");
}
// The messages have been processed, now the results need to be stored somewhere.
try {
if (resultISender instanceof ISenderWithParameters) {
ParameterResolutionContext newPrc = new ParameterResolutionContext(resultsXml.toXML(), prc.getSession());
((ISenderWithParameters) resultISender).sendMessage(correlationID, resultsXml.toXML(), newPrc);
} else {
resultISender.sendMessage(correlationID, resultsXml.toXML());
}
} catch (SenderException se) {
log.warn("failed to send ShadowSender result to [" + resultISender.getName() + "]");
}
if (originalSender.getThrowable() != null) {
throw new SenderException(originalSender.getThrowable());
} else {
return originalSender.getReply().toString();
}
}
use of nl.nn.adapterframework.core.ISender in project iaf by ibissource.
the class ParallelSenders method doSendMessage.
public String doSendMessage(String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
Guard guard = new Guard();
Map<ISender, ParallelSenderExecutor> executorMap = new HashMap<ISender, ParallelSenderExecutor>();
TaskExecutor executor = createTaskExecutor();
for (Iterator<ISender> it = getSenderIterator(); it.hasNext(); ) {
ISender sender = it.next();
// Create a new ParameterResolutionContext to be thread safe, see
// documentation on constructor of ParameterResolutionContext
// (parameter cacheXmlSource).
// Testing also showed that disabling caching is better for
// performance. At least when testing with a lot of large messages
// in parallel. This might be due to the fact that objects can be
// garbage collected earlier. OutOfMemoryErrors occur much
// faster when caching is enabled. Testing was done by sending 10
// messages of 1 MB concurrently to a pipeline which will process
// the message in parallel with 10 SenderWrappers (containing a
// XsltSender and IbisLocalSender).
ParameterResolutionContext newPrc = new ParameterResolutionContext(prc.getInput(), prc.getSession(), prc.isNamespaceAware(), prc.isXslt2(), false);
guard.addResource();
ParallelSenderExecutor pse = new ParallelSenderExecutor(sender, correlationID, message, newPrc, guard, getStatisticsKeeper(sender));
executorMap.put(sender, pse);
executor.execute(pse);
}
try {
guard.waitForAllResources();
} catch (InterruptedException e) {
throw new SenderException(getLogPrefix() + "was interupted", e);
}
XmlBuilder resultsXml = new XmlBuilder("results");
for (Iterator<ISender> it = getSenderIterator(); it.hasNext(); ) {
ISender sender = it.next();
ParallelSenderExecutor pse = (ParallelSenderExecutor) executorMap.get(sender);
XmlBuilder resultXml = new XmlBuilder("result");
resultXml.addAttribute("senderClass", ClassUtils.nameOf(sender));
resultXml.addAttribute("senderName", sender.getName());
Throwable throwable = pse.getThrowable();
if (throwable == null) {
Object result = pse.getReply();
if (result == null) {
resultXml.addAttribute("type", "null");
} else {
resultXml.addAttribute("type", ClassUtils.nameOf(result));
resultXml.setValue(XmlUtils.skipXmlDeclaration(result.toString()), false);
}
} else {
resultXml.addAttribute("type", ClassUtils.nameOf(throwable));
resultXml.setValue(throwable.getMessage());
}
resultsXml.addSubElement(resultXml);
}
return resultsXml.toXML();
}
use of nl.nn.adapterframework.core.ISender in project iaf by ibissource.
the class TestTool method executeSenderWrite.
private static int executeSenderWrite(String stepDisplayName, Map queues, Map writers, String queueName, String senderType, String fileContent) {
int result = RESULT_ERROR;
Map senderInfo = (Map) queues.get(queueName);
ISender sender = (ISender) senderInfo.get(senderType + "Sender");
Boolean convertExceptionToMessage = (Boolean) senderInfo.get("convertExceptionToMessage");
ParameterResolutionContext parameterResolutionContext = (ParameterResolutionContext) senderInfo.get("parameterResolutionContext");
SenderThread senderThread;
if (parameterResolutionContext == null) {
senderThread = new SenderThread(sender, fileContent, convertExceptionToMessage.booleanValue());
} else {
senderThread = new SenderThread((ISenderWithParameters) sender, fileContent, parameterResolutionContext, convertExceptionToMessage.booleanValue());
}
senderThread.start();
senderInfo.put(senderType + "SenderThread", senderThread);
debugPipelineMessage(stepDisplayName, "Successfully started thread writing to '" + queueName + "':", fileContent, writers);
logger.debug("Successfully started thread writing to '" + queueName + "'");
result = RESULT_OK;
return result;
}
Aggregations