Search in sources :

Example 21 with IAdapter

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

the class ServiceClassLoader method reload.

@Override
public void reload() throws ConfigurationException {
    super.reload();
    if (adapterName == null) {
        throw new ConfigurationException("Name of adapter to provide configuration jar not specified");
    }
    IAdapter adapter = ibisManager.getRegisteredAdapter(adapterName);
    if (adapter != null) {
        IPipeLineSession pipeLineSession = new PipeLineSessionBase();
        PipeLineResult processResult = adapter.processMessage(getCorrelationId(), configurationName, pipeLineSession);
        Object object = pipeLineSession.get("configurationJar");
        if (object != null) {
            if (object instanceof byte[]) {
                readResources((byte[]) object, configurationName);
            } else {
                throw new ConfigurationException("SessionKey configurationJar not a byte array");
            }
        } else {
            throw new ConfigurationException("SessionKey configurationJar not found");
        }
    } else {
        throw new ConfigurationException("Could not find adapter: " + adapterName);
    }
}
Also used : ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) PipeLineResult(nl.nn.adapterframework.core.PipeLineResult) IAdapter(nl.nn.adapterframework.core.IAdapter) IPipeLineSession(nl.nn.adapterframework.core.IPipeLineSession) PipeLineSessionBase(nl.nn.adapterframework.core.PipeLineSessionBase)

Example 22 with IAdapter

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

Example 23 with IAdapter

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

the class Trigger method setSources.

/**
 * set List of all throwers that can trigger this Trigger.
 */
public void setSources(String[] sourcesArr) {
    log.debug(getLogPrefix() + "setSources()");
    List<EventThrowing> list = MonitorManager.getInstance().getEventSources((List<String>) null);
    log.debug(getLogPrefix() + "setSources() clearing adapterFilter");
    adapterFilters.clear();
    for (int i = 0; i < list.size(); i++) {
        EventThrowing thrower = (EventThrowing) list.get(i);
        IAdapter adapter = thrower.getAdapter();
        String adaptername;
        String sourcename;
        if (adapter == null) {
            adaptername = "-";
        } else {
            adaptername = adapter.getName();
        }
        sourcename = adaptername + " / " + thrower.getEventSourceName();
        // log.debug("setSources() checking for source ["+sourcename+"]");
        for (int j = 0; j < sourcesArr.length; j++) {
            if (sourcesArr[j].equals(sourcename)) {
                AdapterFilter af = (AdapterFilter) adapterFilters.get(adaptername);
                if (af == null) {
                    af = new AdapterFilter();
                    af.setAdapter(adaptername);
                    log.debug(getLogPrefix() + "setSources() registered adapter [" + adaptername + "]");
                    registerAdapterFilter(af);
                }
                af.registerSubOject(thrower.getEventSourceName());
                log.debug(getLogPrefix() + "setSources() registered source [" + thrower.getEventSourceName() + "] on adapter [" + adapter.getName() + "]");
                break;
            }
        }
    }
}
Also used : IAdapter(nl.nn.adapterframework.core.IAdapter)

Example 24 with IAdapter

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

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

the class IbisTester method testStartAdapters.

public boolean testStartAdapters() {
    BasicConfigurator.configure();
    Logger.getRootLogger().setLevel(Level.INFO);
    // remove AppConstants because it can be present from another JUnit test
    AppConstants.removeInstance();
    appConstants = AppConstants.getInstance();
    webAppPath = getWebContentDirectory();
    String projectBaseDir = Misc.getProjectBaseDir();
    appConstants.put("project.basedir", projectBaseDir);
    debug("***set property with name [project.basedir] and value [" + projectBaseDir + "]***");
    appConstants.put("create.dbscript.location", "create_database_h2.sql");
    // appConstants.put("validators.disabled", "true");
    // appConstants.put("xmlValidator.lazyInit", "true");
    // appConstants.put("xmlValidator.maxInitialised", "200");
    ibisContext = new IbisContext();
    long configLoadStartTime = System.currentTimeMillis();
    ibisContext.init();
    long configLoadEndTime = System.currentTimeMillis();
    debug("***configuration loaded in [" + (configLoadEndTime - configLoadStartTime) + "] msec***");
    int adaptersStarted = 0;
    int adaptersCount = 0;
    List<IAdapter> registeredAdapters = ibisContext.getIbisManager().getRegisteredAdapters();
    for (IAdapter adapter : registeredAdapters) {
        adaptersCount++;
        RunStateEnum runState = adapter.getRunState();
        if (!(RunStateEnum.STARTED).equals(runState)) {
            debug("adapter [" + adapter.getName() + "] has state [" + runState + "], will retry...");
            int count = 30;
            while (count-- > 0 && !(RunStateEnum.STARTED).equals(runState)) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                runState = adapter.getRunState();
                if (!(RunStateEnum.STARTED).equals(runState)) {
                    debug("adapter [" + adapter.getName() + "] has state [" + runState + "], retries left [" + count + "]");
                } else {
                    debug("adapter [" + adapter.getName() + "] has state [" + runState + "]");
                }
            }
        } else {
            debug("adapter [" + adapter.getName() + "] has state [" + runState + "]");
        }
        if ((RunStateEnum.STARTED).equals(runState)) {
            adaptersStarted++;
        } else {
            error("adapter [" + adapter.getName() + "] has state [" + runState + "]");
        }
    }
    String msg = "adapters started [" + adaptersStarted + "] from [" + adaptersCount + "]";
    if (adaptersCount == adaptersStarted) {
        debug(msg);
        return true;
    } else {
        error(msg);
        return false;
    }
}
Also used : IbisContext(nl.nn.adapterframework.configuration.IbisContext) RunStateEnum(nl.nn.adapterframework.util.RunStateEnum) 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