Search in sources :

Example 16 with IAdapter

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

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

the class DefaultIbisManager method getSortedStartedAdapterNames.

public List<String> getSortedStartedAdapterNames() {
    List<String> startedAdapters = new ArrayList<String>();
    for (IAdapter adapter : getRegisteredAdapters()) {
        // add the adapterName if it is started.
        if (adapter.getRunState().equals(RunStateEnum.STARTED)) {
            startedAdapters.add(adapter.getName());
        }
    }
    Collections.sort(startedAdapters, String.CASE_INSENSITIVE_ORDER);
    return startedAdapters;
}
Also used : ArrayList(java.util.ArrayList) IAdapter(nl.nn.adapterframework.core.IAdapter)

Example 18 with IAdapter

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

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

the class DirectoryScanningAdapterServiceImpl method scan.

protected synchronized void scan() {
    LOG.debug("Scanning " + directory);
    if (directory.exists()) {
        if (directory.isDirectory()) {
            File[] files = directory.listFiles(IS_XML);
            {
                Map<File, Collection<IAdapter>> toRemove = new HashMap<File, Collection<IAdapter>>();
                toRemove.putAll(watched);
                for (File file : files) {
                    toRemove.remove(file);
                }
                for (Map.Entry<File, Collection<IAdapter>> removedAdapter : toRemove.entrySet()) {
                    LOG.info("File " + removedAdapter.getKey() + " not found any more, unregistering adapters" + removedAdapter.getValue());
                    for (IAdapter a : removedAdapter.getValue()) {
                        stopAndUnRegister(a);
                    }
                    watched.remove(removedAdapter.getKey());
                }
            }
            for (File file : files) {
                try {
                    Map<String, IAdapter> adapters = read(file.toURI().toURL());
                    if (adapters == null) {
                        LOG.warn("Could not digest " + file);
                        continue;
                    }
                    if (file.lastModified() > lastScan || !watched.containsKey(file)) {
                        if (watched.containsKey(file)) {
                            for (IAdapter adapter : watched.get(file)) {
                                stopAndUnRegister(adapter);
                            }
                        }
                        for (Map.Entry<String, IAdapter> entry : adapters.entrySet()) {
                            if (super.getAdapters().get(entry.getValue().getName()) == null) {
                                registerAndStart(entry.getValue());
                            } else {
                                LOG.warn("Cannot register adapter " + entry.getValue().getName() + " because it is registered already");
                            }
                        }
                        watched.put(file, adapters.values());
                    }
                } catch (MalformedURLException e) {
                    LOG.error(e.getMessage(), e);
                } catch (ConfigurationException e) {
                    LOG.error(e.getMessage(), e);
                } catch (SAXException e) {
                    LOG.error(e.getMessage(), e);
                } catch (IOException e) {
                    LOG.error(e.getMessage(), e);
                } catch (InterruptedException e) {
                    LOG.error(e.getMessage(), e);
                }
            }
        } else {
            LOG.warn("" + directory + " is not a directory");
        }
    } else {
        LOG.debug("" + directory + " does not exist");
    }
    lastScan = System.currentTimeMillis();
    notify();
}
Also used : MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) Collection(java.util.Collection) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map) IAdapter(nl.nn.adapterframework.core.IAdapter)

Example 20 with IAdapter

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

the class Configuration method getSortedStartedAdapterNames.

public List<String> getSortedStartedAdapterNames() {
    List<String> startedAdapters = new ArrayList<String>();
    for (int i = 0; i < getRegisteredAdapters().size(); i++) {
        IAdapter adapter = getRegisteredAdapter(i);
        // add the adapterName if it is started.
        if (adapter.getRunState().equals(RunStateEnum.STARTED)) {
            startedAdapters.add(adapter.getName());
        }
    }
    Collections.sort(startedAdapters, String.CASE_INSENSITIVE_ORDER);
    return startedAdapters;
}
Also used : ArrayList(java.util.ArrayList) IAdapter(nl.nn.adapterframework.core.IAdapter)

Aggregations

IAdapter (nl.nn.adapterframework.core.IAdapter)41 Adapter (nl.nn.adapterframework.core.Adapter)15 Iterator (java.util.Iterator)13 ArrayList (java.util.ArrayList)12 ReceiverBase (nl.nn.adapterframework.receivers.ReceiverBase)11 IReceiver (nl.nn.adapterframework.core.IReceiver)10 IOException (java.io.IOException)8 List (java.util.List)8 Configuration (nl.nn.adapterframework.configuration.Configuration)7 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)7 HashMap (java.util.HashMap)6 LinkedList (java.util.LinkedList)6 IListener (nl.nn.adapterframework.core.IListener)6 PipeRunException (nl.nn.adapterframework.core.PipeRunException)6 ITransactionalStorage (nl.nn.adapterframework.core.ITransactionalStorage)5 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 IPipe (nl.nn.adapterframework.core.IPipe)4 PipeLineResult (nl.nn.adapterframework.core.PipeLineResult)4 XmlBuilder (nl.nn.adapterframework.util.XmlBuilder)4