Search in sources :

Example 1 with IThreadCountControllable

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

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

the class ReceiverBase method decreaseThreadCount.

public void decreaseThreadCount() {
    if (getListener() instanceof IThreadCountControllable) {
        IThreadCountControllable tcc = (IThreadCountControllable) getListener();
        tcc.decreaseThreadCount();
    }
    if (getListener() instanceof IPullingListener) {
        listenerContainer.decreaseThreadCount();
    }
}
Also used : IPullingListener(nl.nn.adapterframework.core.IPullingListener) IThreadCountControllable(nl.nn.adapterframework.core.IThreadCountControllable)

Example 3 with IThreadCountControllable

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

the class ReceiverBase method increaseThreadCount.

public void increaseThreadCount() {
    if (getListener() instanceof IThreadCountControllable) {
        IThreadCountControllable tcc = (IThreadCountControllable) getListener();
        tcc.increaseThreadCount();
    }
    if (getListener() instanceof IPullingListener) {
        listenerContainer.increaseThreadCount();
    }
}
Also used : IPullingListener(nl.nn.adapterframework.core.IPullingListener) IThreadCountControllable(nl.nn.adapterframework.core.IThreadCountControllable)

Example 4 with IThreadCountControllable

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

the class Receiver method decreaseThreadCount.

@Override
public void decreaseThreadCount() {
    if (getListener() instanceof IThreadCountControllable) {
        IThreadCountControllable tcc = (IThreadCountControllable) getListener();
        tcc.decreaseThreadCount();
    }
    if (getListener() instanceof IPullingListener) {
        listenerContainer.decreaseThreadCount();
    }
}
Also used : IPullingListener(nl.nn.adapterframework.core.IPullingListener) IThreadCountControllable(nl.nn.adapterframework.core.IThreadCountControllable)

Example 5 with IThreadCountControllable

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

the class PushingIfsaProviderListener method increaseThreadCount.

@Override
public void increaseThreadCount() {
    if (jmsConnector instanceof IThreadCountControllable) {
        IThreadCountControllable tcc = (IThreadCountControllable) jmsConnector;
        tcc.increaseThreadCount();
    }
}
Also used : IThreadCountControllable(nl.nn.adapterframework.core.IThreadCountControllable)

Aggregations

IThreadCountControllable (nl.nn.adapterframework.core.IThreadCountControllable)10 IPullingListener (nl.nn.adapterframework.core.IPullingListener)4 IListener (nl.nn.adapterframework.core.IListener)2 IReceiver (nl.nn.adapterframework.core.IReceiver)2 ITransactionalStorage (nl.nn.adapterframework.core.ITransactionalStorage)2 EsbJmsListener (nl.nn.adapterframework.extensions.esb.EsbJmsListener)2 ReceiverBase (nl.nn.adapterframework.receivers.ReceiverBase)2 Iterator (java.util.Iterator)1 Configuration (nl.nn.adapterframework.configuration.Configuration)1 HasPhysicalDestination (nl.nn.adapterframework.core.HasPhysicalDestination)1 HasSender (nl.nn.adapterframework.core.HasSender)1 IAdapter (nl.nn.adapterframework.core.IAdapter)1 ISender (nl.nn.adapterframework.core.ISender)1 PipeRunException (nl.nn.adapterframework.core.PipeRunException)1 RestListener (nl.nn.adapterframework.http.RestListener)1 JdbcTransactionalStorage (nl.nn.adapterframework.jdbc.JdbcTransactionalStorage)1 JmsListenerBase (nl.nn.adapterframework.jms.JmsListenerBase)1 JmsMessageBrowser (nl.nn.adapterframework.jms.JmsMessageBrowser)1 IbisLocalSender (nl.nn.adapterframework.senders.IbisLocalSender)1 RunStateEnum (nl.nn.adapterframework.util.RunStateEnum)1