Search in sources :

Example 6 with ProcessState

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

the class Receiver method configure.

/**
 * This method is called by the <code>IAdapter</code> to let the
 * receiver do things to initialize itself before the <code>startListening</code>
 * method is called.
 * @see #startRunning
 * @throws ConfigurationException when initialization did not succeed.
 */
@Override
public void configure() throws ConfigurationException {
    configurationSucceeded = false;
    try {
        super.configure();
        if (StringUtils.isEmpty(getName())) {
            if (getListener() != null) {
                setName(ClassUtils.nameOf(getListener()));
            } else {
                setName(ClassUtils.nameOf(this));
            }
        }
        registerEvent(RCV_CONFIGURED_MONITOR_EVENT);
        registerEvent(RCV_CONFIGURATIONEXCEPTION_MONITOR_EVENT);
        registerEvent(RCV_STARTED_RUNNING_MONITOR_EVENT);
        registerEvent(RCV_SHUTDOWN_MONITOR_EVENT);
        registerEvent(RCV_SUSPENDED_MONITOR_EVENT);
        registerEvent(RCV_RESUMED_MONITOR_EVENT);
        registerEvent(RCV_THREAD_EXIT_MONITOR_EVENT);
        TXNEW_PROC = SpringTxManagerProxy.getTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRES_NEW, getTransactionTimeout());
        // to use direct member variables).
        if (this.tmpInProcessStorage != null) {
            if (this.errorSender == null && messageBrowsers.get(ProcessState.ERROR) == null) {
                messageBrowsers.put(ProcessState.ERROR, this.tmpInProcessStorage);
                info("has errorStorage in inProcessStorage, setting inProcessStorage's type to 'errorStorage'. Please update the configuration to change the inProcessStorage element to an errorStorage element, since the inProcessStorage is no longer used.");
                getErrorStorage().setType(IMessageBrowser.StorageType.ERRORSTORAGE.getCode());
            } else {
                info("has inProcessStorage defined but also has an errorStorage or errorSender. InProcessStorage is not used and can be removed from the configuration.");
            }
            // Set temporary in-process storage pointer to null
            this.tmpInProcessStorage = null;
        }
        // Do propagate-name AFTER changing the errorStorage!
        propagateName();
        if (getListener() == null) {
            throw new ConfigurationException(getLogPrefix() + "has no listener");
        }
        if (!StringUtils.isEmpty(getElementToMove()) && !StringUtils.isEmpty(getElementToMoveChain())) {
            throw new ConfigurationException("cannot have both an elementToMove and an elementToMoveChain specified");
        }
        if (!(getHideMethod().equalsIgnoreCase("all")) && (!(getHideMethod().equalsIgnoreCase("firstHalf")))) {
            throw new ConfigurationException(getLogPrefix() + "invalid value for hideMethod [" + getHideMethod() + "], must be 'all' or 'firstHalf'");
        }
        if (getListener() instanceof ReceiverAware) {
            ((ReceiverAware) getListener()).setReceiver(this);
        }
        if (getListener() instanceof IPushingListener) {
            IPushingListener<M> pl = (IPushingListener<M>) getListener();
            pl.setHandler(this);
            pl.setExceptionListener(this);
        }
        if (getListener() instanceof IPortConnectedListener) {
            IPortConnectedListener<M> pcl = (IPortConnectedListener<M>) getListener();
            pcl.setReceiver(this);
        }
        if (getListener() instanceof IPullingListener) {
            setListenerContainer(createListenerContainer());
        }
        if (getListener() instanceof JdbcFacade) {
            ((JdbcFacade) getListener()).setTransacted(isTransacted());
        }
        if (getListener() instanceof JMSFacade) {
            ((JMSFacade) getListener()).setTransacted(isTransacted());
        }
        getListener().configure();
        if (getListener() instanceof HasPhysicalDestination) {
            info("has listener on " + ((HasPhysicalDestination) getListener()).getPhysicalDestinationName());
        }
        if (getListener() instanceof HasSender) {
            // only informational
            ISender sender = ((HasSender) getListener()).getSender();
            if (sender instanceof HasPhysicalDestination) {
                info("Listener has answer-sender on " + ((HasPhysicalDestination) sender).getPhysicalDestinationName());
            }
        }
        if (getListener() instanceof ITransactionRequirements) {
            ITransactionRequirements tr = (ITransactionRequirements) getListener();
            if (tr.transactionalRequired() && !isTransacted()) {
                ConfigurationWarnings.add(this, log, "listener type [" + ClassUtils.nameOf(getListener()) + "] requires transactional processing", SuppressKeys.TRANSACTION_SUPPRESS_KEY, getAdapter());
            // throw new ConfigurationException(msg);
            }
        }
        ISender sender = getSender();
        if (sender != null) {
            sender.configure();
            if (sender instanceof HasPhysicalDestination) {
                info("has answer-sender on " + ((HasPhysicalDestination) sender).getPhysicalDestinationName());
            }
        }
        ISender errorSender = getErrorSender();
        if (errorSender != null) {
            if (errorSender instanceof HasPhysicalDestination) {
                info("has errorSender to " + ((HasPhysicalDestination) errorSender).getPhysicalDestinationName());
            }
            errorSender.configure();
        }
        if (getListener() instanceof IHasProcessState) {
            knownProcessStates.addAll(((IHasProcessState) getListener()).knownProcessStates());
            targetProcessStates = ((IHasProcessState) getListener()).targetProcessStates();
            supportProgrammaticRetry = knownProcessStates.contains(ProcessState.INPROCESS);
        }
        ITransactionalStorage<Serializable> messageLog = getMessageLog();
        if (messageLog != null) {
            if (getListener() instanceof IProvidesMessageBrowsers && ((IProvidesMessageBrowsers) getListener()).getMessageBrowser(ProcessState.DONE) != null) {
                throw new ConfigurationException("listener with built-in messageLog cannot have external messageLog too");
            }
            messageLog.setName("messageLog of [" + getName() + "]");
            if (StringUtils.isEmpty(messageLog.getSlotId())) {
                messageLog.setSlotId(getName());
            }
            messageLog.setType(IMessageBrowser.StorageType.MESSAGELOG_RECEIVER.getCode());
            messageLog.configure();
            if (messageLog instanceof HasPhysicalDestination) {
                info("has messageLog in " + ((HasPhysicalDestination) messageLog).getPhysicalDestinationName());
            }
            knownProcessStates.add(ProcessState.DONE);
            messageBrowsers.put(ProcessState.DONE, messageLog);
            if (StringUtils.isNotEmpty(getLabelXPath()) || StringUtils.isNotEmpty(getLabelStyleSheet())) {
                labelTp = TransformerPool.configureTransformer0(getLogPrefix(), this, getLabelNamespaceDefs(), getLabelXPath(), getLabelStyleSheet(), OutputType.TEXT, false, null, 0);
            }
        }
        ITransactionalStorage<Serializable> errorStorage = getErrorStorage();
        if (errorStorage != null) {
            if (getListener() instanceof IProvidesMessageBrowsers && ((IProvidesMessageBrowsers) getListener()).getMessageBrowser(ProcessState.ERROR) != null) {
                throw new ConfigurationException("listener with built-in errorStorage cannot have external errorStorage too");
            }
            errorStorage.setName("errorStorage of [" + getName() + "]");
            if (StringUtils.isEmpty(errorStorage.getSlotId())) {
                errorStorage.setSlotId(getName());
            }
            errorStorage.setType(IMessageBrowser.StorageType.ERRORSTORAGE.getCode());
            errorStorage.configure();
            if (errorStorage instanceof HasPhysicalDestination) {
                info("has errorStorage to " + ((HasPhysicalDestination) errorStorage).getPhysicalDestinationName());
            }
            knownProcessStates.add(ProcessState.ERROR);
            messageBrowsers.put(ProcessState.ERROR, errorStorage);
            registerEvent(RCV_MESSAGE_TO_ERRORSTORE_EVENT);
        }
        if (getListener() instanceof IProvidesMessageBrowsers) {
            for (ProcessState state : knownProcessStates) {
                IMessageBrowser messageBrowser = ((IProvidesMessageBrowsers) getListener()).getMessageBrowser(state);
                if (messageBrowser != null && messageBrowser instanceof IConfigurable) {
                    ((IConfigurable) messageBrowser).configure();
                }
                messageBrowsers.put(state, messageBrowser);
            }
        }
        if (targetProcessStates == null) {
            targetProcessStates = ProcessState.getTargetProcessStates(knownProcessStates);
        }
        if (isTransacted() && errorSender == null && errorStorage == null && !knownProcessStates().contains(ProcessState.ERROR)) {
            ConfigurationWarnings.add(this, log, "sets transactionAttribute=" + getTransactionAttribute() + ", but has no errorSender or errorStorage. Messages processed with errors will be lost", SuppressKeys.TRANSACTION_SUPPRESS_KEY, getAdapter());
        }
        if (StringUtils.isNotEmpty(getCorrelationIDXPath()) || StringUtils.isNotEmpty(getCorrelationIDStyleSheet())) {
            correlationIDTp = TransformerPool.configureTransformer0(getLogPrefix(), this, getCorrelationIDNamespaceDefs(), getCorrelationIDXPath(), getCorrelationIDStyleSheet(), OutputType.TEXT, false, null, 0);
        }
        if (StringUtils.isNotEmpty(getHideRegex()) && getErrorStorage() != null && StringUtils.isEmpty(getErrorStorage().getHideRegex())) {
            getErrorStorage().setHideRegex(getHideRegex());
            getErrorStorage().setHideMethod(getHideMethod());
        }
        if (StringUtils.isNotEmpty(getHideRegex()) && getMessageLog() != null && StringUtils.isEmpty(getMessageLog().getHideRegex())) {
            getMessageLog().setHideRegex(getHideRegex());
            getMessageLog().setHideMethod(getHideMethod());
        }
    } catch (Throwable t) {
        ConfigurationException e = null;
        if (t instanceof ConfigurationException) {
            e = (ConfigurationException) t;
        } else {
            e = new ConfigurationException("Exception configuring receiver [" + getName() + "]", t);
        }
        throwEvent(RCV_CONFIGURATIONEXCEPTION_MONITOR_EVENT);
        log.debug(getLogPrefix() + "Errors occured during configuration, setting runstate to ERROR");
        runState.setRunState(RunState.ERROR);
        throw e;
    }
    if (adapter != null) {
        adapter.getMessageKeeper().add(getLogPrefix() + "initialization complete");
    }
    throwEvent(RCV_CONFIGURED_MONITOR_EVENT);
    configurationSucceeded = true;
    if (isInRunState(RunState.ERROR)) {
        // if the adapter was previously in state ERROR, after a successful configure, reset it's state
        runState.setRunState(RunState.STOPPED);
    }
}
Also used : Serializable(java.io.Serializable) IProvidesMessageBrowsers(nl.nn.adapterframework.core.IProvidesMessageBrowsers) IMessageBrowser(nl.nn.adapterframework.core.IMessageBrowser) JMSFacade(nl.nn.adapterframework.jms.JMSFacade) HasSender(nl.nn.adapterframework.core.HasSender) IConfigurable(nl.nn.adapterframework.core.IConfigurable) IHasProcessState(nl.nn.adapterframework.core.IHasProcessState) ProcessState(nl.nn.adapterframework.core.ProcessState) IPullingListener(nl.nn.adapterframework.core.IPullingListener) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) ISender(nl.nn.adapterframework.core.ISender) IHasProcessState(nl.nn.adapterframework.core.IHasProcessState) ITransactionRequirements(nl.nn.adapterframework.core.ITransactionRequirements) IPushingListener(nl.nn.adapterframework.core.IPushingListener) IPortConnectedListener(nl.nn.adapterframework.core.IPortConnectedListener) JdbcFacade(nl.nn.adapterframework.jdbc.JdbcFacade) HasPhysicalDestination(nl.nn.adapterframework.core.HasPhysicalDestination)

Example 7 with ProcessState

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

the class TransactionalStorage method getTargetProcessStateInfo.

public Map<ProcessState, Map<String, String>> getTargetProcessStateInfo(Set<ProcessState> targetProcessStates) {
    if (targetProcessStates == null) {
        return null;
    }
    Map<ProcessState, Map<String, String>> result = new LinkedHashMap<ProcessState, Map<String, String>>();
    for (ProcessState ps : targetProcessStates) {
        Map<String, String> psInfo = new HashMap<String, String>();
        psInfo.put("name", ps.getName());
        result.put(ps, psInfo);
    }
    return result;
}
Also used : ProcessState(nl.nn.adapterframework.core.ProcessState) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 8 with ProcessState

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

the class TransactionalStorage method changeProcessState.

@POST
@RolesAllowed({ "IbisDataAdmin", "IbisAdmin", "IbisTester" })
@Path("/adapters/{adapterName}/receivers/{receiverName}/stores/{processState}/move/{targetState}")
@Relation("pipeline")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response changeProcessState(@PathParam("adapterName") String adapterName, @PathParam("receiverName") String receiverName, @PathParam("processState") String processState, @PathParam("targetState") String targetState, MultipartBody input) throws ApiException {
    Adapter adapter = getIbisManager().getRegisteredAdapter(adapterName);
    if (adapter == null) {
        throw new ApiException("Adapter not found!");
    }
    Receiver<?> receiver = adapter.getReceiverByName(receiverName);
    if (receiver == null) {
        throw new ApiException("Receiver [" + receiverName + "] not found!");
    }
    String[] messageIds = getMessages(input);
    ProcessState currentState = ProcessState.getProcessStateFromName(processState);
    Set<ProcessState> targetProcessStates = receiver.targetProcessStates().get(currentState);
    ProcessState targetPS = ProcessState.getProcessStateFromName(targetState);
    List<String> errorMessages = new ArrayList<>();
    if (targetProcessStates != null && targetProcessStates.contains(targetPS)) {
        IMessageBrowser<?> store = receiver.getMessageBrowser(currentState);
        for (int i = 0; i < messageIds.length; i++) {
            try {
                if (receiver.changeProcessState(store.browseMessage(messageIds[i]), targetPS, "admin requested move") == null) {
                    errorMessages.add("could not move message [" + messageIds[i] + "]");
                }
            } catch (ListenerException e) {
                errorMessages.add(e.getMessage());
            }
        }
    } else {
        throw new ApiException("It is not allowed to move messages from [" + processState + "] " + "to [" + targetState + "]");
    }
    if (errorMessages.isEmpty()) {
        return Response.status(Response.Status.OK).build();
    }
    return Response.status(Response.Status.ACCEPTED).entity(errorMessages).build();
}
Also used : ProcessState(nl.nn.adapterframework.core.ProcessState) ListenerException(nl.nn.adapterframework.core.ListenerException) ArrayList(java.util.ArrayList) Adapter(nl.nn.adapterframework.core.Adapter) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes)

Example 9 with ProcessState

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

the class ShowConfigurationStatus method mapAdapterReceivers.

private ArrayList<Object> mapAdapterReceivers(Adapter adapter, boolean showPendingMsgCount) {
    ArrayList<Object> receivers = new ArrayList<Object>();
    for (Receiver<?> receiver : adapter.getReceivers()) {
        Map<String, Object> receiverInfo = new HashMap<>();
        RunState receiverRunState = receiver.getRunState();
        receiverInfo.put("name", receiver.getName());
        receiverInfo.put("state", receiverRunState.name().toLowerCase());
        Map<String, Object> messages = new HashMap<String, Object>(3);
        messages.put("received", receiver.getMessagesReceived());
        messages.put("retried", receiver.getMessagesRetried());
        messages.put("rejected", receiver.getMessagesRejected());
        receiverInfo.put("messages", messages);
        Set<ProcessState> knownStates = receiver.knownProcessStates();
        Map<ProcessState, Object> tsInfo = new LinkedHashMap<ProcessState, Object>();
        for (ProcessState state : knownStates) {
            IMessageBrowser<?> ts = receiver.getMessageBrowser(state);
            if (ts != null) {
                Map<String, Object> info = new HashMap<>();
                try {
                    info.put("numberOfMessages", ts.getMessageCount());
                } catch (Exception e) {
                    log.warn("Cannot determine number of messages in process state [" + state + "]", e);
                    info.put("numberOfMessages", "error");
                }
                info.put("name", state.getName());
                tsInfo.put(state, info);
            }
        }
        receiverInfo.put("transactionalStores", tsInfo);
        ISender sender = null;
        IListener<?> listener = receiver.getListener();
        if (listener != null) {
            Map<String, Object> listenerInfo = new HashMap<String, Object>();
            listenerInfo.put("name", listener.getName());
            listenerInfo.put("class", ClassUtils.nameOf(listener));
            if (listener instanceof HasPhysicalDestination) {
                String pd = ((HasPhysicalDestination) receiver.getListener()).getPhysicalDestinationName();
                listenerInfo.put("destination", pd);
            }
            if (listener instanceof HasSender) {
                sender = ((HasSender) listener).getSender();
            }
            boolean isRestListener = (listener instanceof RestListener);
            listenerInfo.put("isRestListener", isRestListener);
            if (isRestListener) {
                RestListener rl = (RestListener) listener;
                listenerInfo.put("restUriPattern", rl.getRestUriPattern());
                listenerInfo.put("isView", rl.isView());
            }
            receiverInfo.put("listener", listenerInfo);
        }
        if ((listener instanceof JmsListenerBase) && showPendingMsgCount) {
            JmsListenerBase jlb = (JmsListenerBase) listener;
            JmsBrowser<javax.jms.Message> jmsBrowser;
            if (StringUtils.isEmpty(jlb.getMessageSelector())) {
                jmsBrowser = new JmsBrowser<>();
            } else {
                jmsBrowser = new JmsBrowser<>(jlb.getMessageSelector());
            }
            jmsBrowser.setName("MessageBrowser_" + jlb.getName());
            jmsBrowser.setJmsRealm(jlb.getJmsRealmName());
            jmsBrowser.setDestinationName(jlb.getDestinationName());
            jmsBrowser.setDestinationType(jlb.getDestinationType());
            String numMsgs;
            try {
                int messageCount = jmsBrowser.getMessageCount();
                numMsgs = String.valueOf(messageCount);
            } catch (Throwable t) {
                log.warn("Cannot determine number of messages in errorstore [" + jmsBrowser.getName() + "]", t);
                numMsgs = "?";
            }
            receiverInfo.put("pendingMessagesCount", numMsgs);
        }
        boolean isEsbJmsFFListener = false;
        if (listener instanceof EsbJmsListener) {
            EsbJmsListener ejl = (EsbJmsListener) listener;
            if (ejl.getMessageProtocol() != null) {
                if (ejl.getMessageProtocol().equalsIgnoreCase("FF")) {
                    isEsbJmsFFListener = true;
                }
                if (showPendingMsgCount) {
                    String esbNumMsgs = EsbUtils.getQueueMessageCount(ejl);
                    if (esbNumMsgs == null) {
                        esbNumMsgs = "?";
                    }
                    receiverInfo.put("esbPendingMessagesCount", esbNumMsgs);
                }
            }
        }
        receiverInfo.put("isEsbJmsFFListener", isEsbJmsFFListener);
        ISender rsender = receiver.getSender();
        if (rsender != null) {
            // this sender has preference, but avoid overwriting listeners sender with null
            sender = rsender;
        }
        if (sender != null) {
            receiverInfo.put("senderName", sender.getName());
            receiverInfo.put("senderClass", ClassUtils.nameOf(sender));
            if (sender instanceof HasPhysicalDestination) {
                String pd = ((HasPhysicalDestination) sender).getPhysicalDestinationName();
                receiverInfo.put("senderDestination", pd);
            }
        }
        if (receiver.isThreadCountReadable()) {
            receiverInfo.put("threadCount", receiver.getCurrentThreadCount());
            receiverInfo.put("maxThreadCount", receiver.getMaxThreadCount());
        }
        if (receiver.isThreadCountControllable()) {
            receiverInfo.put("threadCountControllable", "true");
        }
        receivers.add(receiverInfo);
    }
    return receivers;
}
Also used : MessageKeeperMessage(nl.nn.adapterframework.util.MessageKeeperMessage) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) ISender(nl.nn.adapterframework.core.ISender) EsbJmsListener(nl.nn.adapterframework.extensions.esb.EsbJmsListener) HasSender(nl.nn.adapterframework.core.HasSender) SAXException(org.xml.sax.SAXException) TransformerException(javax.xml.transform.TransformerException) ListenerException(nl.nn.adapterframework.core.ListenerException) IOException(java.io.IOException) RunState(nl.nn.adapterframework.util.RunState) ProcessState(nl.nn.adapterframework.core.ProcessState) RestListener(nl.nn.adapterframework.http.RestListener) JmsListenerBase(nl.nn.adapterframework.jms.JmsListenerBase) HasPhysicalDestination(nl.nn.adapterframework.core.HasPhysicalDestination)

Example 10 with ProcessState

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

the class EnumUtilsTest method testParseEnum.

@Test
public void testParseEnum() {
    ProcessState state = EnumUtils.parse(ProcessState.class, "available");
    assertNotNull(state);
    assertEquals("Available", state.getName());
    ProcessState state2 = EnumUtils.parseNormal(ProcessState.class, "fieldName", "available");
    assertNotNull(state2);
    assertEquals("Available", state2.getName());
}
Also used : ProcessState(nl.nn.adapterframework.core.ProcessState) Test(org.junit.Test)

Aggregations

ProcessState (nl.nn.adapterframework.core.ProcessState)10 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)5 LinkedHashMap (java.util.LinkedHashMap)4 IHasProcessState (nl.nn.adapterframework.core.IHasProcessState)4 ListenerException (nl.nn.adapterframework.core.ListenerException)4 HashMap (java.util.HashMap)3 ISender (nl.nn.adapterframework.core.ISender)3 Serializable (java.io.Serializable)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 RolesAllowed (javax.annotation.security.RolesAllowed)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 Adapter (nl.nn.adapterframework.core.Adapter)2 HasPhysicalDestination (nl.nn.adapterframework.core.HasPhysicalDestination)2 HasSender (nl.nn.adapterframework.core.HasSender)2 SenderException (nl.nn.adapterframework.core.SenderException)2 TimeoutException (nl.nn.adapterframework.core.TimeoutException)2 Message (nl.nn.adapterframework.stream.Message)2 IOException (java.io.IOException)1