Search in sources :

Example 6 with IListener

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

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

the class ReceiverBase method propagateName.

protected void propagateName() {
    IListener listener = getListener();
    if (listener != null && StringUtils.isEmpty(listener.getName())) {
        listener.setName("listener of [" + getName() + "]");
    }
    ISender errorSender = getErrorSender();
    if (errorSender != null) {
        errorSender.setName("errorSender of [" + getName() + "]");
    }
    ITransactionalStorage errorStorage = getErrorStorage();
    if (errorStorage != null) {
        errorStorage.setName("errorStorage of [" + getName() + "]");
    }
    ISender answerSender = getSender();
    if (answerSender != null) {
        answerSender.setName("answerSender of [" + getName() + "]");
    }
}
Also used : ISender(nl.nn.adapterframework.core.ISender) IListener(nl.nn.adapterframework.core.IListener) ITransactionalStorage(nl.nn.adapterframework.core.ITransactionalStorage)

Example 8 with IListener

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

the class Wsdl method service.

protected void service(XMLStreamWriter w, String servlet) throws XMLStreamException, NamingException {
    String httpPrefix = "";
    String jmsPrefix = "";
    if (httpActive && jmsActive) {
        httpPrefix = "Http";
        jmsPrefix = "Jms";
    }
    if (httpActive) {
        httpService(w, servlet, httpPrefix);
    }
    if (jmsActive) {
        for (IListener listener : WsdlUtils.getListeners(pipeLine.getAdapter())) {
            if (listener instanceof JmsListener) {
                jmsService(w, (JmsListener) listener, jmsPrefix);
            }
        }
    }
}
Also used : JmsListener(nl.nn.adapterframework.jms.JmsListener) IListener(nl.nn.adapterframework.core.IListener)

Example 9 with IListener

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

the class EsbJmsListenerChecker method doCheck.

public static void doCheck(IbisManager ibisManager, PlatformTransactionManager txManager, String logPrefix) {
    long idleTimeout = AppConstants.getInstance().getInt("check.esbJmsListeners.idleTimeout", 300) * 1000;
    for (Configuration configuration : ibisManager.getConfigurations()) {
        String msg;
        List<String> jmsRealmNames = new ArrayList<String>();
        for (IAdapter adapter : configuration.getRegisteredAdapters()) {
            if (adapter instanceof Adapter) {
                for (Iterator receiverIt = adapter.getReceiverIterator(); receiverIt.hasNext(); ) {
                    IReceiver receiver = (IReceiver) receiverIt.next();
                    if (receiver instanceof ReceiverBase) {
                        ReceiverBase rb = (ReceiverBase) receiver;
                        if (rb.getRunState().equals(RunStateEnum.STARTED)) {
                            // if (true) {
                            long lastMessageDate = rb.getLastMessageDate();
                            if (lastMessageDate == 0 || System.currentTimeMillis() - lastMessageDate > idleTimeout) {
                                IListener listener = rb.getListener();
                                if (listener instanceof EsbJmsListener) {
                                    EsbJmsListener esbJmsListener = (EsbJmsListener) listener;
                                    if (esbJmsListener.getMessageProtocol().equals("FF")) {
                                        Object managedConnectionFactory = null;
                                        try {
                                            managedConnectionFactory = esbJmsListener.getManagedConnectionFactory();
                                            if (managedConnectionFactory == null) {
                                                msg = logPrefix + "could not get managed connection factory";
                                                warn(adapter, msg);
                                            } else {
                                                String contextFactoryClassname = getContextFactoryClassname(managedConnectionFactory);
                                                String providerURL = getProviderURL(managedConnectionFactory);
                                                String authDataAlias = getAuthDataAlias(managedConnectionFactory);
                                                String username = null;
                                                String password = null;
                                                msg = logPrefix + "found esbJmsListener [" + esbJmsListener.getName() + "] with managedConnectionFactoryClassname [" + managedConnectionFactory.getClass().getName() + "] having contextFactoryClassname [" + contextFactoryClassname + "] providerURL [" + providerURL + "] authDataAlias [" + authDataAlias + "]";
                                                if (authDataAlias != null) {
                                                    CredentialFactory cf = new CredentialFactory(authDataAlias, null, null);
                                                    username = cf.getUsername();
                                                    password = cf.getPassword();
                                                }
                                                if (contextFactoryClassname != null && contextFactoryClassname.equals("com.tibco.tibjms.naming.TibjmsInitialContextFactory")) {
                                                    log.debug(msg + ", checking...");
                                                    long age = getTibcoQueueFirstMessageAge(providerURL, authDataAlias, username, password, esbJmsListener.getPhysicalDestinationShortName(), esbJmsListener.getMessageSelector());
                                                    if (age > idleTimeout) {
                                                        msg = logPrefix + "most probably esbJmsListener [" + esbJmsListener.getName() + "] has lost connection with queue [" + esbJmsListener.getPhysicalDestinationShortName() + "]";
                                                        warn(adapter, msg);
                                                    }
                                                } else {
                                                    log.debug(msg + ", ignoring...");
                                                }
                                            }
                                        } catch (Throwable t) {
                                            msg = logPrefix + "exception on checking queue [" + esbJmsListener.getPhysicalDestinationShortName() + "]";
                                            warn(adapter, msg, t);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : ReceiverBase(nl.nn.adapterframework.receivers.ReceiverBase) Configuration(nl.nn.adapterframework.configuration.Configuration) CredentialFactory(nl.nn.adapterframework.util.CredentialFactory) IListener(nl.nn.adapterframework.core.IListener) ArrayList(java.util.ArrayList) Adapter(nl.nn.adapterframework.core.Adapter) IAdapter(nl.nn.adapterframework.core.IAdapter) IReceiver(nl.nn.adapterframework.core.IReceiver) Iterator(java.util.Iterator) IAdapter(nl.nn.adapterframework.core.IAdapter)

Example 10 with IListener

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

the class DefaultIbisManager method unload.

private void unload(Configuration configuration) {
    configuration.setUnloadInProgressOrDone(true);
    while (configuration.getStartAdapterThreads().size() > 0) {
        log.debug("Waiting for start threads to end: " + configuration.getStartAdapterThreads());
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            log.warn("Interrupted waiting for start threads to end", e);
        }
    }
    stopAdapters(configuration);
    while (configuration.getStopAdapterThreads().size() > 0) {
        log.debug("Waiting for stop threads to end: " + configuration.getStopAdapterThreads());
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            log.warn("Interrupted waiting for stop threads to end", e);
        }
    }
    // destroy all jmsContainers
    for (int i = 0; i < configuration.getRegisteredAdapters().size(); i++) {
        IAdapter adapter = configuration.getRegisteredAdapter(i);
        Iterator recIt = adapter.getReceiverIterator();
        if (recIt.hasNext()) {
            while (recIt.hasNext()) {
                IReceiver receiver = (IReceiver) recIt.next();
                if (receiver instanceof ReceiverBase) {
                    ReceiverBase rb = (ReceiverBase) receiver;
                    IListener listener = rb.getListener();
                    if (listener instanceof PushingJmsListener) {
                        PushingJmsListener pjl = (PushingJmsListener) listener;
                        pjl.destroy();
                    }
                }
            }
        }
    }
    while (configuration.getRegisteredAdapters().size() > 0) {
        IAdapter adapter = configuration.getRegisteredAdapter(0);
        AdapterService adapterService = configuration.getAdapterService();
        adapterService.unRegisterAdapter(adapter);
    }
    configurations.remove(configuration);
}
Also used : AdapterService(nl.nn.adapterframework.configuration.AdapterService) IReceiver(nl.nn.adapterframework.core.IReceiver) ReceiverBase(nl.nn.adapterframework.receivers.ReceiverBase) IListener(nl.nn.adapterframework.core.IListener) Iterator(java.util.Iterator) PushingJmsListener(nl.nn.adapterframework.jms.PushingJmsListener) IAdapter(nl.nn.adapterframework.core.IAdapter)

Aggregations

IListener (nl.nn.adapterframework.core.IListener)16 ReceiverBase (nl.nn.adapterframework.receivers.ReceiverBase)10 IReceiver (nl.nn.adapterframework.core.IReceiver)8 ArrayList (java.util.ArrayList)6 Iterator (java.util.Iterator)6 IAdapter (nl.nn.adapterframework.core.IAdapter)6 ITransactionalStorage (nl.nn.adapterframework.core.ITransactionalStorage)6 HashMap (java.util.HashMap)5 Adapter (nl.nn.adapterframework.core.Adapter)5 ISender (nl.nn.adapterframework.core.ISender)5 RestListener (nl.nn.adapterframework.http.RestListener)5 HasPhysicalDestination (nl.nn.adapterframework.core.HasPhysicalDestination)4 XmlBuilder (nl.nn.adapterframework.util.XmlBuilder)4 IThreadCountControllable (nl.nn.adapterframework.core.IThreadCountControllable)3 PipeRunException (nl.nn.adapterframework.core.PipeRunException)3 EsbJmsListener (nl.nn.adapterframework.extensions.esb.EsbJmsListener)3 MessageSendingPipe (nl.nn.adapterframework.pipes.MessageSendingPipe)3 IOException (java.io.IOException)2 Date (java.util.Date)2 LinkedHashMap (java.util.LinkedHashMap)2