use of org.jaffa.modules.messaging.services.configdomain.QueueInfo 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;
}
use of org.jaffa.modules.messaging.services.configdomain.QueueInfo in project jaffa-framework by jaffa-projects.
the class JmsBrowser method getPendingMessages.
/**
* Returns the unconsumed messages in the input queue.
*
* @param queueName the queue name.
* @param filter used for searching within the header information of the retrieved messages. The syntax for the filter will be based on a subset of the SQL92 conditional expression syntax.
* @return the unconsumed messages in the input queue.
* @throws FrameworkException in case any internal error occurs.
* @throws ApplicationExceptions Indicates application error(s).
*/
public static Message[] getPendingMessages(String queueName, String filter) throws FrameworkException, ApplicationExceptions {
Session session = null;
try {
List<Message> messages = new LinkedList<Message>();
QueueInfo queueInfo = ConfigurationService.getInstance().getQueueInfo(queueName);
if (hasBrowseQueueAccess(queueInfo)) {
// Obtain a Connection with the JMS provider
Connection connection = JaffaConnectionFactory.obtainConnection();
// Creates a Session from the Connection
session = JmsClientHelper.obtainSession(connection, false);
// Creates a QueueBrowser from the Session, using the filter, if supplied
QueueBrowser qb = session.createBrowser(JmsClientHelper.obtainQueue(queueName), filter);
if (log.isDebugEnabled())
log.debug("QueueBrowser created for " + queueName + " with filter " + filter);
// Check if the user can access all messages in the queue
boolean browseAllMessagesAccess = hasBrowseAllMessagesAccess(queueInfo);
if (log.isDebugEnabled())
log.debug("browseAllMessages access to " + queueName + " is " + browseAllMessagesAccess);
for (Enumeration e = qb.getEnumeration(); e.hasMoreElements(); ) {
Message message = (Message) e.nextElement();
// If this is an error queue, perform the check against the original queue
if (queueInfo.isErrorQueue() && message.getStringProperty(HEADER_ORIGINAL_QUEUE_NAME) != null) {
String originalQueueName = message.getStringProperty(HEADER_ORIGINAL_QUEUE_NAME);
if (hasBrowseAllMessagesAccess(originalQueueName) || isMessageOwner(message))
messages.add(message);
} else if (browseAllMessagesAccess || isMessageOwner(message)) {
messages.add(message);
}
}
// Close the QueueBrowser
qb.close();
} else {
if (log.isDebugEnabled())
log.debug("No browseQueue access to " + queueName);
}
// Returns an array of Messages from the QueueBrowser's enumeration
Message[] output = messages.toArray(new Message[messages.size()]);
if (log.isDebugEnabled()) {
StringBuilder buf = new StringBuilder("<output>");
for (Message m : output) buf.append("<message>").append(m).append("</message>");
buf.append("</output>");
log.debug(output.length + " messages are being returned: " + buf.toString());
}
return output;
} catch (InvalidSelectorException e) {
if (log.isDebugEnabled())
log.debug("Invalid filter: \"" + filter + '"', e);
throw new ApplicationExceptions(new JaffaMessagingApplicationException(JaffaMessagingApplicationException.INVALID_SELECTOR));
} catch (JMSException e) {
log.error("Error in reading JMS Messages", e);
throw new JaffaMessagingFrameworkException(JaffaMessagingFrameworkException.BROWSE_ERROR, new Object[] { queueName }, e);
} finally {
if (session != null) {
try {
session.close();
} catch (JMSException e) {
log.warn("Error in closing a JMS Session", e);
}
}
}
}
Aggregations