From: <ga...@us...> - 2011-03-29 23:39:04
|
Revision: 5145 http://jaffa.svn.sourceforge.net/jaffa/?rev=5145&view=rev Author: gautamj Date: 2011-03-29 23:38:57 +0000 (Tue, 29 Mar 2011) Log Message: ----------- Initial implementation of the JMS based QueueAdmin Modified Paths: -------------- trunk/JaffaSOA/build/build.xml trunk/JaffaSOA/source/java/org/jaffa/qm/util/PropertyFilter.java Added Paths: ----------- trunk/JaffaSOA/source/java/org/jaffa/modules/messaging/services/JmsQueueAdmin.java trunk/JaffaSOA/source/java/org/jaffa/qm/apis/dwr.xfragment Modified: trunk/JaffaSOA/build/build.xml =================================================================== --- trunk/JaffaSOA/build/build.xml 2011-03-29 23:35:32 UTC (rev 5144) +++ trunk/JaffaSOA/build/build.xml 2011-03-29 23:38:57 UTC (rev 5145) @@ -132,6 +132,7 @@ <defaultexcludes add="**/org/jaffa/modules/messaging/services/**/*"/> <defaultexcludes add="**/org/jaffa/modules/scheduler/**/*"/> <defaultexcludes add="**/org/jaffa/modules/setup/**/*"/> + <defaultexcludes add="**/org/jaffa/qm/**/*"/> <defaultexcludes add="**/org/jaffa/soa/**/*"/> <defaultexcludes add="**/org/jaffa/transaction/**/*"/> <defaultexcludes add="**/resources/**/*"/> @@ -145,6 +146,7 @@ <defaultexcludes remove="**/org/jaffa/modules/messaging/services/**/*"/> <defaultexcludes remove="**/org/jaffa/modules/scheduler/**/*"/> <defaultexcludes remove="**/org/jaffa/modules/setup/**/*"/> + <defaultexcludes remove="**/org/jaffa/qm/**/*"/> <defaultexcludes remove="**/org/jaffa/soa/**/*"/> <defaultexcludes remove="**/org/jaffa/transaction/**/*"/> <defaultexcludes remove="**/resources/**/*"/> @@ -164,6 +166,7 @@ <defaultexcludes add="**/org/jaffa/modules/messaging/services/**/*"/> <defaultexcludes add="**/org/jaffa/modules/scheduler/**/*"/> <defaultexcludes add="**/org/jaffa/modules/setup/**/*"/> + <defaultexcludes add="**/org/jaffa/qm/**/*"/> <defaultexcludes add="**/org/jaffa/soa/**/*"/> <defaultexcludes add="**/org/jaffa/transaction/**/*"/> <defaultexcludes add="**/resources/**/*"/> @@ -177,6 +180,7 @@ <defaultexcludes remove="**/org/jaffa/modules/messaging/services/**/*"/> <defaultexcludes remove="**/org/jaffa/modules/scheduler/**/*"/> <defaultexcludes remove="**/org/jaffa/modules/setup/**/*"/> + <defaultexcludes remove="**/org/jaffa/qm/**/*"/> <defaultexcludes remove="**/org/jaffa/soa/**/*"/> <defaultexcludes remove="**/org/jaffa/transaction/**/*"/> <defaultexcludes remove="**/resources/**/*"/> Added: trunk/JaffaSOA/source/java/org/jaffa/modules/messaging/services/JmsQueueAdmin.java =================================================================== --- trunk/JaffaSOA/source/java/org/jaffa/modules/messaging/services/JmsQueueAdmin.java (rev 0) +++ trunk/JaffaSOA/source/java/org/jaffa/modules/messaging/services/JmsQueueAdmin.java 2011-03-29 23:38:57 UTC (rev 5145) @@ -0,0 +1,238 @@ +/* + * ==================================================================== + * JAFFA - Java Application Framework For All + * + * Copyright (C) 2002 JAFFA Development Group + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Redistribution and use of this software and associated documentation ("Software"), + * with or without modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain copyright statements and notices. + * Redistributions must also contain a copy of this document. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name "JAFFA" must not be used to endorse or promote products derived from + * this Software without prior written permission. For written permission, + * please contact mail to: jaf...@ya.... + * 4. Products derived from this Software may not be called "JAFFA" nor may "JAFFA" + * appear in their names without prior written permission. + * 5. Due credit should be given to the JAFFA Project (http://jaffa.sourceforge.net). + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + */ +package org.jaffa.modules.messaging.services; + +import java.util.Collection; +import java.util.LinkedList; +import javax.jms.Message; +import org.apache.log4j.Logger; +import org.jaffa.components.finder.FinderTx; +import org.jaffa.exceptions.ApplicationExceptions; +import org.jaffa.modules.messaging.services.configdomain.ConsumerPolicy; +import org.jaffa.modules.messaging.services.configdomain.DisplayParam; +import org.jaffa.modules.messaging.services.configdomain.QueueInfo; +import org.jaffa.qm.apis.IQueueAdmin; +import org.jaffa.qm.apis.data.MessageAdminResponse; +import org.jaffa.qm.apis.data.MessageCriteria; +import org.jaffa.qm.apis.data.MessageFieldMetaData; +import org.jaffa.qm.apis.data.MessageGraph; +import org.jaffa.qm.apis.data.MessageQueryResponse; +import org.jaffa.qm.apis.data.QueueAdminResponse; +import org.jaffa.qm.apis.data.QueueCriteria; +import org.jaffa.qm.apis.data.QueueGraph; +import org.jaffa.qm.apis.data.QueueMetaData; +import org.jaffa.qm.apis.data.QueueQueryResponse; +import org.jaffa.qm.util.PropertyFilter; +import org.jaffa.soa.graph.ServiceError; +import org.jaffa.util.ExceptionHelper; + +/** + * This IQueueAdmin implementation is based on the JMS Queues. + * @author GautamJ + */ +public class JmsQueueAdmin implements IQueueAdmin { + + private static final Logger log = Logger.getLogger(JmsQueueAdmin.class); + public static final String QUEUE_SYSTEM_ID = "JMS"; + + public QueueQueryResponse queueQuery(QueueCriteria criteria) { + if (log.isDebugEnabled()) + log.debug("Input to queueQuery: " + criteria); + QueueQueryResponse output = new QueueQueryResponse(); + + try { + PropertyFilter pf = PropertyFilter.getInstance(QueueGraph.class, criteria.getResultGraphRules()); + if (FinderTx.match(QUEUE_SYSTEM_ID, criteria.getQueueSystemId())) { + String[] queueNames = JmsBrowser.getAccessibleQueueNames(); + if (queueNames != null && queueNames.length > 0) { + 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); + } + if (!FinderTx.match(null, criteria.getSuccessCount())) + continue; + if (criteria.getErrorCount() != null || pf.isFieldIncluded("errorCount")) { + Message[] messages = JmsBrowser.getErrorMessages(queueName); + Long count = messages != null ? messages.length : 0L; + if (!FinderTx.match(count, criteria.getErrorCount())) + continue; + if (pf.isFieldIncluded("errorCount")) + graph.setErrorCount(count); + } + if (!FinderTx.match(null, criteria.getHoldCount())) + continue; + if (criteria.getInProcessCount() != null || pf.isFieldIncluded("inProcessCount")) { + Message[] messages = JmsBrowser.getInProcessMessages(queueName); + Long count = messages != null ? messages.length : 0L; + if (!FinderTx.match(count, criteria.getInProcessCount())) + continue; + if (pf.isFieldIncluded("inProcessCount")) + graph.setInProcessCount(count); + } + if (!FinderTx.match(null, criteria.getInterruptedCount())) + continue; + + //Apply the consumerCount and status criteria + if (criteria.getConsumerCount() != null || pf.isFieldIncluded("consumerCount") || criteria.getStatus() != null || pf.isFieldIncluded("status")) { + Long consumerCount = new Long(JmsBrowser.getActiveConsumersCount(queueName)); + QueueGraph.Status status; + QueueInfo queueInfo = ConfigurationService.getInstance().getQueueInfo(queueName); + if (queueInfo != null && queueInfo.getConsumerPolicy() != ConsumerPolicy.NONE) + status = consumerCount > 0 ? QueueGraph.Status.ACTIVE : QueueGraph.Status.INACTIVE; + else + status = QueueGraph.Status.ACTIVE; + if (!FinderTx.match(consumerCount, criteria.getConsumerCount())) + continue; + if (pf.isFieldIncluded("consumerCount")) + graph.setConsumerCount(consumerCount); + 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; + } + + public MessageQueryResponse messageQuery(MessageCriteria criteria) { + //@todo + return null; + } + + public QueueAdminResponse[] toggleQueueStatus(QueueGraph[] graphs) { + //@todo + return null; + } + + public MessageAdminResponse[] deleteMessage(MessageGraph[] graphs) { + //@todo + return null; + } + + public MessageAdminResponse[] resubmitMessage(MessageGraph[] graphs) { + //@todo + return null; + } + + private static QueueMetaData createQueueMetaData(String queueName, PropertyFilter pf) { + QueueMetaData qmd = null; + if (pf.isFieldIncluded("queueMetaData")) { + qmd = new QueueMetaData(); + if (pf.isFieldIncluded("queueMetaData.queueSystemId")) + qmd.setQueueSystemId(QUEUE_SYSTEM_ID); + if (pf.isFieldIncluded("queueMetaData.type")) + qmd.setType(queueName); + if (pf.isFieldIncluded("queueMetaData.supportedMessageStatus")) + qmd.setSupportedMessageStatus(new MessageGraph.Status[]{MessageGraph.Status.OPEN, MessageGraph.Status.ERROR, MessageGraph.Status.IN_PROCESS}); + + if (pf.isFieldIncluded("queueMetaData.supportedApplicationFields")) { + QueueInfo queueInfo = ConfigurationService.getInstance().getQueueInfo(queueName); + if (queueInfo != null && queueInfo.getDisplayParam() != null) { + Collection<MessageFieldMetaData> supportedApplicationFields = new LinkedList<MessageFieldMetaData>(); + for (DisplayParam displayParam : queueInfo.getDisplayParam()) { + MessageFieldMetaData supportedApplicationField = new MessageFieldMetaData(); + if (pf.isFieldIncluded("queueMetaData.supportedApplicationFields.name")) + supportedApplicationField.setName(displayParam.getName()); + if (pf.isFieldIncluded("queueMetaData.supportedApplicationFields.label")) + supportedApplicationField.setLabel(displayParam.getLabel()); + supportedApplicationFields.add(supportedApplicationField); + } + qmd.setSupportedApplicationFields(supportedApplicationFields.toArray(new MessageFieldMetaData[supportedApplicationFields.size()])); + } + } + + if (pf.isFieldIncluded("queueMetaData.supportsTechnicalFields")) + qmd.setSupportsTechnicalFields(Boolean.TRUE); + if (pf.isFieldIncluded("queueMetaData.supportsBusinessEventLogs")) + qmd.setSupportsBusinessEventLogs(Boolean.TRUE); + if (pf.isFieldIncluded("queueMetaData.supportsDependencies")) + qmd.setSupportsDependencies(Boolean.FALSE); + } + return qmd; + } +} Property changes on: trunk/JaffaSOA/source/java/org/jaffa/modules/messaging/services/JmsQueueAdmin.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Added: trunk/JaffaSOA/source/java/org/jaffa/qm/apis/dwr.xfragment =================================================================== --- trunk/JaffaSOA/source/java/org/jaffa/qm/apis/dwr.xfragment (rev 0) +++ trunk/JaffaSOA/source/java/org/jaffa/qm/apis/dwr.xfragment 2011-03-29 23:38:57 UTC (rev 5145) @@ -0,0 +1,12 @@ + <!-- Jaffa_QM_QueueManager --> + <create creator="new" javascript="Jaffa_QM_QueueManager"> + <param name="class" value="org.jaffa.qm.apis.QueueManager"/> + <include method="queueQuery"/> + <include method="messageQuery"/> + <include method="toggleQueueStatus"/> + <include method="deleteMessage"/> + <include method="resubmitMessage"/> + </create> + <convert converter="nnBean" match="org.jaffa.qm.apis.data.*" /> + <convert converter="enum" match="org.jaffa.qm.apis.data.MessageGraph$Status" /> + <convert converter="enum" match="org.jaffa.qm.apis.data.QueueGraph$Status" /> Property changes on: trunk/JaffaSOA/source/java/org/jaffa/qm/apis/dwr.xfragment ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Modified: trunk/JaffaSOA/source/java/org/jaffa/qm/util/PropertyFilter.java =================================================================== --- trunk/JaffaSOA/source/java/org/jaffa/qm/util/PropertyFilter.java 2011-03-29 23:35:32 UTC (rev 5144) +++ trunk/JaffaSOA/source/java/org/jaffa/qm/util/PropertyFilter.java 2011-03-29 23:38:57 UTC (rev 5145) @@ -234,7 +234,7 @@ Class type = pd.getPropertyType(); if (type.isArray()) type = type.getComponentType(); - if (type == String.class || type == Boolean.class || Number.class.isAssignableFrom(type) || IDateBase.class.isAssignableFrom(type) || Currency.class.isAssignableFrom(type) || type.isPrimitive()) + if (type == String.class || type == Boolean.class || Number.class.isAssignableFrom(type) || IDateBase.class.isAssignableFrom(type) || Currency.class.isAssignableFrom(type) || type.isPrimitive() || type.isEnum()) fieldList.add(qualifieldName); else getFieldList(type, fieldList, qualifieldName, classStack); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |