use of nl.nn.adapterframework.core.Adapter in project iaf by ibissource.
the class ShowAdapterStatistics method executeSub.
public ActionForward executeSub(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
// Initialize action
initAction(request);
String adapterName = request.getParameter("adapterName");
String deepString = request.getParameter("deep");
boolean deep = "true".equals(deepString);
Adapter adapter = (Adapter) ibisManager.getRegisteredAdapter(adapterName);
XmlBuilder adapterXML = new XmlBuilder("adapterStatistics");
adapterXML.addAttribute("name", adapter.getName());
adapterXML.addAttribute("state", adapter.getRunState().toString());
adapterXML.addAttribute("upSince", adapter.getStatsUpSince());
adapterXML.addAttribute("lastMessageDate", adapter.getLastMessageDate());
adapterXML.addAttribute("messagesInProcess", "" + adapter.getNumOfMessagesInProcess());
adapterXML.addAttribute("messagesProcessed", "" + adapter.getNumOfMessagesProcessed());
adapterXML.addAttribute("messagesInError", "" + adapter.getNumOfMessagesInError());
StatisticsKeeper st = adapter.getStatsMessageProcessingDuration();
adapterXML.addSubElement(statisticsKeeperToXmlBuilder(st, "messageProcessingDuration", deep));
XmlBuilder messagesReceivedByHour = new XmlBuilder("messagesStartProcessingByHour");
adapterXML.addSubElement(messagesReceivedByHour);
long[] numOfMessagesStartProcessingByHour = adapter.getNumOfMessagesStartProcessingByHour();
for (int i = 0; i < numOfMessagesStartProcessingByHour.length; i++) {
XmlBuilder item = new XmlBuilder("item");
messagesReceivedByHour.addSubElement(item);
String startTime;
if (i < 10) {
startTime = "0" + i + ":00";
} else {
startTime = i + ":00";
}
item.addAttribute("startTime", startTime);
item.addAttribute("count", numOfMessagesStartProcessingByHour[i]);
}
Iterator recIt = adapter.getReceiverIterator();
if (recIt.hasNext()) {
XmlBuilder receiversXML = new XmlBuilder("receivers");
while (recIt.hasNext()) {
IReceiver receiver = (IReceiver) recIt.next();
XmlBuilder receiverXML = new XmlBuilder("receiver");
receiversXML.addSubElement(receiverXML);
receiverXML.addAttribute("name", receiver.getName());
receiverXML.addAttribute("class", receiver.getClass().getName());
receiverXML.addAttribute("messagesReceived", "" + receiver.getMessagesReceived());
receiverXML.addAttribute("messagesRetried", "" + receiver.getMessagesRetried());
/*
if (receiver instanceof HasSender) {
ISender sender = ((HasSender) receiver).getSender();
if (sender != null)
receiverXML.addAttribute("senderName", sender.getName());
}
*/
if (receiver instanceof IReceiverStatistics) {
IReceiverStatistics statReceiver = (IReceiverStatistics) receiver;
Iterator statsIter;
statsIter = statReceiver.getProcessStatisticsIterator();
if (statsIter != null) {
XmlBuilder procStatsXML = new XmlBuilder("procStats");
// procStatsXML.addSubElement(statisticsKeeperToXmlBuilder(statReceiver.getResponseSizeStatistics(), "stat"));
while (statsIter.hasNext()) {
StatisticsKeeper pstat = (StatisticsKeeper) statsIter.next();
procStatsXML.addSubElement(statisticsKeeperToXmlBuilder(pstat, "stat", deep));
}
receiverXML.addSubElement(procStatsXML);
}
statsIter = statReceiver.getIdleStatisticsIterator();
if (statsIter != null) {
XmlBuilder procStatsXML = new XmlBuilder("idleStats");
while (statsIter.hasNext()) {
StatisticsKeeper pstat = (StatisticsKeeper) statsIter.next();
procStatsXML.addSubElement(statisticsKeeperToXmlBuilder(pstat, "stat", deep));
}
receiverXML.addSubElement(procStatsXML);
}
}
}
adapterXML.addSubElement(receiversXML);
}
StatisticsKeeperToXml handler = new StatisticsKeeperToXml(adapterXML, deep);
handler.configure();
Object handle = handler.start(null, null, null);
try {
Object pipelineData = handler.openGroup(handle, null, "pipeline");
adapter.getPipeLine().iterateOverStatistics(handler, pipelineData, HasStatistics.STATISTICS_ACTION_FULL);
} catch (SenderException e) {
log.error(e);
} finally {
handler.end(handle);
}
if (log.isDebugEnabled()) {
log.debug("about to set adapterStatistics [" + adapterXML.toXML() + "]");
// XmlBuilder alt = new XmlBuilder("alt");
// StatisticsKeeperToXml hh = new StatisticsKeeperToXml(alt);
// adapter.forEachStatisticsKeeper(hh,HasStatistics.STATISTICS_ACTION_NONE);
// log.debug("alternative ["+alt.toXML()+"]");
}
request.setAttribute("adapterStatistics", adapterXML.toXML());
// Forward control to the specified success URI
log.debug("forward to success");
return (mapping.findForward("success"));
}
Aggregations