qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgodf...@apache.org
Subject svn commit: r1332796 - in /qpid/branches/java-config-and-management/qpid/java/broker-plugins/management: ./ src/main/java/org/apache/qpid/server/management/plugin/ src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/ src/main/java/resou...
Date Tue, 01 May 2012 19:50:29 GMT
Author: rgodfrey
Date: Tue May  1 19:50:29 2012
New Revision: 1332796

URL: http://svn.apache.org/viewvc?rev=1332796&view=rev
Log:
NO-JIRA : [Java Config] add initial message support

Added:
    qpid/branches/java-config-and-management/qpid/java/broker-plugins/management/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/MessageServlet.java
Modified:
    qpid/branches/java-config-and-management/qpid/java/broker-plugins/management/MANIFEST.MF
    qpid/branches/java-config-and-management/qpid/java/broker-plugins/management/src/main/java/org/apache/qpid/server/management/plugin/Management.java
    qpid/branches/java-config-and-management/qpid/java/broker-plugins/management/src/main/java/resources/css/queue.css
    qpid/branches/java-config-and-management/qpid/java/broker-plugins/management/src/main/java/resources/js/queue.js
    qpid/branches/java-config-and-management/qpid/java/broker-plugins/management/src/main/java/resources/queue.html

Modified: qpid/branches/java-config-and-management/qpid/java/broker-plugins/management/MANIFEST.MF
URL: http://svn.apache.org/viewvc/qpid/branches/java-config-and-management/qpid/java/broker-plugins/management/MANIFEST.MF?rev=1332796&r1=1332795&r2=1332796&view=diff
==============================================================================
--- qpid/branches/java-config-and-management/qpid/java/broker-plugins/management/MANIFEST.MF
(original)
+++ qpid/branches/java-config-and-management/qpid/java/broker-plugins/management/MANIFEST.MF
Tue May  1 19:50:29 2012
@@ -21,6 +21,7 @@ Import-Package:  org.apache.qpid,
  org.apache.qpid.server.binding,
  org.apache.qpid.server.exchange,
  org.apache.qpid.server.logging,
+ org.apache.qpid.server.message,
  org.apache.qpid.server.model,
  org.apache.qpid.server.model.adapter,
  org.apache.qpid.server.model.impl,

Modified: qpid/branches/java-config-and-management/qpid/java/broker-plugins/management/src/main/java/org/apache/qpid/server/management/plugin/Management.java
URL: http://svn.apache.org/viewvc/qpid/branches/java-config-and-management/qpid/java/broker-plugins/management/src/main/java/org/apache/qpid/server/management/plugin/Management.java?rev=1332796&r1=1332795&r2=1332796&view=diff
==============================================================================
--- qpid/branches/java-config-and-management/qpid/java/broker-plugins/management/src/main/java/org/apache/qpid/server/management/plugin/Management.java
(original)
+++ qpid/branches/java-config-and-management/qpid/java/broker-plugins/management/src/main/java/org/apache/qpid/server/management/plugin/Management.java
Tue May  1 19:50:29 2012
@@ -27,10 +27,7 @@ import org.apache.qpid.server.management
 import org.apache.qpid.server.management.plugin.servlet.FileServlet;
 import org.apache.qpid.server.management.plugin.servlet.api.ExchangesServlet;
 import org.apache.qpid.server.management.plugin.servlet.api.VhostsServlet;
-import org.apache.qpid.server.management.plugin.servlet.rest.LogRecordsServlet;
-import org.apache.qpid.server.management.plugin.servlet.rest.RestServlet;
-import org.apache.qpid.server.management.plugin.servlet.rest.SaslServlet;
-import org.apache.qpid.server.management.plugin.servlet.rest.StructureServlet;
+import org.apache.qpid.server.management.plugin.servlet.rest.*;
 import org.apache.qpid.server.model.Binding;
 import org.apache.qpid.server.model.Broker;
 import org.apache.qpid.server.model.ConfiguredObject;
@@ -98,6 +95,7 @@ public class Management
         addRestServlet(root, "session", VirtualHost.class, Connection.class, Session.class);
 
         root.addServlet(new ServletHolder(new StructureServlet(_broker)), "/rest/structure");
+        root.addServlet(new ServletHolder(new MessageServlet(_broker)), "/rest/message/*");
 
         root.addServlet(new ServletHolder(new LogRecordsServlet(_broker)), "/rest/logrecords");
 

Added: qpid/branches/java-config-and-management/qpid/java/broker-plugins/management/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/MessageServlet.java
URL: http://svn.apache.org/viewvc/qpid/branches/java-config-and-management/qpid/java/broker-plugins/management/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/MessageServlet.java?rev=1332796&view=auto
==============================================================================
--- qpid/branches/java-config-and-management/qpid/java/broker-plugins/management/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/MessageServlet.java
(added)
+++ qpid/branches/java-config-and-management/qpid/java/broker-plugins/management/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/MessageServlet.java
Tue May  1 19:50:29 2012
@@ -0,0 +1,171 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.qpid.server.management.plugin.servlet.rest;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.*;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import org.apache.qpid.server.message.AMQMessageHeader;
+import org.apache.qpid.server.message.ServerMessage;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.Queue;
+import org.apache.qpid.server.model.VirtualHost;
+import org.apache.qpid.server.queue.QueueEntry;
+import org.apache.qpid.server.queue.QueueEntryVisitor;
+import org.apache.qpid.server.subscription.Subscription;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.codehaus.jackson.map.SerializationConfig;
+
+public class MessageServlet extends AbstractServlet
+{
+    public MessageServlet(Broker broker)
+    {
+        super(broker);
+    }
+
+    @Override
+    protected void onGet(HttpServletRequest request, HttpServletResponse response) throws
IOException, ServletException
+    {
+
+        List<String> names = new ArrayList<String>();
+        // TODO - validation that there is a vhost and queue and only those in the path
+        if(request.getPathInfo() != null && request.getPathInfo().length()>0)
+        {
+            String path = request.getPathInfo().substring(1);
+            names.addAll(Arrays.asList(path.split("/")));
+        }
+        String vhostName = names.get(0);
+        String queueName = names.get(1);
+
+        VirtualHost vhost = null;
+        Queue queue = null;
+
+        for(VirtualHost vh : getBroker().getVirtualHosts())
+        {
+            if(vh.getName().equals(vhostName))
+            {
+                vhost = vh;
+                break;
+            }
+        }
+
+        for(Queue q : vhost.getQueues())
+        {
+            if(q.getName().equals(queueName))
+            {
+                queue = q;
+                break;
+            }
+        }
+
+        int first = -1;
+        int last = -1;
+        String range = request.getHeader("Range");
+        if(range != null)
+        {
+            String[] boundaries = range.split("=")[1].split("-");
+            first = Integer.parseInt(boundaries[0]);
+            last = Integer.parseInt(boundaries[1]);
+        }
+        final MessageCollector messageCollector = new MessageCollector(first, last);
+        queue.visit(messageCollector);
+
+        response.setContentType("application/json");
+        final List<Map<String, Object>> messages = messageCollector.getMessages();
+        response.setHeader("Content-Range", messages.isEmpty()
+                                                    ? "0-0/0"
+                                                    : messages.get(0).get("id").toString()
+                                                      + "-"
+                                                      + messages.get(messages.size()-1).get("id").toString()
+                                                      + "/" + queue.getStatistics().getStatistic(Queue.QUEUE_DEPTH_MESSAGES));
+        response.setStatus(HttpServletResponse.SC_OK);
+
+        response.setHeader("Cache-Control","no-cache");
+        response.setHeader("Pragma","no-cache");
+        response.setDateHeader ("Expires", 0);
+
+        final PrintWriter writer = response.getWriter();
+        ObjectMapper mapper = new ObjectMapper();
+        mapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
+        mapper.writeValue(writer, messages);
+
+
+    }
+
+    private class MessageCollector implements QueueEntryVisitor
+    {
+        private final int _first;
+        private final int _last;
+        private int _position = -1;
+        private final List<Map<String, Object>> _messages = new ArrayList<Map<String,
Object>>();
+
+        private MessageCollector(int first, int last)
+        {
+            _first = first;
+            _last = last;
+        }
+
+
+        public boolean visit(QueueEntry entry)
+        {
+
+            _position++;
+            if((_first == -1 || _position >= _first) && (_last == -1 || _position
<= _last))
+            {
+                _messages.add(convertToObject(entry, _position));
+            }
+            return _last != -1 && _position > _last;
+        }
+
+        public List<Map<String, Object>> getMessages()
+        {
+            return _messages;
+        }
+    }
+
+    private Map<String, Object> convertToObject(QueueEntry entry, int position)
+    {
+        Map<String, Object> object = new LinkedHashMap<String, Object>();
+        object.put("id", position);
+        object.put("size", entry.getSize());
+        object.put("deliveryCount", entry.getDeliveryCount());
+        object.put("state",entry.isAvailable()
+                                   ? "Available"
+                                   : entry.isAcquired()
+                                             ? "Acquired"
+                                             : "");
+        final Subscription deliveredSubscription = entry.getDeliveredSubscription();
+        object.put("deliveredTo", deliveredSubscription == null ? null : deliveredSubscription.getSubscriptionID());
+        final AMQMessageHeader messageHeader = entry.getMessageHeader();
+        if(messageHeader != null)
+        {
+            object.put("messageId", messageHeader.getMessageId());
+            object.put("expirationTime", messageHeader.getExpiration());
+        }
+        ServerMessage message = entry.getMessage();
+        if(message != null)
+        {
+            object.put("arrivalTime",message.getArrivalTime());
+            object.put("persistent", message.isPersistent());
+        }
+        return object;
+    }
+}

Modified: qpid/branches/java-config-and-management/qpid/java/broker-plugins/management/src/main/java/resources/css/queue.css
URL: http://svn.apache.org/viewvc/qpid/branches/java-config-and-management/qpid/java/broker-plugins/management/src/main/java/resources/css/queue.css?rev=1332796&r1=1332795&r2=1332796&view=diff
==============================================================================
--- qpid/branches/java-config-and-management/qpid/java/broker-plugins/management/src/main/java/resources/css/queue.css
(original)
+++ qpid/branches/java-config-and-management/qpid/java/broker-plugins/management/src/main/java/resources/css/queue.css
Tue May  1 19:50:29 2012
@@ -27,3 +27,10 @@
 	width: 100%;
 	height: 100px;
 }
+
+
+#messages {
+	width: 100%;
+	height: 700px;
+}
+

Modified: qpid/branches/java-config-and-management/qpid/java/broker-plugins/management/src/main/java/resources/js/queue.js
URL: http://svn.apache.org/viewvc/qpid/branches/java-config-and-management/qpid/java/broker-plugins/management/src/main/java/resources/js/queue.js?rev=1332796&r1=1332795&r2=1332796&view=diff
==============================================================================
--- qpid/branches/java-config-and-management/qpid/java/broker-plugins/management/src/main/java/resources/js/queue.js
(original)
+++ qpid/branches/java-config-and-management/qpid/java/broker-plugins/management/src/main/java/resources/js/queue.js
Tue May  1 19:50:29 2012
@@ -226,3 +226,25 @@ require(["dojo/store/JsonRest",
 
      });
 
+require(["dojo/store/JsonRest"], function(JsonRest)
+{
+    urlQuery = dojo.queryToObject(dojo.doc.location.search.substr((dojo.doc.location.search[0]
=== "?" ? 1 : 0)));
+    myStore = new JsonRest({target:"/rest/message/"+ urlQuery.vhost + "/" + urlQuery.queue});
+});
+
+require([
+    "dojox/grid/DataGrid",
+    "dojo/data/ObjectStore",
+    "dojo/domReady!"
+], function(DataGrid, ObjectStore){
+    var grid = new DataGrid({
+        store: dataStore = ObjectStore({objectStore: myStore}),
+        structure: [
+            {name:"Id", field:"id", width: "50px"},
+            {name:"Size", field:"size", width: "60px"},
+            {name:"State", field:"state", width: "120px"},
+            {name:"Arrival", field:"arrivalTime", width: "100%"}
+        ]
+    }, "messages"); // make sure you have a target HTML element with this id
+    grid.startup();
+});
\ No newline at end of file

Modified: qpid/branches/java-config-and-management/qpid/java/broker-plugins/management/src/main/java/resources/queue.html
URL: http://svn.apache.org/viewvc/qpid/branches/java-config-and-management/qpid/java/broker-plugins/management/src/main/java/resources/queue.html?rev=1332796&r1=1332795&r2=1332796&view=diff
==============================================================================
--- qpid/branches/java-config-and-management/qpid/java/broker-plugins/management/src/main/java/resources/queue.html
(original)
+++ qpid/branches/java-config-and-management/qpid/java/broker-plugins/management/src/main/java/resources/queue.html
Tue May  1 19:50:29 2012
@@ -121,6 +121,10 @@
                 <div id="consumers"></div>
             </div>
             <br/>
+            <div data-dojo-type="dijit.TitlePane" data-dojo-props="title: 'Messages'">
+                <div id="messages"></div>
+            </div>
+            <br/>
             <div data-dojo-type="dijit.TitlePane" data-dojo-props="title: 'Alerting Thresholds'">
                 <span style="">Max. Queue Size:</span>
                 <span id="alertThresholdQueueDepthMessages"



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message