Search in sources :

Example 1 with MessageKeeper

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

the class ShowConfigurationStatus method toConfigurationMessagesXml.

private XmlBuilder toConfigurationMessagesXml(IbisManager ibisManager, Configuration configurationSelected) {
    XmlBuilder configurationMessages = new XmlBuilder("configurationMessages");
    MessageKeeper messageKeeper;
    if (configurationSelected != null) {
        messageKeeper = ibisManager.getIbisContext().getMessageKeeper(configurationSelected.getName());
    } else {
        messageKeeper = ibisManager.getIbisContext().getMessageKeeper(CONFIG_ALL);
    }
    for (int t = 0; t < messageKeeper.size(); t++) {
        XmlBuilder configurationMessage = new XmlBuilder("configurationMessage");
        String msg = messageKeeper.getMessage(t).getMessageText();
        if (MAX_MESSAGE_SIZE > 0 && msg.length() > MAX_MESSAGE_SIZE) {
            msg = msg.substring(0, MAX_MESSAGE_SIZE) + "...(" + (msg.length() - MAX_MESSAGE_SIZE) + " characters more)";
        }
        configurationMessage.setValue(msg, true);
        configurationMessage.addAttribute("date", DateUtils.format(messageKeeper.getMessage(t).getMessageDate(), DateUtils.FORMAT_FULL_GENERIC));
        String level = messageKeeper.getMessage(t).getMessageLevel();
        configurationMessage.addAttribute("level", level);
        configurationMessages.addSubElement(configurationMessage);
    }
    return configurationMessages;
}
Also used : XmlBuilder(nl.nn.adapterframework.util.XmlBuilder) MessageKeeper(nl.nn.adapterframework.util.MessageKeeper)

Example 2 with MessageKeeper

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

the class IbisContext method init.

/**
 * Creates the Spring context, and load the configuration. Optionally  with
 * a specific ClassLoader which might for example override the getResource
 * method to load configuration and related resources from a different
 * location from the standard classpath. In case basePath is not null the
 * ClassLoader is wrapped in {@link BasePathClassLoader} to make it possible
 * to reference resources in the configuration relative to the configuration
 * file and have an extra resource override (resource is first resolved
 * relative to the configuration, when not found it is resolved by the
 * original ClassLoader.
 *
 * @see ClassUtils#getResourceURL(ClassLoader, String)
 * @see AppConstants#getInstance(ClassLoader)
 *
 * @param reconnect automatically try to reconnect to a datasource
 */
public synchronized void init(boolean reconnect) {
    try {
        long start = System.currentTimeMillis();
        LOG.info("Attempting to start IBIS application");
        MessageKeeper messageKeeper = new MessageKeeper();
        messageKeepers.put("*ALL*", messageKeeper);
        if (StringUtils.isNotEmpty(FLOW_CREATE_DIAGRAM_URL)) {
            flowDiagram = new FlowDiagram(FLOW_CREATE_DIAGRAM_URL);
        }
        applicationContext = createApplicationContext();
        ibisManager = (IbisManager) applicationContext.getBean("ibisManager");
        ibisManager.setIbisContext(this);
        classLoaderManager = new ClassLoaderManager(this);
        AbstractSpringPoweredDigesterFactory.setIbisContext(this);
        load();
        getMessageKeeper().setMaxSize(Math.max(messageKeeperSize, getMessageKeeper().size()));
        log("startup in " + (System.currentTimeMillis() - start) + " ms");
    } catch (Exception e) {
        // Catch all exceptions, the IBIS failed to startup...
        LOG.error("Failed to initialize IbisContext, retrying in 1 minute!", e);
        if (reconnect) {
            ibisContextReconnectThread = new Thread(new IbisContextRunnable(this));
            ibisContextReconnectThread.setName("ibisContextReconnectThread");
            ibisContextReconnectThread.start();
        }
    }
}
Also used : MessageKeeper(nl.nn.adapterframework.util.MessageKeeper) FlowDiagram(nl.nn.adapterframework.util.FlowDiagram) BeansException(org.springframework.beans.BeansException)

Example 3 with MessageKeeper

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

the class IbisContext method log.

private void log(String configurationName, String configurationVersion, String message, String level, Exception e, boolean allOnly) {
    String key;
    if (allOnly || configurationName == null) {
        key = "*ALL*";
    } else {
        key = configurationName;
    }
    MessageKeeper messageKeeper = messageKeepers.get(key);
    if (messageKeeper == null) {
        messageKeeper = new MessageKeeper(messageKeeperSize < 1 ? 1 : messageKeeperSize);
        messageKeepers.put(key, messageKeeper);
    }
    String m;
    String version;
    if (configurationName != null) {
        m = "Configuration [" + configurationName + "] ";
        version = configurationVersion;
    } else {
        m = "Application [" + INSTANCE_NAME + "] ";
        version = getApplicationVersion();
    }
    if (version != null) {
        m = m + "[" + version + "] ";
    }
    m = m + message;
    if (level.equals(MessageKeeperMessage.ERROR_LEVEL)) {
        LOG.info(m, e);
    } else if (level.equals(MessageKeeperMessage.WARN_LEVEL)) {
        LOG.warn(m, e);
    } else {
        LOG.info(m, e);
    }
    if (e != null) {
        m = m + ": " + e.getMessage();
    }
    messageKeeper.add(m, level);
    if (!allOnly) {
        log(configurationName, configurationVersion, message, level, e, true);
    }
}
Also used : MessageKeeper(nl.nn.adapterframework.util.MessageKeeper)

Example 4 with MessageKeeper

use of nl.nn.adapterframework.util.MessageKeeper 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)

Example 5 with MessageKeeper

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

the class SchedulerAdapter method getJobMessages.

public XmlBuilder getJobMessages(JobDef jobdef) {
    XmlBuilder jobMessages = new XmlBuilder("jobMessages");
    if (jobdef != null) {
        MessageKeeper jobMessageKeeper = jobdef.getMessageKeeper();
        if (jobMessageKeeper != null) {
            for (int t = 0; t < jobMessageKeeper.size(); t++) {
                XmlBuilder jobMessage = new XmlBuilder("jobMessage");
                jobMessage.setValue(jobMessageKeeper.getMessage(t).getMessageText(), true);
                jobMessage.addAttribute("date", DateUtils.format(jobMessageKeeper.getMessage(t).getMessageDate(), DateUtils.FORMAT_FULL_GENERIC));
                jobMessage.addAttribute("level", jobMessageKeeper.getMessage(t).getMessageLevel());
                jobMessages.addSubElement(jobMessage);
            }
        }
    }
    return jobMessages;
}
Also used : XmlBuilder(nl.nn.adapterframework.util.XmlBuilder) MessageKeeper(nl.nn.adapterframework.util.MessageKeeper)

Aggregations

MessageKeeper (nl.nn.adapterframework.util.MessageKeeper)5 XmlBuilder (nl.nn.adapterframework.util.XmlBuilder)2 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)1 StatisticsKeeper (nl.nn.adapterframework.statistics.StatisticsKeeper)1 FlowDiagram (nl.nn.adapterframework.util.FlowDiagram)1 BeansException (org.springframework.beans.BeansException)1