You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ch...@apache.org on 2011/06/13 17:10:36 UTC
svn commit: r1135130 - in /activemq/activemq-apollo/trunk:
apollo-dto/src/main/java/org/apache/activemq/apollo/dto/
apollo-dto/src/main/resources/org/apache/activemq/apollo/dto/
apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/
Author: chirino
Date: Mon Jun 13 15:10:36 2011
New Revision: 1135130
URL: http://svn.apache.org/viewvc?rev=1135130&view=rev
Log:
Wrap the tabular results in a DataPageDTO so that the client can also get information about how many total pages there are available to be paged.
Added:
activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/DataPageDTO.java
Modified:
activemq/activemq-apollo/trunk/apollo-dto/src/main/resources/org/apache/activemq/apollo/dto/jaxb.index
activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/BrokerResource.scala
Added: activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/DataPageDTO.java
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/DataPageDTO.java?rev=1135130&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/DataPageDTO.java (added)
+++ activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/DataPageDTO.java Mon Jun 13 15:10:36 2011
@@ -0,0 +1,86 @@
+/**
+ * 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.activemq.apollo.dto;
+
+import javax.xml.bind.annotation.*;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * <p>
+ * </p>
+ *
+ * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
+ */
+@XmlRootElement(name="data_table")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class DataPageDTO {
+
+ /**
+ */
+ @XmlAttribute(name="page")
+ public int page;
+
+ /**
+ */
+ @XmlAttribute(name="row_max")
+ public int row_max;
+
+ /**
+ */
+ @XmlAttribute(name="total_pages")
+ public int total_pages;
+
+ /**
+ */
+ @XmlAttribute(name="total_rows")
+ public long total_rows;
+
+ @XmlElement(name="header")
+ public List<String> headers = new ArrayList<String>();
+
+ @XmlElement(name="row")
+ public List<?> rows = new ArrayList<Object>();
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof DataPageDTO)) return false;
+
+ DataPageDTO that = (DataPageDTO) o;
+
+ if (page != that.page) return false;
+ if (row_max != that.row_max) return false;
+ if (total_pages != that.total_pages) return false;
+ if (total_rows != that.total_rows) return false;
+ if (headers != null ? !headers.equals(that.headers) : that.headers != null) return false;
+ if (rows != null ? !rows.equals(that.rows) : that.rows != null) return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = page;
+ result = 31 * result + row_max;
+ result = 31 * result + total_pages;
+ result = 31 * result + (int) (total_rows ^ (total_rows >>> 32));
+ result = 31 * result + (headers != null ? headers.hashCode() : 0);
+ result = 31 * result + (rows != null ? rows.hashCode() : 0);
+ return result;
+ }
+}
Modified: activemq/activemq-apollo/trunk/apollo-dto/src/main/resources/org/apache/activemq/apollo/dto/jaxb.index
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-dto/src/main/resources/org/apache/activemq/apollo/dto/jaxb.index?rev=1135130&r1=1135129&r2=1135130&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-dto/src/main/resources/org/apache/activemq/apollo/dto/jaxb.index (original)
+++ activemq/activemq-apollo/trunk/apollo-dto/src/main/resources/org/apache/activemq/apollo/dto/jaxb.index Mon Jun 13 15:10:36 2011
@@ -44,4 +44,5 @@ TopicDTO
LinkDTO
QueueConsumerStatusDTO
ValueDTO
-StringListDTO
\ No newline at end of file
+StringListDTO
+DataPageDTO
\ No newline at end of file
Modified: activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/BrokerResource.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/BrokerResource.scala?rev=1135130&r1=1135129&r2=1135130&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/BrokerResource.scala (original)
+++ activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/BrokerResource.scala Mon Jun 13 15:10:36 2011
@@ -308,7 +308,18 @@ case class BrokerResource() extends Reso
val list = query.execute(records).getResults
- Success(seqAsJavaList( headers :: list.toList) )
+ val rc = new DataPageDTO
+ rc.page = page
+ rc.row_max = page_size
+
+ def total_pages(x:Int,y:Int) = if(x==0) 1 else { x/y + (if ( x%y == 0 ) 0 else 1) }
+ rc.total_pages = total_pages(records.length, rc.row_max)
+
+ rc.total_rows = records.length
+ rc.headers = headers
+ rc.rows = list
+
+ Success(rc)
} catch {
case e:Throwable => Failure(e)
}
@@ -317,7 +328,7 @@ case class BrokerResource() extends Reso
@GET @Path("virtual-hosts/{id}/topics")
@Produces(Array("application/json"))
def topics(@PathParam("id") id : String, @QueryParam("f") f:java.util.List[String],
- @QueryParam("q") q:String, @QueryParam("p") p:java.lang.Integer, @QueryParam("ps") ps:java.lang.Integer ):java.util.List[_] = {
+ @QueryParam("q") q:String, @QueryParam("p") p:java.lang.Integer, @QueryParam("ps") ps:java.lang.Integer ):DataPageDTO = {
with_virtual_host(id) { host =>
val router: LocalRouter = host
val records = Future.all {
@@ -325,7 +336,7 @@ case class BrokerResource() extends Reso
status(value)
}
}
- val rc:FutureResult[java.util.List[_]] = records.map(narrow(classOf[TopicStatusDTO], _, f, q, p, ps))
+ val rc:FutureResult[DataPageDTO] = records.map(narrow(classOf[TopicStatusDTO], _, f, q, p, ps))
rc
}
}
@@ -342,7 +353,7 @@ case class BrokerResource() extends Reso
@GET @Path("virtual-hosts/{id}/queues")
@Produces(Array("application/json"))
def queues(@PathParam("id") id : String, @QueryParam("f") f:java.util.List[String],
- @QueryParam("q") q:String, @QueryParam("p") p:java.lang.Integer, @QueryParam("ps") ps:java.lang.Integer ):java.util.List[_] = {
+ @QueryParam("q") q:String, @QueryParam("p") p:java.lang.Integer, @QueryParam("ps") ps:java.lang.Integer ):DataPageDTO = {
with_virtual_host(id) { host =>
val router: LocalRouter = host
val values: Iterable[Queue] = router.queue_domain.destination_by_id.values
@@ -351,7 +362,7 @@ case class BrokerResource() extends Reso
status(value, false)
}
- val rc:FutureResult[java.util.List[_]] = records.map(narrow(classOf[QueueStatusDTO], _, f, q, p, ps))
+ val rc:FutureResult[DataPageDTO] = records.map(narrow(classOf[QueueStatusDTO], _, f, q, p, ps))
rc
}
}
@@ -389,7 +400,7 @@ case class BrokerResource() extends Reso
@GET @Path("virtual-hosts/{id}/dsubs")
@Produces(Array("application/json"))
def durable_subscriptions(@PathParam("id") id : String, @QueryParam("f") f:java.util.List[String],
- @QueryParam("q") q:String, @QueryParam("p") p:java.lang.Integer, @QueryParam("ps") ps:java.lang.Integer ):java.util.List[_] = {
+ @QueryParam("q") q:String, @QueryParam("p") p:java.lang.Integer, @QueryParam("ps") ps:java.lang.Integer ):DataPageDTO = {
with_virtual_host(id) { host =>
val router: LocalRouter = host
val values: Iterable[Queue] = router.topic_domain.durable_subscriptions_by_id.values
@@ -398,7 +409,7 @@ case class BrokerResource() extends Reso
status(value, false)
}
- val rc:FutureResult[java.util.List[_]] = records.map(narrow(classOf[QueueStatusDTO], _, f, q, p, ps))
+ val rc:FutureResult[DataPageDTO] = records.map(narrow(classOf[QueueStatusDTO], _, f, q, p, ps))
rc
}
}
@@ -537,7 +548,7 @@ case class BrokerResource() extends Reso
@GET @Path("connectors")
@Produces(Array("application/json"))
def connectors(@QueryParam("f") f:java.util.List[String], @QueryParam("q") q:String,
- @QueryParam("p") p:java.lang.Integer, @QueryParam("ps") ps:java.lang.Integer ):java.util.List[_] = {
+ @QueryParam("p") p:java.lang.Integer, @QueryParam("ps") ps:java.lang.Integer ):DataPageDTO = {
with_broker { broker =>
monitoring(broker) {
@@ -605,7 +616,7 @@ case class BrokerResource() extends Reso
@GET @Path("connections")
@Produces(Array("application/json"))
def connections(@QueryParam("f") f:java.util.List[String], @QueryParam("q") q:String,
- @QueryParam("p") p:java.lang.Integer, @QueryParam("ps") ps:java.lang.Integer ):java.util.List[_] = {
+ @QueryParam("p") p:java.lang.Integer, @QueryParam("ps") ps:java.lang.Integer ):DataPageDTO = {
with_broker { broker =>
monitoring(broker) {
@@ -614,7 +625,7 @@ case class BrokerResource() extends Reso
value.get_connection_status
}
- val rc:FutureResult[java.util.List[_]] = records.map(narrow(classOf[ConnectionStatusDTO], _, f, q, p, ps))
+ val rc:FutureResult[DataPageDTO] = records.map(narrow(classOf[ConnectionStatusDTO], _, f, q, p, ps))
rc
}
}