Search in sources :

Example 1 with QueueQueryResponse

use of org.jaffa.qm.apis.data.QueueQueryResponse in project jaffa-framework by jaffa-projects.

the class JmsQueueAdmin method queueQuery.

public QueueQueryResponse queueQuery(QueueCriteria criteria) {
    if (log.isDebugEnabled())
        log.debug("Input to queueQuery: " + criteria);
    QueueQueryResponse output = new QueueQueryResponse();
    try {
        // Match the queueSystemId as well apply checks for unsupported criteria
        if (FinderTx.match(QUEUE_SYSTEM_ID, criteria.getQueueSystemId()) && FinderTx.match(null, criteria.getSuccessCount()) && FinderTx.match(null, criteria.getHoldCount()) && FinderTx.match(null, criteria.getInterruptedCount())) {
            String[] queueNames = JmsBrowser.getAccessibleQueueNames();
            if (queueNames != null && queueNames.length > 0) {
                PropertyFilter pf = PropertyFilter.getInstance(QueueGraph.class, criteria.getResultGraphRules());
                Collection<QueueGraph> graphs = new LinkedList<QueueGraph>();
                for (String queueName : queueNames) {
                    if (FinderTx.match(queueName, criteria.getType())) {
                        QueueGraph graph = new QueueGraph();
                        // Compute message count only if required by criteria or if it is included in the property-filter
                        if (criteria.getOpenCount() != null || pf.isFieldIncluded("openCount")) {
                            Message[] messages = JmsBrowser.getPendingMessages(queueName);
                            Long count = messages != null ? messages.length : 0L;
                            if (!FinderTx.match(count, criteria.getOpenCount()))
                                continue;
                            if (pf.isFieldIncluded("openCount"))
                                graph.setOpenCount(count);
                        }
                        // Apply the status criteria
                        if (criteria.getStatus() != null || pf.isFieldIncluded("status")) {
                            QueueGraph.Status status;
                            QueueInfo queueInfo = ConfigurationService.getInstance().getQueueInfo(queueName);
                            if (queueInfo != null && queueInfo.getConsumerPolicy() != ConsumerPolicy.NONE)
                                status = QueueGraph.Status.ACTIVE;
                            else
                                status = QueueGraph.Status.ACTIVE;
                            if (!FinderTx.match(status.toString(), criteria.getStatus()))
                                continue;
                            if (pf.isFieldIncluded("status"))
                                graph.setStatus(status);
                        }
                        // Stamp the remaining properties, if included in the property-filter
                        graph.setQueueMetaData(createQueueMetaData(queueName, pf));
                        if (pf.isFieldIncluded("type"))
                            graph.setType(queueName);
                        if (pf.isFieldIncluded("hasAdminAccess"))
                            graph.setHasAdminAccess(JmsBrowser.hasAdminMessageAccess(queueName));
                        graphs.add(graph);
                    }
                }
                if (graphs.size() > 0)
                    output.setGraphs(graphs.toArray(new QueueGraph[graphs.size()]));
            }
        }
    } catch (Exception e) {
        // add errors to the response
        ApplicationExceptions appExps = ExceptionHelper.extractApplicationExceptions(e);
        if (appExps != null) {
            if (log.isDebugEnabled())
                log.debug("Error in queueQuery execution", appExps);
            output.setErrors(ServiceError.generate(appExps));
        } else {
            log.error("Internal Error in queueQuery execution", e);
            output.setErrors(ServiceError.generate(e));
        }
    }
    if (log.isDebugEnabled())
        log.debug("Output from queueQuery: " + output);
    return output;
}
Also used : QueueInfo(org.jaffa.modules.messaging.services.configdomain.QueueInfo) ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) QueueQueryResponse(org.jaffa.qm.apis.data.QueueQueryResponse) LinkedList(java.util.LinkedList) JMSException(javax.jms.JMSException) IntrospectionException(java.beans.IntrospectionException) QueueGraph(org.jaffa.qm.apis.data.QueueGraph) PropertyFilter(org.jaffa.qm.util.PropertyFilter)

Example 2 with QueueQueryResponse

use of org.jaffa.qm.apis.data.QueueQueryResponse in project jaffa-framework by jaffa-projects.

the class QueueManager method queueQuery.

// TODO-SWAT add script events here
public QueueQueryResponse queueQuery(QueueCriteria criteria) {
    try {
        if (log.isDebugEnabled())
            log.debug("Input to queueQuery: " + criteria);
        QueueQueryResponse aggregateResponse = new QueueQueryResponse();
        IQueueAdmin[] implementations = findImplementations();
        if (implementations != null && implementations.length > 0) {
            for (IQueueAdmin implementation : implementations) {
                QueueQueryResponse response = implementation.queueQuery(criteria);
                if (response != null && response.getErrors() != null && response.getErrors().length > 0) {
                    aggregateResponse.setErrors(response.getErrors());
                    break;
                } else if (response != null && response.getGraphs() != null && response.getGraphs().length > 0) {
                    aggregateResponse.setGraphs(concatenate(aggregateResponse.getGraphs(), response.getGraphs()));
                }
            }
            if (aggregateResponse.getErrors() == null && aggregateResponse.getGraphs() != null && aggregateResponse.getGraphs().length > 0 && criteria.getOrderByFields() != null && criteria.getOrderByFields().length > 0)
                Arrays.sort(aggregateResponse.getGraphs(), new GraphComparator(criteria.getOrderByFields()));
            handlePaging(aggregateResponse, criteria);
        }
        if (aggregateResponse.getGraphs() == null)
            aggregateResponse.setGraphs(new QueueGraph[0]);
        if (log.isDebugEnabled())
            log.debug("Response from queueQuery: " + aggregateResponse);
        return aggregateResponse;
    } catch (Exception e) {
        log.error("Error in obtaining IQueueAdmin implementations", e);
        return new QueueQueryResponse(null, ServiceError.generate(e));
    }
}
Also used : QueueQueryResponse(org.jaffa.qm.apis.data.QueueQueryResponse) QueueGraph(org.jaffa.qm.apis.data.QueueGraph) GraphComparator(org.jaffa.soa.graph.GraphComparator)

Example 3 with QueueQueryResponse

use of org.jaffa.qm.apis.data.QueueQueryResponse in project jaffa-framework by jaffa-projects.

the class QueueManager method messageQuery.

public MessageQueryResponse messageQuery(MessageCriteria criteria) throws ApplicationExceptions {
    try {
        if (log.isDebugEnabled())
            log.debug("Input to messageQuery: " + criteria);
        MessageQueryResponse aggregateResponse = new MessageQueryResponse();
        IQueueAdmin[] implementations = findImplementations();
        // Find which implementation of queue admin can be used to query messages for supplied queue
        IQueueAdmin queryImplementation = null;
        boolean foundMultiple = false;
        if (implementations != null && implementations.length > 0) {
            for (IQueueAdmin implementation : implementations) {
                QueueCriteria queueCriteria = new QueueCriteria();
                queueCriteria.setType(criteria.getType());
                queueCriteria.setQueueSystemId(criteria.getQueueSystemId());
                QueueQueryResponse queueResponse = implementation.queueQuery(queueCriteria);
                if (queueResponse != null && queueResponse.getGraphs() != null && queueResponse.getGraphs().length == 1) {
                    if (queryImplementation != null)
                        foundMultiple = true;
                    queryImplementation = implementation;
                } else if (queueResponse.getGraphs() != null && queueResponse.getGraphs().length > 1) {
                    foundMultiple = true;
                }
            }
        }
        if (foundMultiple) {
            log.error("Found multiple IQueueAdmin implementations for message query");
            throw new ApplicationExceptions(new QueueAdminException(QueueAdminException.MULTIPLE_QUEUES));
        }
        // Use correct queue admin to retrieve messages. Admin class should perform sorting and paging.
        if (queryImplementation != null) {
            MessageQueryResponse response = queryImplementation.messageQuery(criteria);
            if (response != null && response.getErrors() != null && response.getErrors().length > 0) {
                aggregateResponse.setErrors(response.getErrors());
            } else if (response != null && response.getGraphs() != null && response.getGraphs().length > 0) {
                aggregateResponse.setGraphs(concatenate(aggregateResponse.getGraphs(), response.getGraphs()));
            }
            if (response.getTotalRecords() != null && response.getTotalRecords() > 0)
                aggregateResponse.setTotalRecords(response.getTotalRecords());
        }
        if (aggregateResponse.getGraphs() == null)
            aggregateResponse.setGraphs(new MessageGraph[0]);
        if (log.isDebugEnabled())
            log.debug("Response from messageQuery: " + aggregateResponse);
        return aggregateResponse;
    } catch (Exception e) {
        log.error("Error in obtaining IQueueAdmin implementations", e);
        return new MessageQueryResponse(null, ServiceError.generate(e));
    }
}
Also used : ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) QueueCriteria(org.jaffa.qm.apis.data.QueueCriteria) QueueQueryResponse(org.jaffa.qm.apis.data.QueueQueryResponse) MessageGraph(org.jaffa.qm.apis.data.MessageGraph) MessageQueryResponse(org.jaffa.qm.apis.data.MessageQueryResponse)

Example 4 with QueueQueryResponse

use of org.jaffa.qm.apis.data.QueueQueryResponse in project jaffa-framework by jaffa-projects.

the class TransactionAdmin method queueQuery.

public QueueQueryResponse queueQuery(QueueCriteria criteria) {
    if (log.isDebugEnabled()) {
        log.debug("Input to queueQuery: " + criteria);
    }
    QueueQueryResponse output = new QueueQueryResponse();
    try {
        // Match the queueSystemId
        if (FinderTx.match(QUEUE_SYSTEM_ID, criteria.getQueueSystemId())) {
            String[] types = TransactionEngine.getInstance().getAccessibleTypeNames();
            if (types != null && types.length > 0) {
                PropertyFilter pf = PropertyFilter.getInstance(QueueGraph.class, criteria.getResultGraphRules());
                Collection<QueueGraph> graphs = new LinkedList<QueueGraph>();
                Map<String, TransactionStatusCount> statusCountMap = transactionDAO.getTransactionCountPerStatusForTypes(types);
                for (String type : types) {
                    if (FinderTx.match(type, criteria.getType())) {
                        QueueGraph graph = new QueueGraph();
                        TransactionStatusCount statusCount = statusCountMap.get(type);
                        // Compute message count only if required by criteria or if it is included in the property-filter
                        if ((statusCount != null) && (criteria.getOpenCount() != null || pf.isFieldIncluded("openCount") || criteria.getSuccessCount() != null || pf.isFieldIncluded("successCount") || criteria.getErrorCount() != null || pf.isFieldIncluded("errorCount") || criteria.getHoldCount() != null || pf.isFieldIncluded("holdCount") || criteria.getInProcessCount() != null || pf.isFieldIncluded("inProcessCount") || criteria.getInterruptedCount() != null || pf.isFieldIncluded("interruptedCount") || pf.isFieldIncluded("lastErroredOn"))) {
                            Long openCount = statusCount.getOpenCount();
                            Long successCount = statusCount.getSuccessCount();
                            Long errorCount = statusCount.getErrorCount();
                            Long holdCount = statusCount.getHoldCount();
                            Long inProcessCount = statusCount.getInProcessCount();
                            Long interruptedCount = statusCount.getInterruptedCount();
                            if (pf.isFieldIncluded("lastErroredOn") && statusCount.getTotalCount() > 0L) {
                                graph.setLastErroredOn(transactionDAO.getLastErrorTimeByType(type));
                            }
                            if (!FinderTx.match(openCount, criteria.getOpenCount())) {
                                continue;
                            }
                            if (pf.isFieldIncluded("openCount")) {
                                graph.setOpenCount(openCount);
                            }
                            if (!FinderTx.match(successCount, criteria.getSuccessCount())) {
                                continue;
                            }
                            if (pf.isFieldIncluded("successCount")) {
                                graph.setSuccessCount(successCount);
                            }
                            if (!FinderTx.match(errorCount, criteria.getErrorCount())) {
                                continue;
                            }
                            if (pf.isFieldIncluded("errorCount")) {
                                graph.setErrorCount(errorCount);
                            }
                            if (!FinderTx.match(holdCount, criteria.getHoldCount())) {
                                continue;
                            }
                            if (pf.isFieldIncluded("holdCount")) {
                                graph.setHoldCount(holdCount);
                            }
                            if (!FinderTx.match(inProcessCount, criteria.getInProcessCount())) {
                                continue;
                            }
                            if (pf.isFieldIncluded("inProcessCount")) {
                                graph.setInProcessCount(inProcessCount);
                            }
                            if (!FinderTx.match(interruptedCount, criteria.getInterruptedCount())) {
                                continue;
                            }
                            if (pf.isFieldIncluded("interruptedCount")) {
                                graph.setInterruptedCount(interruptedCount);
                            }
                        }
                        // Apply the status criteria
                        if (criteria.getStatus() != null || pf.isFieldIncluded("status")) {
                            QueueGraph.Status status = QueueGraph.Status.ACTIVE;
                            if (!FinderTx.match(status.toString(), criteria.getStatus())) {
                                continue;
                            }
                            if (pf.isFieldIncluded("status")) {
                                graph.setStatus(status);
                            }
                        }
                        // Stamp the remaining properties, if included in the property-filter
                        graph.setQueueMetaData(createQueueMetaData(type, pf));
                        if (pf.isFieldIncluded("type")) {
                            graph.setType(type);
                        }
                        if (pf.isFieldIncluded("hasAdminAccess")) {
                            graph.setHasAdminAccess(TransactionEngine.getInstance().hasAdminAccess(type));
                        }
                        graphs.add(graph);
                    }
                }
                if (graphs.size() > 0) {
                    output.setGraphs(graphs.toArray(new QueueGraph[graphs.size()]));
                }
            }
        }
    } catch (Exception e) {
        // add errors to the response
        ApplicationExceptions appExps = ExceptionHelper.extractApplicationExceptions(e);
        if (appExps != null) {
            if (log.isDebugEnabled()) {
                log.debug("Error in queueQuery execution", appExps);
            }
            output.setErrors(ServiceError.generate(appExps));
        } else {
            log.error("Internal Error in queueQuery execution", e);
            output.setErrors(ServiceError.generate(e));
        }
    }
    if (log.isDebugEnabled()) {
        log.debug("Output from queueQuery: " + output);
    }
    return output;
}
Also used : TransactionStatusCount(org.jaffa.transaction.domain.TransactionStatusCount) ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) QueueQueryResponse(org.jaffa.qm.apis.data.QueueQueryResponse) LinkedList(java.util.LinkedList) IllegalPersistentStateRuntimeException(org.jaffa.persistence.exceptions.IllegalPersistentStateRuntimeException) JaffaMessagingFrameworkException(org.jaffa.modules.messaging.services.JaffaMessagingFrameworkException) PostLoadFailedException(org.jaffa.persistence.exceptions.PostLoadFailedException) FrameworkException(org.jaffa.exceptions.FrameworkException) QueryFailedException(org.jaffa.persistence.exceptions.QueryFailedException) ApplicationException(org.jaffa.exceptions.ApplicationException) QueueGraph(org.jaffa.qm.apis.data.QueueGraph) PropertyFilter(org.jaffa.qm.util.PropertyFilter)

Aggregations

QueueQueryResponse (org.jaffa.qm.apis.data.QueueQueryResponse)4 ApplicationExceptions (org.jaffa.exceptions.ApplicationExceptions)3 QueueGraph (org.jaffa.qm.apis.data.QueueGraph)3 LinkedList (java.util.LinkedList)2 PropertyFilter (org.jaffa.qm.util.PropertyFilter)2 IntrospectionException (java.beans.IntrospectionException)1 JMSException (javax.jms.JMSException)1 Message (javax.jms.Message)1 TextMessage (javax.jms.TextMessage)1 ApplicationException (org.jaffa.exceptions.ApplicationException)1 FrameworkException (org.jaffa.exceptions.FrameworkException)1 JaffaMessagingFrameworkException (org.jaffa.modules.messaging.services.JaffaMessagingFrameworkException)1 QueueInfo (org.jaffa.modules.messaging.services.configdomain.QueueInfo)1 IllegalPersistentStateRuntimeException (org.jaffa.persistence.exceptions.IllegalPersistentStateRuntimeException)1 PostLoadFailedException (org.jaffa.persistence.exceptions.PostLoadFailedException)1 QueryFailedException (org.jaffa.persistence.exceptions.QueryFailedException)1 MessageGraph (org.jaffa.qm.apis.data.MessageGraph)1 MessageQueryResponse (org.jaffa.qm.apis.data.MessageQueryResponse)1 QueueCriteria (org.jaffa.qm.apis.data.QueueCriteria)1 GraphComparator (org.jaffa.soa.graph.GraphComparator)1