Search in sources :

Example 1 with IExtendedPipe

use of nl.nn.adapterframework.core.IExtendedPipe in project iaf by ibissource.

the class CheckMessageSizePipeProcessor method checkMessageSize.

private void checkMessageSize(Object message, PipeLine pipeLine, IPipe pipe, boolean input) {
    if (message != null && message instanceof String) {
        int messageLength = message.toString().length();
        if (pipe instanceof AbstractPipe) {
            AbstractPipe aPipe = (AbstractPipe) pipe;
            StatisticsKeeper sizeStat = null;
            if (input) {
                if (aPipe.getInSizeStatDummyObject() != null) {
                    sizeStat = pipeLine.getPipeSizeStatistics(aPipe.getInSizeStatDummyObject());
                }
            } else {
                if (aPipe.getOutSizeStatDummyObject() != null) {
                    sizeStat = pipeLine.getPipeSizeStatistics(aPipe.getOutSizeStatDummyObject());
                }
            }
            if (sizeStat != null) {
                sizeStat.addValue(messageLength);
            }
        }
        if (pipeLine.getMessageSizeWarnNum() >= 0) {
            if (messageLength >= pipeLine.getMessageSizeWarnNum()) {
                String logMessage = "pipe [" + pipe.getName() + "] of adapter [" + pipeLine.getOwner().getName() + "], " + (input ? "input" : "result") + " message size [" + Misc.toFileSize(messageLength) + "] exceeds [" + Misc.toFileSize(pipeLine.getMessageSizeWarnNum()) + "]";
                log.warn(logMessage);
                if (pipe instanceof IExtendedPipe) {
                    IExtendedPipe pe = (IExtendedPipe) pipe;
                    pe.throwEvent(IExtendedPipe.MESSAGE_SIZE_MONITORING_EVENT);
                }
            }
        }
    }
}
Also used : AbstractPipe(nl.nn.adapterframework.pipes.AbstractPipe) StatisticsKeeper(nl.nn.adapterframework.statistics.StatisticsKeeper) IExtendedPipe(nl.nn.adapterframework.core.IExtendedPipe)

Example 2 with IExtendedPipe

use of nl.nn.adapterframework.core.IExtendedPipe 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 3 with IExtendedPipe

use of nl.nn.adapterframework.core.IExtendedPipe in project iaf by ibissource.

the class IbisDebuggerAdvice method debugPipeGetInputFrom.

/**
 * Provides advice for {@link CheckSemaphorePipeProcessor#processPipe(PipeLine pipeLine, IPipe pipe, Message message, PipeLineSession pipeLineSession)}
 * CheckSemaphorePipeProcessor is just after InputOutputPipeProcessor, so it sees the effect of the replacements made by the latter.
 */
public PipeRunResult debugPipeGetInputFrom(ProceedingJoinPoint proceedingJoinPoint, PipeLine pipeLine, IPipe pipe, Message message, PipeLineSession pipeLineSession) throws Throwable {
    if (!isEnabled()) {
        return (PipeRunResult) proceedingJoinPoint.proceed();
    }
    if (pipe instanceof IExtendedPipe) {
        IExtendedPipe pe = (IExtendedPipe) pipe;
        String messageId = pipeLineSession.getMessageId();
        message = debugGetInputFrom(pipeLineSession, messageId, message, pe.getGetInputFromSessionKey(), pe.getGetInputFromFixedValue(), pe.getEmptyInputReplacement());
    }
    Object[] args = proceedingJoinPoint.getArgs();
    args[2] = message;
    // the PipeRunResult contains the original result, before replacing via preserveInput
    return (PipeRunResult) proceedingJoinPoint.proceed(args);
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) IExtendedPipe(nl.nn.adapterframework.core.IExtendedPipe) INamedObject(nl.nn.adapterframework.core.INamedObject)

Example 4 with IExtendedPipe

use of nl.nn.adapterframework.core.IExtendedPipe in project iaf by ibissource.

the class IbisDebuggerAdvice method debugPipeInputOutputAbort.

/**
 * Provides advice for {@link InputOutputPipeProcessor#processPipe(PipeLine pipeLine, IPipe pipe, Message message, PipeLineSession pipeLineSession)}
 */
public PipeRunResult debugPipeInputOutputAbort(ProceedingJoinPoint proceedingJoinPoint, PipeLine pipeLine, IPipe pipe, Message message, PipeLineSession pipeLineSession) throws Throwable {
    if (!isEnabled()) {
        return (PipeRunResult) proceedingJoinPoint.proceed();
    }
    String messageId = pipeLineSession.getMessageId();
    message = ibisDebugger.pipeInput(pipeLine, pipe, messageId, message);
    PipeRunResult pipeRunResult = null;
    try {
        Object[] args = proceedingJoinPoint.getArgs();
        args[2] = message;
        // in case of 'preserveInput', this result is already replaced with the preserved input
        pipeRunResult = (PipeRunResult) proceedingJoinPoint.proceed(args);
    } catch (Throwable throwable) {
        throw ibisDebugger.pipeAbort(pipeLine, pipe, messageId, throwable);
    }
    if (pipe instanceof IExtendedPipe && ((IExtendedPipe) pipe).isPreserveInput()) {
        // signal in the debugger that the result of the pipe has been replaced with the original input
        pipeRunResult.setResult(ibisDebugger.preserveInput(messageId, pipeRunResult.getResult()));
    }
    pipeRunResult.setResult(ibisDebugger.pipeOutput(pipeLine, pipe, messageId, pipeRunResult.getResult()));
    return pipeRunResult;
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) INamedObject(nl.nn.adapterframework.core.INamedObject) IExtendedPipe(nl.nn.adapterframework.core.IExtendedPipe)

Example 5 with IExtendedPipe

use of nl.nn.adapterframework.core.IExtendedPipe in project iaf by ibissource.

the class JobDef method cleanupDatabase.

private void cleanupDatabase(IbisManager ibisManager) {
    Date date = new Date();
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String formattedDate = formatter.format(date);
    List<String> jmsRealmNames = new ArrayList<String>();
    for (Configuration configuration : ibisManager.getConfigurations()) {
        List<JobDef> scheduledJobs = configuration.getScheduledJobs();
        for (JobDef jobdef : configuration.getScheduledJobs()) {
            if (jobdef.getLocker() != null) {
                String jmsRealmName = jobdef.getLocker().getJmsRealName();
                if (!jmsRealmNames.contains(jmsRealmName)) {
                    jmsRealmNames.add(jmsRealmName);
                }
            }
        }
    }
    for (IAdapter adapter : ibisManager.getRegisteredAdapters()) {
        if (adapter instanceof Adapter) {
            PipeLine pipeLine = ((Adapter) adapter).getPipeLine();
            if (pipeLine != null) {
                for (IPipe pipe : pipeLine.getPipes()) {
                    if (pipe instanceof IExtendedPipe) {
                        IExtendedPipe extendedPipe = (IExtendedPipe) pipe;
                        if (extendedPipe.getLocker() != null) {
                            String jmsRealmName = extendedPipe.getLocker().getJmsRealName();
                            if (!jmsRealmNames.contains(jmsRealmName)) {
                                jmsRealmNames.add(jmsRealmName);
                            }
                        }
                    }
                }
            }
        }
    }
    for (Iterator iter = jmsRealmNames.iterator(); iter.hasNext(); ) {
        String jmsRealmName = (String) iter.next();
        setJmsRealm(jmsRealmName);
        DirectQuerySender qs;
        qs = (DirectQuerySender) ibisManager.getIbisContext().createBeanAutowireByName(DirectQuerySender.class);
        qs.setJmsRealm(jmsRealmName);
        String deleteQuery;
        if (qs.getDatabaseType() == DbmsSupportFactory.DBMS_MSSQLSERVER) {
            deleteQuery = "DELETE FROM IBISLOCK WHERE EXPIRYDATE < CONVERT(datetime, '" + formattedDate + "', 120)";
        } else {
            deleteQuery = "DELETE FROM IBISLOCK WHERE EXPIRYDATE < TO_TIMESTAMP('" + formattedDate + "', 'YYYY-MM-DD HH24:MI:SS')";
        }
        setQuery(deleteQuery);
        qs = null;
        executeQueryJob(ibisManager);
    }
    List messageLogs = new ArrayList();
    for (IAdapter iadapter : ibisManager.getRegisteredAdapters()) {
        Adapter adapter = (Adapter) iadapter;
        PipeLine pipeline = adapter.getPipeLine();
        for (int i = 0; i < pipeline.getPipes().size(); i++) {
            IPipe pipe = pipeline.getPipe(i);
            if (pipe instanceof MessageSendingPipe) {
                MessageSendingPipe msp = (MessageSendingPipe) pipe;
                if (msp.getMessageLog() != null) {
                    ITransactionalStorage transactionStorage = msp.getMessageLog();
                    if (transactionStorage instanceof JdbcTransactionalStorage) {
                        JdbcTransactionalStorage messageLog = (JdbcTransactionalStorage) transactionStorage;
                        String jmsRealmName = messageLog.getJmsRealName();
                        String expiryDateField = messageLog.getExpiryDateField();
                        String tableName = messageLog.getTableName();
                        String keyField = messageLog.getKeyField();
                        String typeField = messageLog.getTypeField();
                        MessageLogObject mlo = new MessageLogObject(jmsRealmName, tableName, expiryDateField, keyField, typeField);
                        if (!messageLogs.contains(mlo)) {
                            messageLogs.add(mlo);
                        }
                    }
                }
            }
        }
    }
    for (Iterator iter = messageLogs.iterator(); iter.hasNext(); ) {
        MessageLogObject mlo = (MessageLogObject) iter.next();
        setJmsRealm(mlo.getJmsRealmName());
        DirectQuerySender qs;
        qs = (DirectQuerySender) ibisManager.getIbisContext().createBeanAutowireByName(DirectQuerySender.class);
        qs.setJmsRealm(mlo.getJmsRealmName());
        String deleteQuery;
        if (qs.getDatabaseType() == DbmsSupportFactory.DBMS_MSSQLSERVER) {
            deleteQuery = "DELETE FROM " + mlo.getTableName() + " WHERE " + mlo.getKeyField() + " IN (SELECT " + mlo.getKeyField() + " FROM " + mlo.getTableName() + " WITH (rowlock,updlock,readpast) WHERE " + mlo.getTypeField() + " IN ('" + JdbcTransactionalStorage.TYPE_MESSAGELOG_PIPE + "','" + JdbcTransactionalStorage.TYPE_MESSAGELOG_RECEIVER + "') AND " + mlo.getExpiryDateField() + " < CONVERT(datetime, '" + formattedDate + "', 120))";
        } else {
            deleteQuery = "DELETE FROM " + mlo.getTableName() + " WHERE " + mlo.getTypeField() + " IN ('" + JdbcTransactionalStorage.TYPE_MESSAGELOG_PIPE + "','" + JdbcTransactionalStorage.TYPE_MESSAGELOG_RECEIVER + "') AND " + mlo.getExpiryDateField() + " < TO_TIMESTAMP('" + formattedDate + "', 'YYYY-MM-DD HH24:MI:SS')";
        }
        qs = null;
        setQuery(deleteQuery);
        setQueryTimeout(900);
        executeQueryJob(ibisManager);
    }
}
Also used : Configuration(nl.nn.adapterframework.configuration.Configuration) MessageSendingPipe(nl.nn.adapterframework.pipes.MessageSendingPipe) ArrayList(java.util.ArrayList) DirectQuerySender(nl.nn.adapterframework.jdbc.DirectQuerySender) Adapter(nl.nn.adapterframework.core.Adapter) IAdapter(nl.nn.adapterframework.core.IAdapter) Date(java.util.Date) ITransactionalStorage(nl.nn.adapterframework.core.ITransactionalStorage) JdbcTransactionalStorage(nl.nn.adapterframework.jdbc.JdbcTransactionalStorage) Iterator(java.util.Iterator) IExtendedPipe(nl.nn.adapterframework.core.IExtendedPipe) ArrayList(java.util.ArrayList) List(java.util.List) PipeLine(nl.nn.adapterframework.core.PipeLine) SimpleDateFormat(java.text.SimpleDateFormat) IAdapter(nl.nn.adapterframework.core.IAdapter) IPipe(nl.nn.adapterframework.core.IPipe)

Aggregations

IExtendedPipe (nl.nn.adapterframework.core.IExtendedPipe)11 PipeRunResult (nl.nn.adapterframework.core.PipeRunResult)8 PipeRunException (nl.nn.adapterframework.core.PipeRunException)6 INamedObject (nl.nn.adapterframework.core.INamedObject)4 AbstractPipe (nl.nn.adapterframework.pipes.AbstractPipe)4 StatisticsKeeper (nl.nn.adapterframework.statistics.StatisticsKeeper)4 InputStream (java.io.InputStream)2 StringTokenizer (java.util.StringTokenizer)2 SAXParser (javax.xml.parsers.SAXParser)2 SAXParserFactory (javax.xml.parsers.SAXParserFactory)2 FixedForwardPipe (nl.nn.adapterframework.pipes.FixedForwardPipe)2 CompactSaxHandler (nl.nn.adapterframework.util.CompactSaxHandler)2 Locker (nl.nn.adapterframework.util.Locker)2 IOException (java.io.IOException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Configuration (nl.nn.adapterframework.configuration.Configuration)1