Search in sources :

Example 31 with Adapter

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"));
}
Also used : Adapter(nl.nn.adapterframework.core.Adapter) IReceiver(nl.nn.adapterframework.core.IReceiver) Iterator(java.util.Iterator) XmlBuilder(nl.nn.adapterframework.util.XmlBuilder) StatisticsKeeper(nl.nn.adapterframework.statistics.StatisticsKeeper) IReceiverStatistics(nl.nn.adapterframework.core.IReceiverStatistics) SenderException(nl.nn.adapterframework.core.SenderException)

Aggregations

Adapter (nl.nn.adapterframework.core.Adapter)31 IAdapter (nl.nn.adapterframework.core.IAdapter)24 Iterator (java.util.Iterator)10 Path (javax.ws.rs.Path)10 Produces (javax.ws.rs.Produces)10 ReceiverBase (nl.nn.adapterframework.receivers.ReceiverBase)10 RolesAllowed (javax.annotation.security.RolesAllowed)9 IReceiver (nl.nn.adapterframework.core.IReceiver)9 GET (javax.ws.rs.GET)8 PipeLine (nl.nn.adapterframework.core.PipeLine)8 ArrayList (java.util.ArrayList)7 Configuration (nl.nn.adapterframework.configuration.Configuration)7 IOException (java.io.IOException)6 HashMap (java.util.HashMap)6 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)5 IListener (nl.nn.adapterframework.core.IListener)5 XmlBuilder (nl.nn.adapterframework.util.XmlBuilder)5 ServletException (javax.servlet.ServletException)4 Response (javax.ws.rs.core.Response)4 IPipe (nl.nn.adapterframework.core.IPipe)4