Search in sources :

Example 1 with QueueAdminResponse

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

the class TransactionAdmin method toggleQueueStatus.

/**
 * NOTE: Each graph is expected to contain type. It may also contain the optional queueMetaData.queueSystemId, which may help optimize the process.
 */
public QueueAdminResponse[] toggleQueueStatus(QueueGraph[] graphs) {
    if (log.isDebugEnabled()) {
        log.debug("Input to toggleQueueStatus: " + Arrays.toString(graphs));
    }
    Collection<QueueAdminResponse> output = null;
    String[] types = TransactionEngine.getInstance().getAccessibleTypeNames();
    Arrays.sort(types);
    for (QueueGraph graph : graphs) {
        if (graph.getQueueMetaData() == null || graph.getQueueMetaData().getQueueSystemId() == null || graph.getQueueMetaData().getQueueSystemId().equals(QUEUE_SYSTEM_ID)) {
            if (types != null && Arrays.binarySearch(types, graph.getType()) >= 0) {
                try {
                    if (!TransactionEngine.getInstance().hasAdminAccess(graph.getType())) {
                        throw new ApplicationExceptions(new ApplicationException("error.Jaffa.Transaction.Transaction.noAdminAccess", new Object[] { graph.getType() }));
                    }
                } catch (Exception e) {
                    QueueAdminResponse response = new QueueAdminResponse();
                    response.setSource(graph);
                    ApplicationExceptions appExps = ExceptionHelper.extractApplicationExceptions(e);
                    if (appExps != null) {
                        if (log.isDebugEnabled()) {
                            log.debug("Error while toggling status of queue " + graph.getType(), appExps);
                        }
                        response.setErrors(ServiceError.generate(appExps));
                    } else {
                        log.error("Internal Error while toggling status of queue " + graph.getType(), e);
                        response.setErrors(ServiceError.generate(e));
                    }
                    if (output == null) {
                        output = new LinkedList<QueueAdminResponse>();
                    }
                    output.add(response);
                }
            } else {
                if (log.isDebugEnabled()) {
                    log.debug("Status of queue " + graph.getType() + " will not be toggled by this implementation, since the queue does not belong to this system");
                }
            }
        } else {
            if (log.isDebugEnabled()) {
                log.debug("Status of queue " + graph.getType() + " will not be toggled by this implementation, since the input queueSystemId does not match this system");
            }
        }
    }
    if (log.isDebugEnabled()) {
        log.debug("Output from toggleQueueStatus: " + output);
    }
    return output != null && output.size() > 0 ? output.toArray(new QueueAdminResponse[output.size()]) : null;
}
Also used : ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) ApplicationException(org.jaffa.exceptions.ApplicationException) QueueGraph(org.jaffa.qm.apis.data.QueueGraph) QueueAdminResponse(org.jaffa.qm.apis.data.QueueAdminResponse) 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) LinkedList(java.util.LinkedList)

Example 2 with QueueAdminResponse

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

the class JmsQueueAdmin method toggleQueueStatus.

/**
 * NOTE: Each graph is expected to contain type. It may also contain the optional queueMetaData.queueSystemId, which may help optimize the process.
 */
public QueueAdminResponse[] toggleQueueStatus(QueueGraph[] graphs) {
    if (log.isDebugEnabled())
        log.debug("Input to toggleQueueStatus: " + Arrays.toString(graphs));
    Collection<QueueAdminResponse> output = null;
    String[] queueNames = null;
    for (QueueGraph graph : graphs) {
        if (graph.getQueueMetaData() == null || graph.getQueueMetaData().getQueueSystemId() == null || graph.getQueueMetaData().getQueueSystemId().equals(QUEUE_SYSTEM_ID)) {
            // Initialize and sort the queueNames array; if not already done
            if (queueNames == null) {
                queueNames = ConfigurationService.getInstance().getQueueNames();
                Arrays.sort(queueNames);
            }
            if (Arrays.binarySearch(queueNames, graph.getType()) >= 0) {
                try {
                    if (!JmsBrowser.hasAdminMessageAccess(graph.getType()))
                        throw new JaffaMessagingApplicationException(JaffaMessagingApplicationException.NO_ADMIN_MESSAGE_ACESSS, new Object[] { graph.getType() });
                    if (ConfigurationService.getInstance().getQueueInfo(graph.getType()).getConsumerPolicy() == ConsumerPolicy.NONE) {
                        if (log.isDebugEnabled())
                            log.debug("ConsumerPolicy of queue " + graph.getType() + " is NONE. It's status cannnot be toggled");
                    }
                } catch (Exception e) {
                    QueueAdminResponse response = new QueueAdminResponse();
                    response.setSource(graph);
                    ApplicationExceptions appExps = ExceptionHelper.extractApplicationExceptions(e);
                    if (appExps != null) {
                        if (log.isDebugEnabled())
                            log.debug("Error while toggling status of queue " + graph.getType(), appExps);
                        response.setErrors(ServiceError.generate(appExps));
                    } else {
                        log.error("Internal Error while toggling status of queue " + graph.getType(), e);
                        response.setErrors(ServiceError.generate(e));
                    }
                    if (output == null)
                        output = new LinkedList<QueueAdminResponse>();
                    output.add(response);
                }
            } else {
                if (log.isDebugEnabled())
                    log.debug("Status of queue " + graph.getType() + " will not be toggled by this implementation, since the queue does not belong to this system");
            }
        } else {
            if (log.isDebugEnabled())
                log.debug("Status of queue " + graph.getType() + " will not be toggled by this implementation, since the input queueSystemId does not match this system");
        }
    }
    if (log.isDebugEnabled())
        log.debug("Output from toggleQueueStatus: " + output);
    return output != null && output.size() > 0 ? output.toArray(new QueueAdminResponse[output.size()]) : null;
}
Also used : ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) QueueGraph(org.jaffa.qm.apis.data.QueueGraph) QueueAdminResponse(org.jaffa.qm.apis.data.QueueAdminResponse) JMSException(javax.jms.JMSException) IntrospectionException(java.beans.IntrospectionException)

Example 3 with QueueAdminResponse

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

the class QueueManager method toggleQueueStatus.

public QueueAdminResponse[] toggleQueueStatus(QueueGraph[] graphs) {
    try {
        if (log.isDebugEnabled())
            log.debug("Input to toggleQueueStatus: " + graphs);
        QueueAdminResponse[] aggregateResponse = null;
        IQueueAdmin[] implementations = findImplementations();
        if (implementations != null && implementations.length > 0) {
            for (IQueueAdmin implementation : implementations) {
                QueueAdminResponse[] response = implementation.toggleQueueStatus(graphs);
                if (response != null && response.length > 0)
                    aggregateResponse = concatenate(aggregateResponse, response);
            }
        }
        if (log.isDebugEnabled())
            log.debug("Response from toggleQueueStatus: " + aggregateResponse);
        return aggregateResponse;
    } catch (Exception e) {
        log.error("Error in obtaining IQueueAdmin implementations", e);
        return new QueueAdminResponse[] { new QueueAdminResponse(null, ServiceError.generate(e)) };
    }
}
Also used : QueueAdminResponse(org.jaffa.qm.apis.data.QueueAdminResponse)

Aggregations

QueueAdminResponse (org.jaffa.qm.apis.data.QueueAdminResponse)3 ApplicationExceptions (org.jaffa.exceptions.ApplicationExceptions)2 QueueGraph (org.jaffa.qm.apis.data.QueueGraph)2 IntrospectionException (java.beans.IntrospectionException)1 LinkedList (java.util.LinkedList)1 JMSException (javax.jms.JMSException)1 ApplicationException (org.jaffa.exceptions.ApplicationException)1 FrameworkException (org.jaffa.exceptions.FrameworkException)1 JaffaMessagingFrameworkException (org.jaffa.modules.messaging.services.JaffaMessagingFrameworkException)1 IllegalPersistentStateRuntimeException (org.jaffa.persistence.exceptions.IllegalPersistentStateRuntimeException)1 PostLoadFailedException (org.jaffa.persistence.exceptions.PostLoadFailedException)1 QueryFailedException (org.jaffa.persistence.exceptions.QueryFailedException)1