Search in sources :

Example 11 with StatisticsKeeper

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

the class MonitoringPipeProcessor method processPipe.

public PipeRunResult processPipe(PipeLine pipeLine, IPipe pipe, String messageId, Object message, IPipeLineSession pipeLineSession) throws PipeRunException {
    PipeRunResult pipeRunResult = null;
    IExtendedPipe pe = null;
    if (pipe instanceof IExtendedPipe) {
        pe = (IExtendedPipe) pipe;
    }
    long pipeStartTime = System.currentTimeMillis();
    if (log.isDebugEnabled()) {
        // for performance reasons
        StringBuffer sb = new StringBuffer();
        String ownerName = pipeLine.getOwner() == null ? "<null>" : pipeLine.getOwner().getName();
        String pipeName = pipe == null ? "<null>" : pipe.getName();
        sb.append("Pipeline of adapter [" + ownerName + "] messageId [" + messageId + "] is about to call pipe [" + pipeName + "]");
        boolean lir = false;
        if (AppConstants.getInstance().getProperty("log.logIntermediaryResults") != null) {
            if (AppConstants.getInstance().getProperty("log.logIntermediaryResults").equalsIgnoreCase("true")) {
                lir = true;
            }
        }
        if (pipe instanceof AbstractPipe) {
            AbstractPipe ap = (AbstractPipe) pipe;
            if (StringUtils.isNotEmpty(ap.getLogIntermediaryResults())) {
                lir = Boolean.valueOf(ap.getLogIntermediaryResults());
            }
        }
        if (lir) {
            sb.append(" current result [" + message + "] ");
        }
        log.debug(sb.toString());
    }
    // start it
    long pipeDuration = -1;
    try {
        pipeRunResult = pipeProcessor.processPipe(pipeLine, pipe, messageId, message, pipeLineSession);
    } catch (PipeRunException pre) {
        if (pe != null) {
            pe.throwEvent(IExtendedPipe.PIPE_EXCEPTION_MONITORING_EVENT);
        }
        throw pre;
    } catch (RuntimeException re) {
        if (pe != null) {
            pe.throwEvent(IExtendedPipe.PIPE_EXCEPTION_MONITORING_EVENT);
        }
        throw new PipeRunException(pipe, "Uncaught runtime exception running pipe '" + (pipe == null ? "null" : pipe.getName()) + "'", re);
    } finally {
        long pipeEndTime = System.currentTimeMillis();
        pipeDuration = pipeEndTime - pipeStartTime;
        StatisticsKeeper sk = pipeLine.getPipeStatistics(pipe);
        if (sk == null) {
            log.warn("Could not get statistics for pipe [+" + pipe.getName() + "]");
        } else {
            sk.addValue(pipeDuration);
        }
        if (pe != null) {
            if (pe.getDurationThreshold() >= 0 && pipeDuration > pe.getDurationThreshold()) {
                durationLog.info("Pipe [" + pe.getName() + "] of [" + pipeLine.getOwner().getName() + "] duration [" + pipeDuration + "] ms exceeds max [" + pe.getDurationThreshold() + "], message [" + message + "]");
                pe.throwEvent(IExtendedPipe.LONG_DURATION_MONITORING_EVENT);
            }
        }
    }
    return pipeRunResult;
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) AbstractPipe(nl.nn.adapterframework.pipes.AbstractPipe) PipeRunException(nl.nn.adapterframework.core.PipeRunException) StatisticsKeeper(nl.nn.adapterframework.statistics.StatisticsKeeper) IExtendedPipe(nl.nn.adapterframework.core.IExtendedPipe)

Example 12 with StatisticsKeeper

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

the class CounterSwitchPipe method doPipe.

public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    String forward = "";
    PipeForward pipeForward = null;
    StatisticsKeeper sk = getPipeLine().getPipeStatistics(this);
    if (sk != null) {
        long count = sk.getCount();
        forward = "" + (getDivisor() - (count % getDivisor()));
    }
    log.debug(getLogPrefix(session) + "determined forward [" + forward + "]");
    pipeForward = findForward(forward);
    if (pipeForward == null) {
        throw new PipeRunException(this, getLogPrefix(null) + "cannot find forward or pipe named [" + forward + "]");
    }
    log.debug(getLogPrefix(session) + "resolved forward [" + forward + "] to path [" + pipeForward.getPath() + "]");
    return new PipeRunResult(pipeForward, input);
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) PipeRunException(nl.nn.adapterframework.core.PipeRunException) StatisticsKeeper(nl.nn.adapterframework.statistics.StatisticsKeeper) PipeForward(nl.nn.adapterframework.core.PipeForward)

Example 13 with StatisticsKeeper

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

the class Adapter method configure.

/*
	 * This function is called by Configuration.registerAdapter,
	 * to make configuration information available to the Adapter. <br/><br/>
	 * This method also performs
	 * a <code>Pipeline.configurePipes()</code>, as to configure the individual pipes.
	 * @see nl.nn.adapterframework.core.Pipeline#configurePipes
	 */
public void configure() throws ConfigurationException {
    configurationSucceeded = false;
    log.debug("configuring adapter [" + getName() + "]");
    messageKeeper = getMessageKeeper();
    statsMessageProcessingDuration = new StatisticsKeeper(getName());
    if (pipeline == null) {
        String msg = "No pipeline configured for adapter [" + getName() + "]";
        messageKeeper.add(msg, MessageKeeperMessage.ERROR_LEVEL);
        throw new ConfigurationException(msg);
    }
    try {
        pipeline.setAdapter(this);
        pipeline.configure();
        messageKeeper.add("Adapter [" + name + "] pipeline successfully configured");
        Iterator<IReceiver> it = receivers.iterator();
        while (it.hasNext()) {
            IReceiver receiver = it.next();
            configureReceiver(receiver);
        }
        configurationSucceeded = true;
    } catch (ConfigurationException e) {
        error(true, "error initializing pipeline", e);
    }
    List<String> hrs = new ArrayList<String>();
    for (IPipe pipe : pipeline.getPipes()) {
        if (pipe instanceof AbstractPipe) {
            AbstractPipe aPipe = (AbstractPipe) pipe;
            if (aPipe.getHideRegex() != null) {
                if (!hrs.contains(aPipe.getHideRegex())) {
                    hrs.add(aPipe.getHideRegex());
                }
            }
        }
    }
    StringBuilder sb = new StringBuilder();
    for (String hr : hrs) {
        if (sb.length() > 0) {
            sb.append("|");
        }
        sb.append("(");
        sb.append(hr);
        sb.append(")");
    }
    if (sb.length() > 0) {
        composedHideRegex = sb.toString();
    }
}
Also used : AbstractPipe(nl.nn.adapterframework.pipes.AbstractPipe) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) ArrayList(java.util.ArrayList) StatisticsKeeper(nl.nn.adapterframework.statistics.StatisticsKeeper)

Example 14 with StatisticsKeeper

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

the class PipeLine method handlePipeStat.

private void handlePipeStat(INamedObject pipe, Map<String, StatisticsKeeper> pipelineStatistics, Object pipeStatsData, StatisticsKeeperIterationHandler handler, boolean deep, int action) throws SenderException {
    if (pipe == null) {
        return;
    }
    StatisticsKeeper pstat = pipelineStatistics.get(pipe.getName());
    handler.handleStatisticsKeeper(pipeStatsData, pstat);
    if (deep && pipe instanceof HasStatistics) {
        ((HasStatistics) pipe).iterateOverStatistics(handler, pipeStatsData, action);
    }
}
Also used : SizeStatisticsKeeper(nl.nn.adapterframework.statistics.SizeStatisticsKeeper) StatisticsKeeper(nl.nn.adapterframework.statistics.StatisticsKeeper) HasStatistics(nl.nn.adapterframework.statistics.HasStatistics)

Example 15 with StatisticsKeeper

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

the class JobDef method configure.

public void configure(Configuration config) throws ConfigurationException {
    MessageKeeper messageKeeper = getMessageKeeper();
    statsKeeper = new StatisticsKeeper(getName());
    if (StringUtils.isEmpty(getFunction())) {
        throw new ConfigurationException("jobdef [" + getName() + "] function must be specified");
    }
    if (!(getFunction().equalsIgnoreCase(JOB_FUNCTION_STOP_ADAPTER) || getFunction().equalsIgnoreCase(JOB_FUNCTION_START_ADAPTER) || getFunction().equalsIgnoreCase(JOB_FUNCTION_STOP_RECEIVER) || getFunction().equalsIgnoreCase(JOB_FUNCTION_START_RECEIVER) || getFunction().equalsIgnoreCase(JOB_FUNCTION_SEND_MESSAGE) || getFunction().equalsIgnoreCase(JOB_FUNCTION_QUERY) || getFunction().equalsIgnoreCase(JOB_FUNCTION_DUMPSTATS) || getFunction().equalsIgnoreCase(JOB_FUNCTION_DUMPSTATSFULL) || getFunction().equalsIgnoreCase(JOB_FUNCTION_CLEANUPDB) || getFunction().equalsIgnoreCase(JOB_FUNCTION_CLEANUPFS) || getFunction().equalsIgnoreCase(JOB_FUNCTION_RECOVER_ADAPTERS) || getFunction().equalsIgnoreCase(JOB_FUNCTION_CHECK_RELOAD))) {
        throw new ConfigurationException("jobdef [" + getName() + "] function [" + getFunction() + "] must be one of [" + JOB_FUNCTION_STOP_ADAPTER + "," + JOB_FUNCTION_START_ADAPTER + "," + JOB_FUNCTION_STOP_RECEIVER + "," + JOB_FUNCTION_START_RECEIVER + "," + JOB_FUNCTION_SEND_MESSAGE + "," + JOB_FUNCTION_QUERY + "," + JOB_FUNCTION_DUMPSTATS + "," + JOB_FUNCTION_DUMPSTATSFULL + "," + JOB_FUNCTION_CLEANUPDB + "," + JOB_FUNCTION_CLEANUPFS + JOB_FUNCTION_RECOVER_ADAPTERS + JOB_FUNCTION_CHECK_RELOAD + "]");
    }
    if (getFunction().equalsIgnoreCase(JOB_FUNCTION_DUMPSTATS)) {
    // nothing special for now
    } else if (getFunction().equalsIgnoreCase(JOB_FUNCTION_DUMPSTATSFULL)) {
    // nothing special for now
    } else if (getFunction().equalsIgnoreCase(JOB_FUNCTION_CLEANUPDB)) {
    // nothing special for now
    } else if (getFunction().equalsIgnoreCase(JOB_FUNCTION_CLEANUPFS)) {
    // nothing special for now
    } else if (getFunction().equalsIgnoreCase(JOB_FUNCTION_RECOVER_ADAPTERS)) {
    // nothing special for now
    } else if (getFunction().equalsIgnoreCase(JOB_FUNCTION_CHECK_RELOAD)) {
    // nothing special for now
    } else if (getFunction().equalsIgnoreCase(JOB_FUNCTION_QUERY)) {
        if (StringUtils.isEmpty(getJmsRealm())) {
            throw new ConfigurationException("jobdef [" + getName() + "] for function [" + getFunction() + "] a jmsRealm must be specified");
        }
    } else {
        if (StringUtils.isEmpty(getAdapterName())) {
            throw new ConfigurationException("jobdef [" + getName() + "] for function [" + getFunction() + "] a adapterName must be specified");
        }
        if (config.getRegisteredAdapter(getAdapterName()) == null) {
            String msg = "Jobdef [" + getName() + "] got error: adapter [" + getAdapterName() + "] not registered.";
            throw new ConfigurationException(msg);
        }
        if (getFunction().equalsIgnoreCase(JOB_FUNCTION_STOP_RECEIVER) || getFunction().equalsIgnoreCase(JOB_FUNCTION_START_RECEIVER)) {
            if (StringUtils.isEmpty(getReceiverName())) {
                throw new ConfigurationException("jobdef [" + getName() + "] for function [" + getFunction() + "] a receiverName must be specified");
            }
            if (StringUtils.isNotEmpty(getReceiverName())) {
                if (!config.isRegisteredReceiver(getAdapterName(), getReceiverName())) {
                    String msg = "Jobdef [" + getName() + "] got error: adapter [" + getAdapterName() + "] receiver [" + getReceiverName() + "] not registered.";
                    throw new ConfigurationException(msg);
                }
            }
        }
    }
    if (getLocker() != null) {
        getLocker().configure();
    }
    txDef = SpringTxManagerProxy.getTransactionDefinition(getTransactionAttributeNum(), getTransactionTimeout());
    messageKeeper.add("job successfully configured");
}
Also used : ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) MessageKeeper(nl.nn.adapterframework.util.MessageKeeper) StatisticsKeeper(nl.nn.adapterframework.statistics.StatisticsKeeper)

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