use of nl.nn.adapterframework.util.XmlBuilder in project iaf by ibissource.
the class SchedulerAdapter method getSchedulerCalendarNamesToXml.
public XmlBuilder getSchedulerCalendarNamesToXml(Scheduler theScheduler) {
XmlBuilder xbRoot = new XmlBuilder("schedulerCalendars");
try {
String[] names = theScheduler.getCalendarNames();
for (int i = 0; i < names.length; i++) {
XmlBuilder el = new XmlBuilder("calendar");
el.setValue(names[i]);
xbRoot.addSubElement(el);
}
} catch (org.quartz.SchedulerException se) {
log.error(se.toString());
}
return xbRoot;
}
use of nl.nn.adapterframework.util.XmlBuilder in project iaf by ibissource.
the class SchedulerAdapter method getTriggerGroupNamesWithTriggersToXml.
public XmlBuilder getTriggerGroupNamesWithTriggersToXml(Scheduler theScheduler) {
XmlBuilder xbRoot = new XmlBuilder("triggerGroups");
try {
// process groups
String[] tgnames = theScheduler.getTriggerGroupNames();
for (int i = 0; i < tgnames.length; i++) {
XmlBuilder el = new XmlBuilder("triggerGroup");
el.addAttribute("name", tgnames[i]);
// process jobs within group
XmlBuilder tgg = new XmlBuilder("triggers");
String[] triggerNames = theScheduler.getTriggerNames(tgnames[i]);
for (int j = 0; j < triggerNames.length; j++) {
XmlBuilder tn = new XmlBuilder("trigger");
tn.addAttribute("name", triggerNames[j]);
// detail of trigger
XmlBuilder td = triggerToXmlBuilder(theScheduler, triggerNames[j], tgnames[i]);
tn.addSubElement(td);
tgg.addSubElement(tn);
}
el.addSubElement(tgg);
xbRoot.addSubElement(el);
}
} catch (org.quartz.SchedulerException se) {
log.error(se);
}
return xbRoot;
}
use of nl.nn.adapterframework.util.XmlBuilder in project iaf by ibissource.
the class SchedulerAdapter method getJobGroupNamesWithJobsToXml.
/**
* Get all jobgroups, jobs within this group, the jobdetail and the
* associated triggers in XML format.
*/
public XmlBuilder getJobGroupNamesWithJobsToXml(Scheduler theScheduler, IbisManager ibisManager) {
XmlBuilder xbRoot = new XmlBuilder("jobGroups");
try {
// process groups
String[] jgnames = theScheduler.getJobGroupNames();
for (int i = 0; i < jgnames.length; i++) {
XmlBuilder el = new XmlBuilder("jobGroup");
el.addAttribute("name", jgnames[i]);
// process jobs within group
XmlBuilder jb = new XmlBuilder("jobs");
String[] jobNames = theScheduler.getJobNames(jgnames[i]);
for (int j = 0; j < jobNames.length; j++) {
XmlBuilder jn = new XmlBuilder("job");
jn.addAttribute("name", jobNames[j]);
// details for job
XmlBuilder jd = jobDetailToXmlBuilder(theScheduler, jobNames[j], jgnames[i]);
jn.addSubElement(jd);
// get the triggers for this job
XmlBuilder tr = getJobTriggers(theScheduler, jobNames[j], jgnames[i]);
jn.addSubElement(tr);
XmlBuilder datamap = jobDataMapToXmlBuilder(theScheduler, jobNames[j], jgnames[i]);
jn.addSubElement(datamap);
jb.addSubElement(jn);
JobDef jobDef = null;
for (Configuration configuration : ibisManager.getConfigurations()) {
jobDef = configuration.getScheduledJob(jobNames[j]);
if (jobDef != null) {
break;
}
}
XmlBuilder ms = getJobMessages(jobDef);
jn.addSubElement(ms);
XmlBuilder jrs = getJobRunStatistics(jobDef);
jn.addSubElement(jrs);
}
el.addSubElement(jb);
xbRoot.addSubElement(el);
}
} catch (org.quartz.SchedulerException se) {
log.error(se);
}
return xbRoot;
}
use of nl.nn.adapterframework.util.XmlBuilder 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.util.XmlBuilder 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();
}
Aggregations