Search in sources :

Example 16 with ITransactionalStorage

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

the class ShowConfigurationStatus method toReceiversXml.

private XmlBuilder toReceiversXml(Configuration configurationSelected, Adapter adapter, ShowConfigurationStatusManager showConfigurationStatusManager, ShowConfigurationStatusAdapterManager showConfigurationStatusAdapterManager) {
    Iterator recIt = adapter.getReceiverIterator();
    if (!recIt.hasNext()) {
        return null;
    }
    XmlBuilder receiversXML = new XmlBuilder("receivers");
    while (recIt.hasNext()) {
        IReceiver receiver = (IReceiver) recIt.next();
        XmlBuilder receiverXML = new XmlBuilder("receiver");
        receiversXML.addSubElement(receiverXML);
        RunStateEnum receiverRunState = receiver.getRunState();
        receiverXML.addAttribute("isStarted", "" + (receiverRunState.equals(RunStateEnum.STARTED)));
        receiverXML.addAttribute("state", receiverRunState.toString());
        if (receiverRunState.equals(RunStateEnum.STARTING)) {
            showConfigurationStatusManager.countReceiverStateStarting++;
        } else if ((receiverRunState.equals(RunStateEnum.STARTED))) {
            showConfigurationStatusManager.countReceiverStateStarted++;
        } else if ((receiverRunState.equals(RunStateEnum.STOPPING))) {
            showConfigurationStatusManager.countReceiverStateStopping++;
        } else if ((receiverRunState.equals(RunStateEnum.STOPPED))) {
            showConfigurationStatusManager.countReceiverStateStopped++;
        } else if ((receiverRunState.equals(RunStateEnum.ERROR))) {
            showConfigurationStatusManager.countReceiverStateError++;
        }
        if (!showConfigurationStatusAdapterManager.stateAlert && !(receiverRunState.equals(RunStateEnum.STARTED))) {
            showConfigurationStatusAdapterManager.stateAlert = true;
        }
        receiverXML.addAttribute("name", receiver.getName());
        receiverXML.addAttribute("class", ClassUtils.nameOf(receiver));
        receiverXML.addAttribute("messagesReceived", "" + receiver.getMessagesReceived());
        receiverXML.addAttribute("messagesRetried", "" + receiver.getMessagesRetried());
        receiverXML.addAttribute("messagesRejected", "" + receiver.getMessagesRejected());
        if (configurationSelected != null) {
            ISender sender = null;
            if (receiver instanceof ReceiverBase) {
                ReceiverBase rb = (ReceiverBase) receiver;
                IListener listener = rb.getListener();
                receiverXML.addAttribute("listenerClass", ClassUtils.nameOf(listener));
                if (listener instanceof HasPhysicalDestination) {
                    String pd = ((HasPhysicalDestination) rb.getListener()).getPhysicalDestinationName();
                    receiverXML.addAttribute("listenerDestination", pd);
                }
                if (listener instanceof HasSender) {
                    sender = ((HasSender) listener).getSender();
                }
                ITransactionalStorage ts;
                ts = rb.getErrorStorage();
                receiverXML.addAttribute("hasErrorStorage", "" + (ts != null));
                if (ts != null) {
                    try {
                        if (SHOW_COUNT_ERRORSTORE) {
                            receiverXML.addAttribute("errorStorageCount", ts.getMessageCount());
                        } else {
                            receiverXML.addAttribute("errorStorageCount", "?");
                        }
                    } catch (Exception e) {
                        log.warn(e);
                        receiverXML.addAttribute("errorStorageCount", "error");
                    }
                }
                ts = rb.getMessageLog();
                receiverXML.addAttribute("hasMessageLog", "" + (ts != null));
                if (ts != null) {
                    try {
                        if (SHOW_COUNT_MESSAGELOG) {
                            receiverXML.addAttribute("messageLogCount", ts.getMessageCount());
                        } else {
                            receiverXML.addAttribute("messageLogCount", "?");
                        }
                    } catch (Exception e) {
                        log.warn(e);
                        receiverXML.addAttribute("messageLogCount", "error");
                    }
                }
                boolean isRestListener = (listener instanceof RestListener);
                receiverXML.addAttribute("isRestListener", isRestListener);
                if (isRestListener) {
                    RestListener rl = (RestListener) listener;
                    receiverXML.addAttribute("restUriPattern", rl.getRestUriPattern());
                    receiverXML.addAttribute("isView", (rl.isView() == null ? false : rl.isView()));
                    String matchingPattern = RestServiceDispatcher.getInstance().findMatchingPattern("/" + rl.getUriPattern());
                    receiverXML.addAttribute("isAvailable", (matchingPattern == null ? false : true));
                }
                if (showConfigurationStatusManager.count) {
                    if (listener instanceof JmsListenerBase) {
                        JmsListenerBase jlb = (JmsListenerBase) listener;
                        JmsMessageBrowser jmsBrowser;
                        if (StringUtils.isEmpty(jlb.getMessageSelector())) {
                            jmsBrowser = new JmsMessageBrowser();
                        } else {
                            jmsBrowser = new JmsMessageBrowser(jlb.getMessageSelector());
                        }
                        jmsBrowser.setName("MessageBrowser_" + jlb.getName());
                        jmsBrowser.setJmsRealm(jlb.getJmsRealName());
                        jmsBrowser.setDestinationName(jlb.getDestinationName());
                        jmsBrowser.setDestinationType(jlb.getDestinationType());
                        String numMsgs;
                        try {
                            int messageCount = jmsBrowser.getMessageCount();
                            numMsgs = String.valueOf(messageCount);
                        } catch (Throwable t) {
                            log.warn(t);
                            numMsgs = "?";
                        }
                        receiverXML.addAttribute("pendingMessagesCount", numMsgs);
                    }
                }
                boolean isEsbJmsFFListener = false;
                if (listener instanceof EsbJmsListener) {
                    EsbJmsListener ejl = (EsbJmsListener) listener;
                    if ("FF".equalsIgnoreCase(ejl.getMessageProtocol())) {
                        isEsbJmsFFListener = true;
                    }
                    if (showConfigurationStatusManager.count) {
                        String esbNumMsgs = EsbUtils.getQueueMessageCount(ejl);
                        if (esbNumMsgs == null) {
                            esbNumMsgs = "?";
                        }
                        receiverXML.addAttribute("esbPendingMessagesCount", esbNumMsgs);
                    }
                }
                receiverXML.addAttribute("isEsbJmsFFListener", isEsbJmsFFListener);
            }
            if (receiver instanceof HasSender) {
                ISender rsender = ((HasSender) receiver).getSender();
                if (rsender != null) {
                    // this sender has preference, but
                    // avoid overwriting listeners
                    // sender with null
                    sender = rsender;
                }
            }
            if (sender != null) {
                receiverXML.addAttribute("senderName", sender.getName());
                receiverXML.addAttribute("senderClass", ClassUtils.nameOf(sender));
                if (sender instanceof HasPhysicalDestination) {
                    String pd = ((HasPhysicalDestination) sender).getPhysicalDestinationName();
                    receiverXML.addAttribute("senderDestination", pd);
                }
            }
            if (receiver instanceof IThreadCountControllable) {
                IThreadCountControllable tcc = (IThreadCountControllable) receiver;
                if (tcc.isThreadCountReadable()) {
                    receiverXML.addAttribute("threadCount", tcc.getCurrentThreadCount() + "");
                    receiverXML.addAttribute("maxThreadCount", tcc.getMaxThreadCount() + "");
                }
                if (tcc.isThreadCountControllable()) {
                    receiverXML.addAttribute("threadCountControllable", "true");
                }
            }
        }
    }
    return receiversXML;
}
Also used : ReceiverBase(nl.nn.adapterframework.receivers.ReceiverBase) IListener(nl.nn.adapterframework.core.IListener) EsbJmsListener(nl.nn.adapterframework.extensions.esb.EsbJmsListener) HasSender(nl.nn.adapterframework.core.HasSender) PipeRunException(nl.nn.adapterframework.core.PipeRunException) ITransactionalStorage(nl.nn.adapterframework.core.ITransactionalStorage) RestListener(nl.nn.adapterframework.http.RestListener) JmsListenerBase(nl.nn.adapterframework.jms.JmsListenerBase) IReceiver(nl.nn.adapterframework.core.IReceiver) JmsMessageBrowser(nl.nn.adapterframework.jms.JmsMessageBrowser) RunStateEnum(nl.nn.adapterframework.util.RunStateEnum) ISender(nl.nn.adapterframework.core.ISender) IThreadCountControllable(nl.nn.adapterframework.core.IThreadCountControllable) Iterator(java.util.Iterator) XmlBuilder(nl.nn.adapterframework.util.XmlBuilder) HasPhysicalDestination(nl.nn.adapterframework.core.HasPhysicalDestination)

Example 17 with ITransactionalStorage

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

the class ServerStatistics method getServerConfiguration.

@GET
@PermitAll
@Path("/server/warnings")
@Produces(MediaType.APPLICATION_JSON)
public Response getServerConfiguration() throws ApiException {
    initBase(servletConfig);
    ConfigurationWarnings globalConfigWarnings = ConfigurationWarnings.getInstance();
    // (globalConfigWarnings.size() + 1); //Add 1 for ESR
    List<Object> warnings = new ArrayList<Object>();
    boolean showCountErrorStore = AppConstants.getInstance().getBoolean("errorStore.count.show", true);
    List<IAdapter> registeredAdapters = ibisManager.getRegisteredAdapters();
    long esr = 0;
    if (showCountErrorStore) {
        for (Iterator<IAdapter> adapterIt = registeredAdapters.iterator(); adapterIt.hasNext(); ) {
            Adapter adapter = (Adapter) adapterIt.next();
            for (Iterator<?> receiverIt = adapter.getReceiverIterator(); receiverIt.hasNext(); ) {
                ReceiverBase receiver = (ReceiverBase) receiverIt.next();
                ITransactionalStorage errorStorage = receiver.getErrorStorage();
                if (errorStorage != null) {
                    try {
                        esr += errorStorage.getMessageCount();
                    } catch (Exception e) {
                        // error("error occured on getting number of errorlog records for adapter ["+adapter.getName()+"]",e);
                        log.warn("Assuming there are no errorlog records for adapter [" + adapter.getName() + "]");
                    }
                }
            }
        }
    } else {
        esr = -1;
    }
    if (esr != 0) {
        Map<String, Object> messageObj = new HashMap<String, Object>(2);
        String message;
        if (esr == -1) {
            message = "Errorlog might contain records. This is unknown because errorStore.count.show is not set to true";
        } else if (esr == 1) {
            message = "Errorlog contains 1 record. Service management should check whether this record has to be resent or deleted";
        } else {
            message = "Errorlog contains " + esr + " records. Service Management should check whether these records have to be resent or deleted";
        }
        messageObj.put("message", message);
        messageObj.put("type", "severe");
        warnings.add(messageObj);
    }
    for (Configuration config : ibisManager.getConfigurations()) {
        if (config.getConfigurationException() != null) {
            Map<String, Object> messageObj = new HashMap<String, Object>(2);
            String message = config.getConfigurationException().getMessage();
            messageObj.put("message", message);
            messageObj.put("type", "exception");
            warnings.add(messageObj);
        }
    }
    // Configuration specific warnings
    for (Configuration configuration : ibisManager.getConfigurations()) {
        BaseConfigurationWarnings configWarns = configuration.getConfigurationWarnings();
        for (int j = 0; j < configWarns.size(); j++) {
            Map<String, Object> messageObj = new HashMap<String, Object>(1);
            messageObj.put("message", configWarns.get(j));
            messageObj.put("configuration", configuration.getName());
            warnings.add(messageObj);
        }
    }
    // Global warnings
    if (globalConfigWarnings.size() > 0) {
        for (int j = 0; j < globalConfigWarnings.size(); j++) {
            Map<String, Object> messageObj = new HashMap<String, Object>(1);
            messageObj.put("message", globalConfigWarnings.get(j));
            warnings.add(messageObj);
        }
    }
    return Response.status(Response.Status.CREATED).entity(warnings).build();
}
Also used : ReceiverBase(nl.nn.adapterframework.receivers.ReceiverBase) ConfigurationWarnings(nl.nn.adapterframework.configuration.ConfigurationWarnings) BaseConfigurationWarnings(nl.nn.adapterframework.configuration.BaseConfigurationWarnings) Configuration(nl.nn.adapterframework.configuration.Configuration) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) Adapter(nl.nn.adapterframework.core.Adapter) IAdapter(nl.nn.adapterframework.core.IAdapter) ITransactionalStorage(nl.nn.adapterframework.core.ITransactionalStorage) IAdapter(nl.nn.adapterframework.core.IAdapter) BaseConfigurationWarnings(nl.nn.adapterframework.configuration.BaseConfigurationWarnings) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) PermitAll(javax.annotation.security.PermitAll)

Aggregations

ITransactionalStorage (nl.nn.adapterframework.core.ITransactionalStorage)17 ISender (nl.nn.adapterframework.core.ISender)8 IPipe (nl.nn.adapterframework.core.IPipe)7 ReceiverBase (nl.nn.adapterframework.receivers.ReceiverBase)7 HashMap (java.util.HashMap)6 HasPhysicalDestination (nl.nn.adapterframework.core.HasPhysicalDestination)6 IListener (nl.nn.adapterframework.core.IListener)6 LinkedHashMap (java.util.LinkedHashMap)5 IAdapter (nl.nn.adapterframework.core.IAdapter)5 PipeRunException (nl.nn.adapterframework.core.PipeRunException)5 ArrayList (java.util.ArrayList)4 Iterator (java.util.Iterator)4 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)4 Adapter (nl.nn.adapterframework.core.Adapter)4 PipeLine (nl.nn.adapterframework.core.PipeLine)4 SenderException (nl.nn.adapterframework.core.SenderException)4 MessageSendingPipe (nl.nn.adapterframework.pipes.MessageSendingPipe)4 IOException (java.io.IOException)3 Date (java.util.Date)3 Configuration (nl.nn.adapterframework.configuration.Configuration)3