Search in sources :

Example 1 with ICacheAdapter

use of nl.nn.adapterframework.cache.ICacheAdapter in project iaf by ibissource.

the class CacheSenderWrapperProcessor method sendMessage.

public String sendMessage(SenderWrapperBase senderWrapperBase, String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
    ICacheAdapter cache = senderWrapperBase.getCache();
    if (cache == null) {
        return senderWrapperProcessor.sendMessage(senderWrapperBase, correlationID, message, prc);
    }
    String key = cache.transformKey(message, prc.getSession());
    if (key == null) {
        if (log.isDebugEnabled())
            log.debug("cache key is null, will not use cache");
        return senderWrapperProcessor.sendMessage(senderWrapperBase, correlationID, message, prc);
    }
    if (log.isDebugEnabled())
        log.debug("cache key [" + key + "]");
    String result = cache.getString(key);
    if (result == null) {
        if (log.isDebugEnabled())
            log.debug("no cached results found using key [" + key + "]");
        result = senderWrapperProcessor.sendMessage(senderWrapperBase, correlationID, message, prc);
        if (log.isDebugEnabled())
            log.debug("caching result using key [" + key + "]");
        String cacheValue = cache.transformValue(result, prc.getSession());
        if (cacheValue == null) {
            if (log.isDebugEnabled())
                log.debug("transformed cache value is null, will not cache");
            return result;
        }
        result = cacheValue;
        cache.putString(key, result);
    } else {
        if (log.isDebugEnabled())
            log.debug("retrieved result from cache using key [" + key + "]");
    }
    return result;
}
Also used : ICacheAdapter(nl.nn.adapterframework.cache.ICacheAdapter)

Example 2 with ICacheAdapter

use of nl.nn.adapterframework.cache.ICacheAdapter in project iaf by ibissource.

the class Adapter method doForEachStatisticsKeeperBody.

private void doForEachStatisticsKeeperBody(StatisticsKeeperIterationHandler hski, Object adapterData, int action) throws SenderException {
    hski.handleScalar(adapterData, "messagesInProcess", getNumOfMessagesInProcess());
    hski.handleScalar(adapterData, "messagesProcessed", getNumOfMessagesProcessed());
    hski.handleScalar(adapterData, "messagesInError", getNumOfMessagesInError());
    hski.handleScalar(adapterData, "messagesProcessedThisInterval", numOfMessagesProcessed.getIntervalValue());
    hski.handleScalar(adapterData, "messagesInErrorThisInterval", numOfMessagesInError.getIntervalValue());
    hski.handleStatisticsKeeper(adapterData, statsMessageProcessingDuration);
    statsMessageProcessingDuration.performAction(action);
    numOfMessagesProcessed.performAction(action);
    numOfMessagesInError.performAction(action);
    Object hourData = hski.openGroup(adapterData, getName(), "processing by hour");
    for (int i = 0; i < getNumOfMessagesStartProcessingByHour().length; i++) {
        String startTime;
        if (i < 10) {
            startTime = "0" + i + ":00";
        } else {
            startTime = i + ":00";
        }
        hski.handleScalar(hourData, startTime, getNumOfMessagesStartProcessingByHour()[i]);
    }
    hski.closeGroup(hourData);
    boolean showDetails = action == HasStatistics.STATISTICS_ACTION_FULL || action == HasStatistics.STATISTICS_ACTION_MARK_FULL || action == HasStatistics.STATISTICS_ACTION_RESET;
    if (showDetails) {
        Object recsData = hski.openGroup(adapterData, null, "receivers");
        Iterator<IReceiver> recIt = getReceiverIterator();
        if (recIt.hasNext()) {
            while (recIt.hasNext()) {
                IReceiver receiver = recIt.next();
                receiver.iterateOverStatistics(hski, recsData, action);
            }
        }
        hski.closeGroup(recsData);
        ICacheAdapter cache = pipeline.getCache();
        if (cache != null && cache instanceof HasStatistics) {
            ((HasStatistics) cache).iterateOverStatistics(hski, recsData, action);
        }
        Object pipelineData = hski.openGroup(adapterData, null, "pipeline");
        getPipeLine().iterateOverStatistics(hski, pipelineData, action);
        hski.closeGroup(pipelineData);
    }
}
Also used : ICacheAdapter(nl.nn.adapterframework.cache.ICacheAdapter) HasStatistics(nl.nn.adapterframework.statistics.HasStatistics)

Example 3 with ICacheAdapter

use of nl.nn.adapterframework.cache.ICacheAdapter in project iaf by ibissource.

the class CachePipeLineProcessor method processPipeLine.

public PipeLineResult processPipeLine(PipeLine pipeLine, String messageId, String message, IPipeLineSession pipeLineSession, String firstPipe) throws PipeRunException {
    ICacheAdapter cache = pipeLine.getCache();
    if (cache == null) {
        return pipeLineProcessor.processPipeLine(pipeLine, messageId, message, pipeLineSession, firstPipe);
    }
    String key = cache.transformKey(message, pipeLineSession);
    if (key == null) {
        if (log.isDebugEnabled())
            log.debug("cache key is null, will not use cache");
        return pipeLineProcessor.processPipeLine(pipeLine, messageId, message, pipeLineSession, firstPipe);
    }
    if (log.isDebugEnabled())
        log.debug("cache key [" + key + "]");
    String result;
    String state;
    synchronized (cache) {
        result = cache.getString("r" + key);
        state = cache.getString("s" + key);
    }
    if (result != null && state != null) {
        if (log.isDebugEnabled())
            log.debug("retrieved result from cache using key [" + key + "]");
        PipeLineResult prr = new PipeLineResult();
        prr.setState(state);
        prr.setResult(result);
        return prr;
    }
    if (log.isDebugEnabled())
        log.debug("no cached results found using key [" + key + "]");
    PipeLineResult prr = pipeLineProcessor.processPipeLine(pipeLine, messageId, message, pipeLineSession, firstPipe);
    if (log.isDebugEnabled())
        log.debug("caching result using key [" + key + "]");
    String cacheValue = cache.transformValue(prr.getResult(), pipeLineSession);
    synchronized (cache) {
        cache.putString("r" + key, cacheValue);
        cache.putString("s" + key, prr.getState());
    }
    return prr;
}
Also used : ICacheAdapter(nl.nn.adapterframework.cache.ICacheAdapter) PipeLineResult(nl.nn.adapterframework.core.PipeLineResult)

Aggregations

ICacheAdapter (nl.nn.adapterframework.cache.ICacheAdapter)3 PipeLineResult (nl.nn.adapterframework.core.PipeLineResult)1 HasStatistics (nl.nn.adapterframework.statistics.HasStatistics)1