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;
}
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;
}
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);
}
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;
}
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;
}
Aggregations