Search in sources :

Example 1 with ITransactionRequirements

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

the class ReceiverBase method configure.

public void configure() throws ConfigurationException {
    configurationSucceeded = false;
    try {
        if (StringUtils.isEmpty(getName())) {
            if (getListener() != null) {
                setName(ClassUtils.nameOf(getListener()));
            } else {
                setName(ClassUtils.nameOf(this));
            }
        }
        eventHandler = MonitorManager.getEventHandler();
        registerEvent(RCV_CONFIGURED_MONITOR_EVENT);
        registerEvent(RCV_CONFIGURATIONEXCEPTION_MONITOR_EVENT);
        registerEvent(RCV_STARTED_RUNNING_MONITOR_EVENT);
        registerEvent(RCV_SHUTDOWN_MONITOR_EVENT);
        registerEvent(RCV_SUSPENDED_MONITOR_EVENT);
        registerEvent(RCV_RESUMED_MONITOR_EVENT);
        registerEvent(RCV_THREAD_EXIT_MONITOR_EVENT);
        TXNEW_PROC = SpringTxManagerProxy.getTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRES_NEW, getTransactionTimeout());
        // to use direct member variables).
        if (this.tmpInProcessStorage != null) {
            if (this.errorSender == null && this.errorStorage == null) {
                this.errorStorage = this.tmpInProcessStorage;
                info(getLogPrefix() + "has errorStorage in inProcessStorage, setting inProcessStorage's type to 'errorStorage'. Please update the configuration to change the inProcessStorage element to an errorStorage element, since the inProcessStorage is no longer used.");
                errorStorage.setType(JdbcTransactionalStorage.TYPE_ERRORSTORAGE);
            } else {
                info(getLogPrefix() + "has inProcessStorage defined but also has an errorStorage or errorSender. InProcessStorage is not used and can be removed from the configuration.");
            }
            // Set temporary in-process storage pointer to null
            this.tmpInProcessStorage = null;
        }
        // Do propagate-name AFTER changing the errorStorage!
        propagateName();
        if (getListener() == null) {
            throw new ConfigurationException(getLogPrefix() + "has no listener");
        }
        if (!StringUtils.isEmpty(getElementToMove()) && !StringUtils.isEmpty(getElementToMoveChain())) {
            throw new ConfigurationException("cannot have both an elementToMove and an elementToMoveChain specified");
        }
        if (!(getHideMethod().equalsIgnoreCase("all")) && (!(getHideMethod().equalsIgnoreCase("firstHalf")))) {
            throw new ConfigurationException(getLogPrefix() + "invalid value for hideMethod [" + getHideMethod() + "], must be 'all' or 'firstHalf'");
        }
        if (getListener() instanceof ReceiverAware) {
            ((ReceiverAware) getListener()).setReceiver(this);
        }
        if (getListener() instanceof IPushingListener) {
            IPushingListener pl = (IPushingListener) getListener();
            pl.setHandler(this);
            pl.setExceptionListener(this);
        }
        if (getListener() instanceof IPortConnectedListener) {
            IPortConnectedListener pcl = (IPortConnectedListener) getListener();
            pcl.setReceiver(this);
        }
        if (getListener() instanceof IPullingListener) {
            setListenerContainer(createListenerContainer());
        }
        if (getListener() instanceof JdbcFacade) {
            ((JdbcFacade) getListener()).setTransacted(isTransacted());
        }
        if (getListener() instanceof JMSFacade) {
            ((JMSFacade) getListener()).setTransacted(isTransacted());
        }
        getListener().configure();
        if (getListener() instanceof HasPhysicalDestination) {
            info(getLogPrefix() + "has listener on " + ((HasPhysicalDestination) getListener()).getPhysicalDestinationName());
        }
        if (getListener() instanceof HasSender) {
            // only informational
            ISender sender = ((HasSender) getListener()).getSender();
            if (sender instanceof HasPhysicalDestination) {
                info("Listener of receiver [" + getName() + "] has answer-sender on " + ((HasPhysicalDestination) sender).getPhysicalDestinationName());
            }
        }
        if (getListener() instanceof ITransactionRequirements) {
            ITransactionRequirements tr = (ITransactionRequirements) getListener();
            if (tr.transactionalRequired() && !isTransacted()) {
                String msg = getLogPrefix() + "listener type [" + ClassUtils.nameOf(getListener()) + "] requires transactional processing";
                ConfigurationWarnings.getInstance().add(msg);
            // throw new ConfigurationException(msg);
            }
        }
        ISender sender = getSender();
        if (sender != null) {
            sender.configure();
            if (sender instanceof HasPhysicalDestination) {
                info(getLogPrefix() + "has answer-sender on " + ((HasPhysicalDestination) sender).getPhysicalDestinationName());
            }
        }
        ISender errorSender = getErrorSender();
        if (errorSender != null) {
            errorSender.configure();
            if (errorSender instanceof HasPhysicalDestination) {
                info(getLogPrefix() + "has errorSender to " + ((HasPhysicalDestination) errorSender).getPhysicalDestinationName());
            }
        }
        ITransactionalStorage errorStorage = getErrorStorage();
        if (errorStorage != null) {
            errorStorage.configure();
            if (errorStorage instanceof HasPhysicalDestination) {
                info(getLogPrefix() + "has errorStorage to " + ((HasPhysicalDestination) errorStorage).getPhysicalDestinationName());
            }
            registerEvent(RCV_MESSAGE_TO_ERRORSTORE_EVENT);
        }
        ITransactionalStorage messageLog = getMessageLog();
        if (messageLog != null) {
            messageLog.configure();
            if (messageLog instanceof HasPhysicalDestination) {
                info(getLogPrefix() + "has messageLog in " + ((HasPhysicalDestination) messageLog).getPhysicalDestinationName());
            }
            if (StringUtils.isNotEmpty(getLabelXPath()) || StringUtils.isNotEmpty(getLabelStyleSheet())) {
                labelTp = TransformerPool.configureTransformer0(getLogPrefix(), classLoader, getLabelNamespaceDefs(), getLabelXPath(), getLabelStyleSheet(), "text", false, null, isXslt2());
            }
        }
        if (isTransacted()) {
            if (errorSender == null && errorStorage == null) {
                ConfigurationWarnings configWarnings = ConfigurationWarnings.getInstance();
                String msg = getLogPrefix() + "sets transactionAttribute=" + getTransactionAttribute() + ", but has no errorSender or errorStorage. Messages processed with errors will be lost";
                configWarnings.add(log, msg);
            } else {
            // if (errorSender!=null && !(errorSender instanceof IXAEnabled && ((IXAEnabled)errorSender).isTransacted())) {
            // warn(getLogPrefix()+"sets transacted=true, but errorSender is not. Transactional integrity is not guaranteed");
            // }
            // if (errorStorage!=null && !(errorStorage instanceof IXAEnabled && ((IXAEnabled)errorStorage).isTransacted())) {
            // warn(getLogPrefix()+"sets transacted=true, but errorStorage is not. Transactional integrity is not guaranteed");
            // }
            }
            if (getTransactionTimeout() > 0) {
                String systemTransactionTimeout = Misc.getSystemTransactionTimeout();
                if (systemTransactionTimeout != null && StringUtils.isNumeric(systemTransactionTimeout)) {
                    int stt = Integer.parseInt(systemTransactionTimeout);
                    if (getTransactionTimeout() > stt) {
                        ConfigurationWarnings configWarnings = ConfigurationWarnings.getInstance();
                        String msg = getLogPrefix() + "has a transaction timeout [" + getTransactionTimeout() + "] which exceeds the system transaction timeout [" + stt + "]";
                        configWarnings.add(log, msg);
                    }
                }
            }
        }
        if (StringUtils.isNotEmpty(getCorrelationIDXPath()) || StringUtils.isNotEmpty(getCorrelationIDStyleSheet())) {
            correlationIDTp = TransformerPool.configureTransformer0(getLogPrefix(), classLoader, getCorrelationIDNamespaceDefs(), getCorrelationIDXPath(), getCorrelationIDStyleSheet(), "text", false, null, isXslt2());
        }
        if (adapter != null) {
            adapter.getMessageKeeper().add(getLogPrefix() + "initialization complete");
        }
        throwEvent(RCV_CONFIGURED_MONITOR_EVENT);
        configurationSucceeded = true;
    } catch (Throwable t) {
        ConfigurationException e = null;
        if (t instanceof ConfigurationException) {
            e = (ConfigurationException) t;
        } else {
            e = new ConfigurationException("Exception configuring receiver [" + getName() + "]", t);
        }
        throwEvent(RCV_CONFIGURATIONEXCEPTION_MONITOR_EVENT);
        log.debug(getLogPrefix() + "Errors occured during configuration, setting runstate to ERROR");
        runState.setRunState(RunStateEnum.ERROR);
        throw e;
    }
}
Also used : ConfigurationWarnings(nl.nn.adapterframework.configuration.ConfigurationWarnings) JMSFacade(nl.nn.adapterframework.jms.JMSFacade) HasSender(nl.nn.adapterframework.core.HasSender) ITransactionalStorage(nl.nn.adapterframework.core.ITransactionalStorage) IPullingListener(nl.nn.adapterframework.core.IPullingListener) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) ISender(nl.nn.adapterframework.core.ISender) ITransactionRequirements(nl.nn.adapterframework.core.ITransactionRequirements) IPushingListener(nl.nn.adapterframework.core.IPushingListener) IPortConnectedListener(nl.nn.adapterframework.core.IPortConnectedListener) JdbcFacade(nl.nn.adapterframework.jdbc.JdbcFacade) HasPhysicalDestination(nl.nn.adapterframework.core.HasPhysicalDestination)

Example 2 with ITransactionRequirements

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

the class Receiver method configure.

/**
 * This method is called by the <code>IAdapter</code> to let the
 * receiver do things to initialize itself before the <code>startListening</code>
 * method is called.
 * @see #startRunning
 * @throws ConfigurationException when initialization did not succeed.
 */
@Override
public void configure() throws ConfigurationException {
    configurationSucceeded = false;
    try {
        super.configure();
        if (StringUtils.isEmpty(getName())) {
            if (getListener() != null) {
                setName(ClassUtils.nameOf(getListener()));
            } else {
                setName(ClassUtils.nameOf(this));
            }
        }
        registerEvent(RCV_CONFIGURED_MONITOR_EVENT);
        registerEvent(RCV_CONFIGURATIONEXCEPTION_MONITOR_EVENT);
        registerEvent(RCV_STARTED_RUNNING_MONITOR_EVENT);
        registerEvent(RCV_SHUTDOWN_MONITOR_EVENT);
        registerEvent(RCV_SUSPENDED_MONITOR_EVENT);
        registerEvent(RCV_RESUMED_MONITOR_EVENT);
        registerEvent(RCV_THREAD_EXIT_MONITOR_EVENT);
        TXNEW_PROC = SpringTxManagerProxy.getTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRES_NEW, getTransactionTimeout());
        // to use direct member variables).
        if (this.tmpInProcessStorage != null) {
            if (this.errorSender == null && messageBrowsers.get(ProcessState.ERROR) == null) {
                messageBrowsers.put(ProcessState.ERROR, this.tmpInProcessStorage);
                info("has errorStorage in inProcessStorage, setting inProcessStorage's type to 'errorStorage'. Please update the configuration to change the inProcessStorage element to an errorStorage element, since the inProcessStorage is no longer used.");
                getErrorStorage().setType(IMessageBrowser.StorageType.ERRORSTORAGE.getCode());
            } else {
                info("has inProcessStorage defined but also has an errorStorage or errorSender. InProcessStorage is not used and can be removed from the configuration.");
            }
            // Set temporary in-process storage pointer to null
            this.tmpInProcessStorage = null;
        }
        // Do propagate-name AFTER changing the errorStorage!
        propagateName();
        if (getListener() == null) {
            throw new ConfigurationException(getLogPrefix() + "has no listener");
        }
        if (!StringUtils.isEmpty(getElementToMove()) && !StringUtils.isEmpty(getElementToMoveChain())) {
            throw new ConfigurationException("cannot have both an elementToMove and an elementToMoveChain specified");
        }
        if (!(getHideMethod().equalsIgnoreCase("all")) && (!(getHideMethod().equalsIgnoreCase("firstHalf")))) {
            throw new ConfigurationException(getLogPrefix() + "invalid value for hideMethod [" + getHideMethod() + "], must be 'all' or 'firstHalf'");
        }
        if (getListener() instanceof ReceiverAware) {
            ((ReceiverAware) getListener()).setReceiver(this);
        }
        if (getListener() instanceof IPushingListener) {
            IPushingListener<M> pl = (IPushingListener<M>) getListener();
            pl.setHandler(this);
            pl.setExceptionListener(this);
        }
        if (getListener() instanceof IPortConnectedListener) {
            IPortConnectedListener<M> pcl = (IPortConnectedListener<M>) getListener();
            pcl.setReceiver(this);
        }
        if (getListener() instanceof IPullingListener) {
            setListenerContainer(createListenerContainer());
        }
        if (getListener() instanceof JdbcFacade) {
            ((JdbcFacade) getListener()).setTransacted(isTransacted());
        }
        if (getListener() instanceof JMSFacade) {
            ((JMSFacade) getListener()).setTransacted(isTransacted());
        }
        getListener().configure();
        if (getListener() instanceof HasPhysicalDestination) {
            info("has listener on " + ((HasPhysicalDestination) getListener()).getPhysicalDestinationName());
        }
        if (getListener() instanceof HasSender) {
            // only informational
            ISender sender = ((HasSender) getListener()).getSender();
            if (sender instanceof HasPhysicalDestination) {
                info("Listener has answer-sender on " + ((HasPhysicalDestination) sender).getPhysicalDestinationName());
            }
        }
        if (getListener() instanceof ITransactionRequirements) {
            ITransactionRequirements tr = (ITransactionRequirements) getListener();
            if (tr.transactionalRequired() && !isTransacted()) {
                ConfigurationWarnings.add(this, log, "listener type [" + ClassUtils.nameOf(getListener()) + "] requires transactional processing", SuppressKeys.TRANSACTION_SUPPRESS_KEY, getAdapter());
            // throw new ConfigurationException(msg);
            }
        }
        ISender sender = getSender();
        if (sender != null) {
            sender.configure();
            if (sender instanceof HasPhysicalDestination) {
                info("has answer-sender on " + ((HasPhysicalDestination) sender).getPhysicalDestinationName());
            }
        }
        ISender errorSender = getErrorSender();
        if (errorSender != null) {
            if (errorSender instanceof HasPhysicalDestination) {
                info("has errorSender to " + ((HasPhysicalDestination) errorSender).getPhysicalDestinationName());
            }
            errorSender.configure();
        }
        if (getListener() instanceof IHasProcessState) {
            knownProcessStates.addAll(((IHasProcessState) getListener()).knownProcessStates());
            targetProcessStates = ((IHasProcessState) getListener()).targetProcessStates();
            supportProgrammaticRetry = knownProcessStates.contains(ProcessState.INPROCESS);
        }
        ITransactionalStorage<Serializable> messageLog = getMessageLog();
        if (messageLog != null) {
            if (getListener() instanceof IProvidesMessageBrowsers && ((IProvidesMessageBrowsers) getListener()).getMessageBrowser(ProcessState.DONE) != null) {
                throw new ConfigurationException("listener with built-in messageLog cannot have external messageLog too");
            }
            messageLog.setName("messageLog of [" + getName() + "]");
            if (StringUtils.isEmpty(messageLog.getSlotId())) {
                messageLog.setSlotId(getName());
            }
            messageLog.setType(IMessageBrowser.StorageType.MESSAGELOG_RECEIVER.getCode());
            messageLog.configure();
            if (messageLog instanceof HasPhysicalDestination) {
                info("has messageLog in " + ((HasPhysicalDestination) messageLog).getPhysicalDestinationName());
            }
            knownProcessStates.add(ProcessState.DONE);
            messageBrowsers.put(ProcessState.DONE, messageLog);
            if (StringUtils.isNotEmpty(getLabelXPath()) || StringUtils.isNotEmpty(getLabelStyleSheet())) {
                labelTp = TransformerPool.configureTransformer0(getLogPrefix(), this, getLabelNamespaceDefs(), getLabelXPath(), getLabelStyleSheet(), OutputType.TEXT, false, null, 0);
            }
        }
        ITransactionalStorage<Serializable> errorStorage = getErrorStorage();
        if (errorStorage != null) {
            if (getListener() instanceof IProvidesMessageBrowsers && ((IProvidesMessageBrowsers) getListener()).getMessageBrowser(ProcessState.ERROR) != null) {
                throw new ConfigurationException("listener with built-in errorStorage cannot have external errorStorage too");
            }
            errorStorage.setName("errorStorage of [" + getName() + "]");
            if (StringUtils.isEmpty(errorStorage.getSlotId())) {
                errorStorage.setSlotId(getName());
            }
            errorStorage.setType(IMessageBrowser.StorageType.ERRORSTORAGE.getCode());
            errorStorage.configure();
            if (errorStorage instanceof HasPhysicalDestination) {
                info("has errorStorage to " + ((HasPhysicalDestination) errorStorage).getPhysicalDestinationName());
            }
            knownProcessStates.add(ProcessState.ERROR);
            messageBrowsers.put(ProcessState.ERROR, errorStorage);
            registerEvent(RCV_MESSAGE_TO_ERRORSTORE_EVENT);
        }
        if (getListener() instanceof IProvidesMessageBrowsers) {
            for (ProcessState state : knownProcessStates) {
                IMessageBrowser messageBrowser = ((IProvidesMessageBrowsers) getListener()).getMessageBrowser(state);
                if (messageBrowser != null && messageBrowser instanceof IConfigurable) {
                    ((IConfigurable) messageBrowser).configure();
                }
                messageBrowsers.put(state, messageBrowser);
            }
        }
        if (targetProcessStates == null) {
            targetProcessStates = ProcessState.getTargetProcessStates(knownProcessStates);
        }
        if (isTransacted() && errorSender == null && errorStorage == null && !knownProcessStates().contains(ProcessState.ERROR)) {
            ConfigurationWarnings.add(this, log, "sets transactionAttribute=" + getTransactionAttribute() + ", but has no errorSender or errorStorage. Messages processed with errors will be lost", SuppressKeys.TRANSACTION_SUPPRESS_KEY, getAdapter());
        }
        if (StringUtils.isNotEmpty(getCorrelationIDXPath()) || StringUtils.isNotEmpty(getCorrelationIDStyleSheet())) {
            correlationIDTp = TransformerPool.configureTransformer0(getLogPrefix(), this, getCorrelationIDNamespaceDefs(), getCorrelationIDXPath(), getCorrelationIDStyleSheet(), OutputType.TEXT, false, null, 0);
        }
        if (StringUtils.isNotEmpty(getHideRegex()) && getErrorStorage() != null && StringUtils.isEmpty(getErrorStorage().getHideRegex())) {
            getErrorStorage().setHideRegex(getHideRegex());
            getErrorStorage().setHideMethod(getHideMethod());
        }
        if (StringUtils.isNotEmpty(getHideRegex()) && getMessageLog() != null && StringUtils.isEmpty(getMessageLog().getHideRegex())) {
            getMessageLog().setHideRegex(getHideRegex());
            getMessageLog().setHideMethod(getHideMethod());
        }
    } catch (Throwable t) {
        ConfigurationException e = null;
        if (t instanceof ConfigurationException) {
            e = (ConfigurationException) t;
        } else {
            e = new ConfigurationException("Exception configuring receiver [" + getName() + "]", t);
        }
        throwEvent(RCV_CONFIGURATIONEXCEPTION_MONITOR_EVENT);
        log.debug(getLogPrefix() + "Errors occured during configuration, setting runstate to ERROR");
        runState.setRunState(RunState.ERROR);
        throw e;
    }
    if (adapter != null) {
        adapter.getMessageKeeper().add(getLogPrefix() + "initialization complete");
    }
    throwEvent(RCV_CONFIGURED_MONITOR_EVENT);
    configurationSucceeded = true;
    if (isInRunState(RunState.ERROR)) {
        // if the adapter was previously in state ERROR, after a successful configure, reset it's state
        runState.setRunState(RunState.STOPPED);
    }
}
Also used : Serializable(java.io.Serializable) IProvidesMessageBrowsers(nl.nn.adapterframework.core.IProvidesMessageBrowsers) IMessageBrowser(nl.nn.adapterframework.core.IMessageBrowser) JMSFacade(nl.nn.adapterframework.jms.JMSFacade) HasSender(nl.nn.adapterframework.core.HasSender) IConfigurable(nl.nn.adapterframework.core.IConfigurable) IHasProcessState(nl.nn.adapterframework.core.IHasProcessState) ProcessState(nl.nn.adapterframework.core.ProcessState) IPullingListener(nl.nn.adapterframework.core.IPullingListener) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) ISender(nl.nn.adapterframework.core.ISender) IHasProcessState(nl.nn.adapterframework.core.IHasProcessState) ITransactionRequirements(nl.nn.adapterframework.core.ITransactionRequirements) IPushingListener(nl.nn.adapterframework.core.IPushingListener) IPortConnectedListener(nl.nn.adapterframework.core.IPortConnectedListener) JdbcFacade(nl.nn.adapterframework.jdbc.JdbcFacade) HasPhysicalDestination(nl.nn.adapterframework.core.HasPhysicalDestination)

Aggregations

ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)2 HasPhysicalDestination (nl.nn.adapterframework.core.HasPhysicalDestination)2 HasSender (nl.nn.adapterframework.core.HasSender)2 IPortConnectedListener (nl.nn.adapterframework.core.IPortConnectedListener)2 IPullingListener (nl.nn.adapterframework.core.IPullingListener)2 IPushingListener (nl.nn.adapterframework.core.IPushingListener)2 ISender (nl.nn.adapterframework.core.ISender)2 ITransactionRequirements (nl.nn.adapterframework.core.ITransactionRequirements)2 JdbcFacade (nl.nn.adapterframework.jdbc.JdbcFacade)2 JMSFacade (nl.nn.adapterframework.jms.JMSFacade)2 Serializable (java.io.Serializable)1 ConfigurationWarnings (nl.nn.adapterframework.configuration.ConfigurationWarnings)1 IConfigurable (nl.nn.adapterframework.core.IConfigurable)1 IHasProcessState (nl.nn.adapterframework.core.IHasProcessState)1 IMessageBrowser (nl.nn.adapterframework.core.IMessageBrowser)1 IProvidesMessageBrowsers (nl.nn.adapterframework.core.IProvidesMessageBrowsers)1 ITransactionalStorage (nl.nn.adapterframework.core.ITransactionalStorage)1 ProcessState (nl.nn.adapterframework.core.ProcessState)1