Search in sources :

Example 6 with StatisticsKeeper

use of nl.nn.adapterframework.statistics.StatisticsKeeper in project iaf by ibissource.

the class PipeLine method addPipe.

/**
 * Register an Pipe at this pipeline.
 * The name is also put in the globalForwards table (with
 * forward-name=pipename and forward-path=pipename, so that
 * pipe can look for a specific pipe-name. If already a globalForward
 * exists under that name, the pipe is NOT added, allowing globalForwards
 * to prevail.
 * @see nl.nn.adapterframework.pipes.AbstractPipe
 */
public void addPipe(IPipe pipe) throws ConfigurationException {
    if (pipe == null) {
        throw new ConfigurationException("pipe to be added is null, pipelineTable size [" + pipesByName.size() + "]");
    }
    if (pipe instanceof IExtendedPipe && !((IExtendedPipe) pipe).isActive()) {
        log.debug("Pipe [" + pipe.getName() + "] is not active, therefore not included in configuration");
        return;
    }
    String name = pipe.getName();
    if (StringUtils.isEmpty(name)) {
        throw new ConfigurationException("pipe [" + pipe.getClass().getName() + "] to be added has no name, pipelineTable size [" + pipesByName.size() + "]");
    }
    IPipe current = getPipe(name);
    if (current != null) {
        throw new ConfigurationException("pipe [" + name + "] defined more then once");
    }
    pipesByName.put(name, pipe);
    pipes.add(pipe);
    if (pipe.getMaxThreads() > 0) {
        pipeWaitingStatistics.put(name, new StatisticsKeeper(name));
    }
    log.debug("added pipe [" + pipe.toString() + "]");
    if (!isForceFixedForwarding()) {
        if (globalForwards.get(name) == null) {
            PipeForward pw = new PipeForward();
            pw.setName(name);
            pw.setPath(name);
            registerForward(pw);
        } else {
            log.info("already had a pipeForward with name [" + name + "] skipping the implicit one to Pipe [" + pipe.getName() + "]");
        }
    }
}
Also used : ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) SizeStatisticsKeeper(nl.nn.adapterframework.statistics.SizeStatisticsKeeper) StatisticsKeeper(nl.nn.adapterframework.statistics.StatisticsKeeper)

Example 7 with StatisticsKeeper

use of nl.nn.adapterframework.statistics.StatisticsKeeper in project iaf by ibissource.

the class PipeLine method configure.

public void configure(IPipe pipe) throws ConfigurationException {
    try {
        if (pipe instanceof IExtendedPipe) {
            IExtendedPipe epipe = (IExtendedPipe) pipe;
            epipe.configure(this);
            if (epipe.getDurationThreshold() >= 0) {
                epipe.registerEvent(IExtendedPipe.LONG_DURATION_MONITORING_EVENT);
            }
            epipe.registerEvent(IExtendedPipe.PIPE_EXCEPTION_MONITORING_EVENT);
            if (getMessageSizeWarnNum() >= 0) {
                epipe.registerEvent(IExtendedPipe.MESSAGE_SIZE_MONITORING_EVENT);
            }
            if (epipe.hasSizeStatistics()) {
                if (pipe instanceof AbstractPipe) {
                    AbstractPipe aPipe = (AbstractPipe) pipe;
                    if (aPipe.getInSizeStatDummyObject() != null) {
                        pipeSizeStats.put(aPipe.getInSizeStatDummyObject().getName(), new SizeStatisticsKeeper(aPipe.getInSizeStatDummyObject().getName()));
                    }
                    if (aPipe.getOutSizeStatDummyObject() != null) {
                        pipeSizeStats.put(aPipe.getOutSizeStatDummyObject().getName(), new SizeStatisticsKeeper(aPipe.getOutSizeStatDummyObject().getName()));
                    }
                } else {
                    pipeSizeStats.put(pipe.getName(), new SizeStatisticsKeeper(pipe.getName()));
                }
            }
        } else {
            pipe.configure();
        }
        if (pipe instanceof MessageSendingPipe) {
            MessageSendingPipe messageSendingPipe = (MessageSendingPipe) pipe;
            if (messageSendingPipe.getInputValidator() != null) {
                configure(messageSendingPipe.getInputValidator());
            }
            if (messageSendingPipe.getOutputValidator() != null) {
                configure(messageSendingPipe.getOutputValidator());
            }
            if (messageSendingPipe.getInputWrapper() != null) {
                configure(messageSendingPipe.getInputWrapper());
            }
            if (messageSendingPipe.getOutputWrapper() != null) {
                configure(messageSendingPipe.getOutputWrapper());
            }
            if (messageSendingPipe.getMessageLog() != null) {
                pipeStatistics.put(messageSendingPipe.getMessageLog().getName(), new StatisticsKeeper(messageSendingPipe.getMessageLog().getName()));
            }
        }
        pipeStatistics.put(pipe.getName(), new StatisticsKeeper(pipe.getName()));
    // congestionSensors.addSensor(pipe);
    } catch (Throwable t) {
        if (t instanceof ConfigurationException) {
            throw (ConfigurationException) t;
        }
        throw new ConfigurationException("Exception configuring Pipe [" + pipe.getName() + "]", t);
    }
    if (log.isDebugEnabled()) {
        log.debug("Pipeline of [" + owner.getName() + "]: Pipe [" + pipe.getName() + "] successfully configured: [" + pipe.toString() + "]");
    }
}
Also used : AbstractPipe(nl.nn.adapterframework.pipes.AbstractPipe) MessageSendingPipe(nl.nn.adapterframework.pipes.MessageSendingPipe) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) SizeStatisticsKeeper(nl.nn.adapterframework.statistics.SizeStatisticsKeeper) SizeStatisticsKeeper(nl.nn.adapterframework.statistics.SizeStatisticsKeeper) StatisticsKeeper(nl.nn.adapterframework.statistics.StatisticsKeeper)

Example 8 with StatisticsKeeper

use of nl.nn.adapterframework.statistics.StatisticsKeeper in project iaf by ibissource.

the class ReceiverBase method iterateOverStatistics.

public void iterateOverStatistics(StatisticsKeeperIterationHandler hski, Object data, int action) throws SenderException {
    Object recData = hski.openGroup(data, getName(), "receiver");
    hski.handleScalar(recData, "messagesReceived", getMessagesReceived());
    hski.handleScalar(recData, "messagesRetried", getMessagesRetried());
    hski.handleScalar(recData, "messagesRejected", numRejected.getValue());
    hski.handleScalar(recData, "messagesReceivedThisInterval", numReceived.getIntervalValue());
    hski.handleScalar(recData, "messagesRetriedThisInterval", numRetried.getIntervalValue());
    hski.handleScalar(recData, "messagesRejectedThisInterval", numRejected.getIntervalValue());
    numReceived.performAction(action);
    numRetried.performAction(action);
    numRejected.performAction(action);
    Iterator statsIter = getProcessStatisticsIterator();
    Object pstatData = hski.openGroup(recData, null, "procStats");
    if (statsIter != null) {
        while (statsIter.hasNext()) {
            StatisticsKeeper pstat = (StatisticsKeeper) statsIter.next();
            hski.handleStatisticsKeeper(pstatData, pstat);
            pstat.performAction(action);
        }
    }
    hski.closeGroup(pstatData);
    statsIter = getIdleStatisticsIterator();
    if (statsIter != null) {
        Object istatData = hski.openGroup(recData, null, "idleStats");
        while (statsIter.hasNext()) {
            StatisticsKeeper pstat = (StatisticsKeeper) statsIter.next();
            hski.handleStatisticsKeeper(istatData, pstat);
            pstat.performAction(action);
        }
        hski.closeGroup(istatData);
    }
    statsIter = getQueueingStatisticsIterator();
    if (statsIter != null) {
        Object qstatData = hski.openGroup(recData, null, "queueingStats");
        while (statsIter.hasNext()) {
            StatisticsKeeper qstat = (StatisticsKeeper) statsIter.next();
            hski.handleStatisticsKeeper(qstatData, qstat);
            qstat.performAction(action);
        }
        hski.closeGroup(qstatData);
    }
    hski.closeGroup(recData);
}
Also used : Iterator(java.util.Iterator) StatisticsKeeper(nl.nn.adapterframework.statistics.StatisticsKeeper) INamedObject(nl.nn.adapterframework.core.INamedObject)

Example 9 with StatisticsKeeper

use of nl.nn.adapterframework.statistics.StatisticsKeeper in project iaf by ibissource.

the class SchedulerAdapter method getJobRunStatistics.

public XmlBuilder getJobRunStatistics(JobDef jobdef) {
    XmlBuilder jobRunStatistics = new XmlBuilder("jobRunStatistics");
    if (jobdef != null) {
        StatisticsKeeper statsKeeper = jobdef.getStatisticsKeeper();
        if (statsKeeper != null) {
            XmlBuilder jobRunDuration = statsKeeper.toXml("jobRunDuration", false, tf, pf);
            jobRunStatistics.addSubElement(jobRunDuration);
        }
    }
    return jobRunStatistics;
}
Also used : XmlBuilder(nl.nn.adapterframework.util.XmlBuilder) StatisticsKeeper(nl.nn.adapterframework.statistics.StatisticsKeeper)

Example 10 with StatisticsKeeper

use of nl.nn.adapterframework.statistics.StatisticsKeeper 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();
    }
}
Also used : HashMap(java.util.HashMap) ISenderWithParameters(nl.nn.adapterframework.core.ISenderWithParameters) TaskExecutor(org.springframework.core.task.TaskExecutor) ISender(nl.nn.adapterframework.core.ISender) XmlBuilder(nl.nn.adapterframework.util.XmlBuilder) StatisticsKeeper(nl.nn.adapterframework.statistics.StatisticsKeeper) Guard(nl.nn.adapterframework.util.Guard) SenderException(nl.nn.adapterframework.core.SenderException) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext)

Aggregations

StatisticsKeeper (nl.nn.adapterframework.statistics.StatisticsKeeper)20 PipeRunException (nl.nn.adapterframework.core.PipeRunException)5 PipeRunResult (nl.nn.adapterframework.core.PipeRunResult)5 AbstractPipe (nl.nn.adapterframework.pipes.AbstractPipe)5 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)4 SenderException (nl.nn.adapterframework.core.SenderException)4 HashMap (java.util.HashMap)3 Iterator (java.util.Iterator)3 PipeForward (nl.nn.adapterframework.core.PipeForward)3 SizeStatisticsKeeper (nl.nn.adapterframework.statistics.SizeStatisticsKeeper)3 XmlBuilder (nl.nn.adapterframework.util.XmlBuilder)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Adapter (nl.nn.adapterframework.core.Adapter)2 IExtendedPipe (nl.nn.adapterframework.core.IExtendedPipe)2 IPipe (nl.nn.adapterframework.core.IPipe)2 IReceiver (nl.nn.adapterframework.core.IReceiver)2 IReceiverStatistics (nl.nn.adapterframework.core.IReceiverStatistics)2 ISender (nl.nn.adapterframework.core.ISender)2