Search in sources :

Example 1 with Semaphore

use of nl.nn.adapterframework.util.Semaphore in project iaf by ibissource.

the class CheckSemaphorePipeProcessor method processPipe.

public PipeRunResult processPipe(PipeLine pipeLine, IPipe pipe, String messageId, Object message, IPipeLineSession pipeLineSession) throws PipeRunException {
    PipeRunResult pipeRunResult;
    Semaphore s = getSemaphore(pipe);
    if (s != null) {
        long waitingDuration = 0;
        try {
            // keep waiting statistics for thread-limited pipes
            long startWaiting = System.currentTimeMillis();
            s.acquire();
            waitingDuration = System.currentTimeMillis() - startWaiting;
            StatisticsKeeper sk = pipeLine.getPipeWaitingStatistics(pipe);
            sk.addValue(waitingDuration);
            pipeRunResult = pipeProcessor.processPipe(pipeLine, pipe, messageId, message, pipeLineSession);
        } catch (InterruptedException e) {
            throw new PipeRunException(pipe, "Interrupted acquiring semaphore", e);
        } finally {
            s.release();
        }
    } else {
        // no restrictions on the maximum number of threads (s==null)
        pipeRunResult = pipeProcessor.processPipe(pipeLine, pipe, messageId, message, pipeLineSession);
    }
    return pipeRunResult;
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) PipeRunException(nl.nn.adapterframework.core.PipeRunException) StatisticsKeeper(nl.nn.adapterframework.statistics.StatisticsKeeper) Semaphore(nl.nn.adapterframework.util.Semaphore)

Example 2 with Semaphore

use of nl.nn.adapterframework.util.Semaphore in project iaf by ibissource.

the class CheckSemaphorePipeLineProcessor method processPipeLine.

@Override
public PipeLineResult processPipeLine(PipeLine pipeLine, String messageId, Message message, PipeLineSession pipeLineSession, String firstPipe) throws PipeRunException {
    PipeLineResult pipeLineResult;
    Semaphore s = getSemaphore(pipeLine);
    if (s != null) {
        long waitingDuration = 0;
        IPipe pipe = pipeLine.getPipe(firstPipe);
        try {
            // keep waiting statistics for thread-limited pipes
            long startWaiting = System.currentTimeMillis();
            s.acquire();
            waitingDuration = System.currentTimeMillis() - startWaiting;
            StatisticsKeeper sk = pipeLine.getPipeWaitingStatistics(pipe);
            sk.addValue(waitingDuration);
            pipeLineResult = pipeLineProcessor.processPipeLine(pipeLine, messageId, message, pipeLineSession, firstPipe);
        } catch (InterruptedException e) {
            throw new PipeRunException(pipe, "Interrupted acquiring PipeLine semaphore", e);
        } finally {
            s.release();
        }
    } else {
        // no restrictions on the maximum number of threads (s==null)
        pipeLineResult = pipeLineProcessor.processPipeLine(pipeLine, messageId, message, pipeLineSession, firstPipe);
    }
    return pipeLineResult;
}
Also used : PipeLineResult(nl.nn.adapterframework.core.PipeLineResult) PipeRunException(nl.nn.adapterframework.core.PipeRunException) StatisticsKeeper(nl.nn.adapterframework.statistics.StatisticsKeeper) Semaphore(nl.nn.adapterframework.util.Semaphore) IPipe(nl.nn.adapterframework.core.IPipe)

Example 3 with Semaphore

use of nl.nn.adapterframework.util.Semaphore in project iaf by ibissource.

the class IteratingPipe method configure.

@Override
public void configure() throws ConfigurationException {
    super.configure();
    msgTransformerPool = TransformerPool.configureTransformer(getLogPrefix(null), this, getNamespaceDefs(), getXpathExpression(), getStyleSheetName(), getOutputType(), !isOmitXmlDeclaration(), getParameterList(), false);
    if (msgTransformerPool != null) {
        preprocessingStatisticsKeeper = new StatisticsKeeper("-> message preprocessing");
    }
    try {
        if (StringUtils.isNotEmpty(getStopConditionXPathExpression())) {
            stopConditionTp = TransformerPool.getInstance(XmlUtils.createXPathEvaluatorSource(null, getStopConditionXPathExpression(), OutputType.XML, false));
            stopConditionStatisticsKeeper = new StatisticsKeeper("-> stop condition determination");
        }
    } catch (TransformerConfigurationException e) {
        throw new ConfigurationException("Cannot compile stylesheet from stopConditionXPathExpression [" + getStopConditionXPathExpression() + "]", e);
    }
    if (getMaxChildThreads() > 0) {
        childThreadSemaphore = new Semaphore(getMaxChildThreads());
    }
    stopForwardConfigured = getForwards() != null && (getForwards().get(StopReason.MAX_ITEMS_REACHED.getForwardName()) != null || getForwards().get(StopReason.STOP_CONDITION_MET.getForwardName()) != null);
}
Also used : TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) StatisticsKeeper(nl.nn.adapterframework.statistics.StatisticsKeeper) Semaphore(nl.nn.adapterframework.util.Semaphore)

Example 4 with Semaphore

use of nl.nn.adapterframework.util.Semaphore in project iaf by ibissource.

the class CheckSemaphorePipeProcessor method getSemaphore.

private Semaphore getSemaphore(IPipe pipe) {
    int maxThreads = pipe.getMaxThreads();
    if (maxThreads > 0) {
        Semaphore s;
        synchronized (pipeThreadCounts) {
            if (pipeThreadCounts.containsKey(pipe)) {
                s = (Semaphore) pipeThreadCounts.get(pipe);
            } else {
                s = new Semaphore(maxThreads);
                pipeThreadCounts.put(pipe, s);
            }
        }
        return s;
    }
    return null;
}
Also used : Semaphore(nl.nn.adapterframework.util.Semaphore)

Example 5 with Semaphore

use of nl.nn.adapterframework.util.Semaphore in project iaf by ibissource.

the class CheckSemaphorePipeProcessor method processPipe.

@Override
protected PipeRunResult processPipe(PipeLine pipeLine, IPipe pipe, Message message, PipeLineSession pipeLineSession, ThrowingFunction<Message, PipeRunResult, PipeRunException> chain) throws PipeRunException {
    PipeRunResult pipeRunResult;
    Semaphore s = getSemaphore(pipe);
    if (s != null) {
        long waitingDuration = 0;
        try {
            // keep waiting statistics for thread-limited pipes
            long startWaiting = System.currentTimeMillis();
            s.acquire();
            waitingDuration = System.currentTimeMillis() - startWaiting;
            StatisticsKeeper sk = pipeLine.getPipeWaitingStatistics(pipe);
            sk.addValue(waitingDuration);
            pipeRunResult = chain.apply(message);
        } catch (InterruptedException e) {
            throw new PipeRunException(pipe, "Interrupted acquiring semaphore", e);
        } finally {
            s.release();
        }
    } else {
        // no restrictions on the maximum number of threads (s==null)
        pipeRunResult = chain.apply(message);
    }
    return pipeRunResult;
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) PipeRunException(nl.nn.adapterframework.core.PipeRunException) StatisticsKeeper(nl.nn.adapterframework.statistics.StatisticsKeeper) Semaphore(nl.nn.adapterframework.util.Semaphore)

Aggregations

Semaphore (nl.nn.adapterframework.util.Semaphore)7 StatisticsKeeper (nl.nn.adapterframework.statistics.StatisticsKeeper)4 PipeRunException (nl.nn.adapterframework.core.PipeRunException)3 PipeRunResult (nl.nn.adapterframework.core.PipeRunResult)2 Connection (java.sql.Connection)1 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)1 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)1 IPipe (nl.nn.adapterframework.core.IPipe)1 PipeLineResult (nl.nn.adapterframework.core.PipeLineResult)1 DefaultTransactionDefinition (org.springframework.transaction.support.DefaultTransactionDefinition)1