Search in sources :

Example 6 with ReceiverBase

use of nl.nn.adapterframework.receivers.ReceiverBase in project iaf by ibissource.

the class WsdlTest method mockPipeLine.

protected PipeLine mockPipeLine(IPipe inputValidator, IPipe outputValidator, String targetNamespace, String adapterName) {
    PipeLine simple = mock(PipeLine.class);
    when(simple.getInputValidator()).thenReturn(inputValidator);
    when(simple.getOutputValidator()).thenReturn(outputValidator);
    Adapter adp = mock(Adapter.class);
    when(simple.getAdapter()).thenReturn(adp);
    Configuration cfg = mock(Configuration.class);
    when(simple.getAdapter().getConfiguration()).thenReturn(cfg);
    final ReceiverBase receiverBase = mock(ReceiverBase.class);
    WebServiceListener listener = new WebServiceListener();
    listener.setServiceNamespaceURI(targetNamespace);
    when(receiverBase.getListener()).thenReturn(listener);
    when(adp.getReceiverIterator()).thenAnswer(new Answer<Iterator>() {

        public Iterator answer(InvocationOnMock invocation) throws Throwable {
            return Arrays.asList(receiverBase).iterator();
        }
    });
    when(adp.getName()).thenReturn(adapterName);
    return simple;
}
Also used : ReceiverBase(nl.nn.adapterframework.receivers.ReceiverBase) Configuration(nl.nn.adapterframework.configuration.Configuration) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Iterator(java.util.Iterator) Adapter(nl.nn.adapterframework.core.Adapter) PipeLine(nl.nn.adapterframework.core.PipeLine) WebServiceListener(nl.nn.adapterframework.http.WebServiceListener)

Example 7 with ReceiverBase

use of nl.nn.adapterframework.receivers.ReceiverBase in project iaf by ibissource.

the class FxfListener method warn.

private void warn(String msg, Throwable t) {
    log.warn(msg, t);
    IReceiver iReceiver = getReceiver();
    if (iReceiver != null && iReceiver instanceof ReceiverBase) {
        ReceiverBase rb = (ReceiverBase) iReceiver;
        IAdapter iAdapter = rb.getAdapter();
        if (iAdapter != null) {
            iAdapter.getMessageKeeper().add("WARNING: " + msg + (t != null ? ": " + t.getMessage() : ""), MessageKeeperMessage.WARN_LEVEL);
        }
    }
}
Also used : IReceiver(nl.nn.adapterframework.core.IReceiver) ReceiverBase(nl.nn.adapterframework.receivers.ReceiverBase) IAdapter(nl.nn.adapterframework.core.IAdapter)

Example 8 with ReceiverBase

use of nl.nn.adapterframework.receivers.ReceiverBase in project iaf by ibissource.

the class EsbJmsListener method configure.

public void configure() throws ConfigurationException {
    if (getMessageProtocol() == null) {
        throw new ConfigurationException(getLogPrefix() + "messageProtocol must be set");
    }
    if (!getMessageProtocol().equalsIgnoreCase(REQUEST_REPLY) && !getMessageProtocol().equalsIgnoreCase(FIRE_AND_FORGET)) {
        throw new ConfigurationException(getLogPrefix() + "illegal value for messageProtocol [" + getMessageProtocol() + "], must be '" + REQUEST_REPLY + "' or '" + FIRE_AND_FORGET + "'");
    }
    if (getMessageProtocol().equalsIgnoreCase(REQUEST_REPLY)) {
        setForceMessageIdAsCorrelationId(true);
        if (CACHE_CONSUMER.equals(getCacheMode())) {
            boolean recovered = false;
            ReceiverBase receiverBase = getReceiverBase();
            if (receiverBase != null) {
                recovered = (receiverBase.isRecover() || receiverBase.isRecoverAdapter());
            }
            if (!recovered) {
                ConfigurationWarnings configWarnings = ConfigurationWarnings.getInstance();
                configWarnings.add(log, "attribute [cacheMode] already has a default value [" + CACHE_CONSUMER + "]");
            }
        }
        setCacheMode("CACHE_CONSUMER");
    } else {
        setUseReplyTo(false);
    }
    super.configure();
}
Also used : ReceiverBase(nl.nn.adapterframework.receivers.ReceiverBase) ConfigurationWarnings(nl.nn.adapterframework.configuration.ConfigurationWarnings) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException)

Example 9 with ReceiverBase

use of nl.nn.adapterframework.receivers.ReceiverBase in project iaf by ibissource.

the class DefaultIbisManager method handleAdapter.

/**
 * Utility function to give commands to Adapters and Receivers
 */
public void handleAdapter(String action, String configurationName, String adapterName, String receiverName, String commandIssuedBy, boolean isAdmin) {
    if (action.equalsIgnoreCase("STOPADAPTER")) {
        if (adapterName.equals("*ALL*")) {
            if (configurationName.equals("*ALL*")) {
                log.info("Stopping all adapters on request of [" + commandIssuedBy + "]");
                for (Configuration configuration : configurations) {
                    stopAdapters(configuration);
                }
            } else {
                log.info("Stopping all adapters for configuration [" + configurationName + "] on request of [" + commandIssuedBy + "]");
                stopAdapters(getConfiguration(configurationName));
            }
        } else {
            for (Configuration configuration : configurations) {
                if (configuration.getRegisteredAdapter(adapterName) != null) {
                    log.info("Stopping adapter [" + adapterName + "], on request of [" + commandIssuedBy + "]");
                    configuration.getRegisteredAdapter(adapterName).stopRunning();
                }
            }
        }
    } else if (action.equalsIgnoreCase("STARTADAPTER")) {
        if (adapterName.equals("*ALL*")) {
            if (configurationName.equals("*ALL*")) {
                log.info("Starting all adapters on request of [" + commandIssuedBy + "]");
                for (Configuration configuration : configurations) {
                    startAdapters(configuration);
                }
            } else {
                log.info("Starting all adapters for configuration [" + configurationName + "] on request of [" + commandIssuedBy + "]");
                startAdapters(getConfiguration(configurationName));
            }
        } else {
            try {
                for (Configuration configuration : configurations) {
                    if (configuration.getRegisteredAdapter(adapterName) != null) {
                        log.info("Starting adapter [" + adapterName + "] on request of [" + commandIssuedBy + "]");
                        configuration.getRegisteredAdapter(adapterName).startRunning();
                    }
                }
            } catch (Exception e) {
                log.error("error in execution of command [" + action + "] for adapter [" + adapterName + "]", e);
            // errors.add("", new ActionError("errors.generic", e.toString()));
            }
        }
    } else if (action.equalsIgnoreCase("STOPRECEIVER")) {
        for (Configuration configuration : configurations) {
            if (configuration.getRegisteredAdapter(adapterName) != null) {
                IAdapter adapter = configuration.getRegisteredAdapter(adapterName);
                IReceiver receiver = adapter.getReceiverByName(receiverName);
                receiver.stopRunning();
                log.info("receiver [" + receiverName + "] stopped by webcontrol on request of " + commandIssuedBy);
            }
        }
    } else if (action.equalsIgnoreCase("STARTRECEIVER")) {
        for (Configuration configuration : configurations) {
            if (configuration.getRegisteredAdapter(adapterName) != null) {
                IAdapter adapter = configuration.getRegisteredAdapter(adapterName);
                IReceiver receiver = adapter.getReceiverByName(receiverName);
                receiver.startRunning();
                log.info("receiver [" + receiverName + "] started by " + commandIssuedBy);
            }
        }
    } else if (action.equalsIgnoreCase("RELOAD")) {
        String msg = "Reload configuration [" + configurationName + "] on request of [" + commandIssuedBy + "]";
        log.info(msg);
        secLog.info(msg);
        ibisContext.reload(configurationName);
    } else if (action.equalsIgnoreCase("FULLRELOAD")) {
        if (isAdmin) {
            String msg = "Full reload on request of [" + commandIssuedBy + "]";
            log.info(msg);
            secLog.info(msg);
            ibisContext.fullReload();
        } else {
            log.warn("Full reload not allowed for [" + commandIssuedBy + "]");
        }
    } else if (action.equalsIgnoreCase("INCTHREADS")) {
        for (Configuration configuration : configurations) {
            if (configuration.getRegisteredAdapter(adapterName) != null) {
                IAdapter adapter = configuration.getRegisteredAdapter(adapterName);
                IReceiver receiver = adapter.getReceiverByName(receiverName);
                if (receiver instanceof IThreadCountControllable) {
                    IThreadCountControllable tcc = (IThreadCountControllable) receiver;
                    if (tcc.isThreadCountControllable()) {
                        tcc.increaseThreadCount();
                    }
                }
                log.info("receiver [" + receiverName + "] increased threadcount on request of " + commandIssuedBy);
            }
        }
    } else if (action.equalsIgnoreCase("DECTHREADS")) {
        for (Configuration configuration : configurations) {
            if (configuration.getRegisteredAdapter(adapterName) != null) {
                IAdapter adapter = configuration.getRegisteredAdapter(adapterName);
                IReceiver receiver = adapter.getReceiverByName(receiverName);
                if (receiver instanceof IThreadCountControllable) {
                    IThreadCountControllable tcc = (IThreadCountControllable) receiver;
                    if (tcc.isThreadCountControllable()) {
                        tcc.decreaseThreadCount();
                    }
                }
                log.info("receiver [" + receiverName + "] decreased threadcount on request of " + commandIssuedBy);
            }
        }
    } else if (action.equalsIgnoreCase("SENDMESSAGE")) {
        try {
            // send job
            IbisLocalSender localSender = new IbisLocalSender();
            localSender.setJavaListener(receiverName);
            localSender.setIsolated(false);
            localSender.setName("AdapterJob");
            localSender.configure();
            localSender.open();
            try {
                localSender.sendMessage(null, "");
            } finally {
                localSender.close();
            }
        } catch (Exception e) {
            log.error("Error while sending message (as part of scheduled job execution)", e);
        }
    } else if (action.equalsIgnoreCase("MOVEMESSAGE")) {
        for (Configuration configuration : configurations) {
            if (configuration.getRegisteredAdapter(adapterName) != null) {
                IAdapter adapter = configuration.getRegisteredAdapter(adapterName);
                IReceiver receiver = adapter.getReceiverByName(receiverName);
                if (receiver instanceof ReceiverBase) {
                    ReceiverBase rb = (ReceiverBase) receiver;
                    ITransactionalStorage errorStorage = rb.getErrorStorage();
                    if (errorStorage == null) {
                        log.error("action [" + action + "] is only allowed for receivers with an ErrorStorage");
                    } else {
                        if (errorStorage instanceof JdbcTransactionalStorage) {
                            JdbcTransactionalStorage jdbcErrorStorage = (JdbcTransactionalStorage) rb.getErrorStorage();
                            IListener listener = rb.getListener();
                            if (listener instanceof EsbJmsListener) {
                                EsbJmsListener esbJmsListener = (EsbJmsListener) listener;
                                EsbUtils.receiveMessageAndMoveToErrorStorage(esbJmsListener, jdbcErrorStorage);
                            } else {
                                log.error("action [" + action + "] is currently only allowed for EsbJmsListener, not for type [" + listener.getClass().getName() + "]");
                            }
                        } else {
                            log.error("action [" + action + "] is currently only allowed for JdbcTransactionalStorage, not for type [" + errorStorage.getClass().getName() + "]");
                        }
                    }
                }
            }
        }
    }
}
Also used : IReceiver(nl.nn.adapterframework.core.IReceiver) IbisLocalSender(nl.nn.adapterframework.senders.IbisLocalSender) ReceiverBase(nl.nn.adapterframework.receivers.ReceiverBase) Configuration(nl.nn.adapterframework.configuration.Configuration) IThreadCountControllable(nl.nn.adapterframework.core.IThreadCountControllable) IListener(nl.nn.adapterframework.core.IListener) EsbJmsListener(nl.nn.adapterframework.extensions.esb.EsbJmsListener) IAdapter(nl.nn.adapterframework.core.IAdapter) SchedulerException(org.quartz.SchedulerException) ITransactionalStorage(nl.nn.adapterframework.core.ITransactionalStorage) JdbcTransactionalStorage(nl.nn.adapterframework.jdbc.JdbcTransactionalStorage)

Example 10 with ReceiverBase

use of nl.nn.adapterframework.receivers.ReceiverBase in project iaf by ibissource.

the class JobDef method recoverAdapters.

private void recoverAdapters(IbisManager ibisManager) {
    int countAdapter = 0;
    int countAdapterStateStarted = 0;
    int countReceiver = 0;
    int countReceiverStateStarted = 0;
    for (IAdapter iAdapter : ibisManager.getRegisteredAdapters()) {
        countAdapter++;
        if (iAdapter instanceof Adapter) {
            Adapter adapter = (Adapter) iAdapter;
            RunStateEnum adapterRunState = adapter.getRunState();
            if (adapterRunState.equals(RunStateEnum.ERROR)) {
                log.debug("trying to recover adapter [" + adapter.getName() + "]");
                try {
                    adapter.setRecover(true);
                    adapter.configure();
                } catch (ConfigurationException e) {
                    // do nothing
                    log.warn("error during recovering adapter [" + adapter.getName() + "]: " + e.getMessage());
                } finally {
                    adapter.setRecover(false);
                }
                if (adapter.configurationSucceeded()) {
                    adapter.stopRunning();
                    int count = 10;
                    while (count-- >= 0 && !adapter.getRunState().equals(RunStateEnum.STOPPED)) {
                        try {
                            Thread.sleep(1000);
                        } catch (InterruptedException e) {
                        // do nothing
                        }
                    }
                }
                // check for start is in method startRunning in Adapter self
                if (adapter.isAutoStart()) {
                    adapter.startRunning();
                }
                log.debug("finished recovering adapter [" + adapter.getName() + "]");
            }
            String message = "adapter [" + adapter.getName() + "] has state [" + adapterRunState + "]";
            adapterRunState = adapter.getRunState();
            if (adapterRunState.equals(RunStateEnum.STARTED)) {
                countAdapterStateStarted++;
                heartbeatLog.info(message);
            } else if (adapterRunState.equals(RunStateEnum.ERROR)) {
                heartbeatLog.error(message);
            } else {
                heartbeatLog.warn(message);
            }
            for (Iterator receiverIt = adapter.getReceiverIterator(); receiverIt.hasNext(); ) {
                countReceiver++;
                IReceiver iReceiver = (IReceiver) receiverIt.next();
                if (iReceiver instanceof ReceiverBase) {
                    ReceiverBase receiver = (ReceiverBase) iReceiver;
                    RunStateEnum receiverRunState = receiver.getRunState();
                    if (!adapterRunState.equals(RunStateEnum.ERROR) && receiverRunState.equals(RunStateEnum.ERROR)) {
                        log.debug("trying to recover receiver [" + receiver.getName() + "] of adapter [" + adapter.getName() + "]");
                        try {
                            if (receiver != null) {
                                receiver.setRecover(true);
                            }
                            adapter.configureReceiver(receiver);
                        } finally {
                            if (receiver != null) {
                                receiver.setRecover(false);
                            }
                        }
                        if (receiver != null) {
                            if (receiver.configurationSucceeded()) {
                                receiver.stopRunning();
                                int count = 10;
                                while (count-- >= 0 && !receiver.getRunState().equals(RunStateEnum.STOPPED)) {
                                    try {
                                        Thread.sleep(1000);
                                    } catch (InterruptedException e) {
                                        log.debug("Interrupted waiting for receiver to stop", e);
                                    }
                                }
                            }
                            // check for start is in method startRunning in
                            // ReceiverBase self
                            receiver.startRunning();
                            log.debug("finished recovering receiver [" + receiver.getName() + "] of adapter [" + adapter.getName() + "]");
                        }
                    }
                    receiverRunState = receiver.getRunState();
                    message = "receiver [" + receiver.getName() + "] of adapter [" + adapter.getName() + "] has state [" + receiverRunState + "]";
                    if (receiverRunState.equals(RunStateEnum.STARTED)) {
                        countReceiverStateStarted++;
                        heartbeatLog.info(message);
                    } else if (receiverRunState.equals(RunStateEnum.ERROR)) {
                        heartbeatLog.error(message);
                    } else {
                        heartbeatLog.warn(message);
                    }
                } else {
                    log.warn("will not try to recover receiver [" + iReceiver.getName() + "] of adapter [" + adapter.getName() + "], is not of type Receiver but [" + iAdapter.getClass().getName() + "]");
                }
            }
        } else {
            log.warn("will not try to recover adapter [" + iAdapter.getName() + "], is not of type Adapter but [" + iAdapter.getClass().getName() + "]");
        }
    }
    heartbeatLog.info("[" + countAdapterStateStarted + "/" + countAdapter + "] adapters and [" + countReceiverStateStarted + "/" + countReceiver + "] receivers have state [" + RunStateEnum.STARTED + "]");
}
Also used : IReceiver(nl.nn.adapterframework.core.IReceiver) ReceiverBase(nl.nn.adapterframework.receivers.ReceiverBase) RunStateEnum(nl.nn.adapterframework.util.RunStateEnum) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) Iterator(java.util.Iterator) Adapter(nl.nn.adapterframework.core.Adapter) IAdapter(nl.nn.adapterframework.core.IAdapter) IAdapter(nl.nn.adapterframework.core.IAdapter)

Aggregations

ReceiverBase (nl.nn.adapterframework.receivers.ReceiverBase)19 IAdapter (nl.nn.adapterframework.core.IAdapter)11 Iterator (java.util.Iterator)10 Adapter (nl.nn.adapterframework.core.Adapter)10 IListener (nl.nn.adapterframework.core.IListener)10 IReceiver (nl.nn.adapterframework.core.IReceiver)10 ITransactionalStorage (nl.nn.adapterframework.core.ITransactionalStorage)7 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)5 RestListener (nl.nn.adapterframework.http.RestListener)5 Configuration (nl.nn.adapterframework.configuration.Configuration)4 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)4 IOException (java.io.IOException)3 LinkedHashMap (java.util.LinkedHashMap)3 ConfigurationWarnings (nl.nn.adapterframework.configuration.ConfigurationWarnings)3 IThreadCountControllable (nl.nn.adapterframework.core.IThreadCountControllable)3 PipeLine (nl.nn.adapterframework.core.PipeLine)3 PipeRunException (nl.nn.adapterframework.core.PipeRunException)3 EsbJmsListener (nl.nn.adapterframework.extensions.esb.EsbJmsListener)3 MessageSendingPipe (nl.nn.adapterframework.pipes.MessageSendingPipe)3