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 2010/07/07 06:16:38 UTC

svn commit: r961193 - in /activemq/sandbox/activemq-apollo-actor/activemq-web/src/main/scala/org/apache/activemq/apollo/web/resources: ConfigurationResource.scala RuntimeResource.scala

Author: chirino
Date: Wed Jul  7 04:16:38 2010
New Revision: 961193

URL: http://svn.apache.org/viewvc?rev=961193&view=rev
Log:
better url handling.

Modified:
    activemq/sandbox/activemq-apollo-actor/activemq-web/src/main/scala/org/apache/activemq/apollo/web/resources/ConfigurationResource.scala
    activemq/sandbox/activemq-apollo-actor/activemq-web/src/main/scala/org/apache/activemq/apollo/web/resources/RuntimeResource.scala

Modified: activemq/sandbox/activemq-apollo-actor/activemq-web/src/main/scala/org/apache/activemq/apollo/web/resources/ConfigurationResource.scala
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo-actor/activemq-web/src/main/scala/org/apache/activemq/apollo/web/resources/ConfigurationResource.scala?rev=961193&r1=961192&r2=961193&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo-actor/activemq-web/src/main/scala/org/apache/activemq/apollo/web/resources/ConfigurationResource.scala (original)
+++ activemq/sandbox/activemq-apollo-actor/activemq-web/src/main/scala/org/apache/activemq/apollo/web/resources/ConfigurationResource.scala Wed Jul  7 04:16:38 2010
@@ -16,113 +16,58 @@
  */
 package org.apache.activemq.apollo.web.resources
 
-import java.lang.String
-import com.sun.jersey.api.NotFoundException
 import javax.ws.rs._
-import core.{Response, Context}
-import org.fusesource.scalate.util.Logging
-import reflect.{BeanProperty}
-import com.sun.jersey.api.view.ImplicitProduces
+import core.{UriInfo, Response, Context}
 import org.fusesource.hawtdispatch.Future
-import Response._
 import Response.Status._
-import org.apache.activemq.apollo.dto.{IdListDTO, BrokerSummaryDTO, BrokerDTO}
-import java.util.{Arrays, Collections}
+import Response._
+import org.apache.activemq.apollo.dto.{BrokerDTO}
 import org.apache.activemq.apollo.web.ConfigStore
+import java.net.URI
 
 /**
- * Defines the default representations to be used on resources
+ * A broker resource is used to represent the configuration of a broker.
  */
-@ImplicitProduces(Array("text/html;qs=5"))
-@Produces(Array("application/json", "application/xml","text/xml"))
-trait Resource extends Logging {
-
-  def result[T](value:Status, message:Any=null):T = {
-    val response = Response.status(value)
-    if( message!=null ) {
-      response.entity(message)
-    }
-    throw new WebApplicationException(response.build)
-  }
+case class ConfigurationResource(parent:Broker) extends Resource {
 
-}
 
-/**
- * Manages a collection of broeker resources.
- */
-@Path("/")
-class Root() extends Resource {
+  def store = ConfigStore()
 
-  @Context
-  var configStore = ConfigStore()
-
-  @GET
-  def get() = {
-    val rc = new IdListDTO
-    val ids = Future[List[String]] { cb=>
-      configStore.listBrokers(cb)
-    }.toArray[String]
-    rc.ids.addAll(Arrays.asList(ids: _*))
-    rc
+  lazy val config = {
+    Future[Option[BrokerDTO]] { cb=>
+      store.getBroker(parent.id, false)(cb)
+    }.getOrElse(result(NOT_FOUND))
   }
 
-  @Path("{id}")
-  def broker(@PathParam("id") id : String): Broker = new Broker(this, id)
-}
-
-/**
- * A broker resource is used to represent the configuration and runtime status of a broker.
- */
-case class Broker(parent:Root, @BeanProperty id: String) extends Resource {
-
-  @Context
-  var configStore = ConfigStore()
 
   @GET
-  def get() = {
-    val c = config()
-    val rc = new BrokerSummaryDTO
-    rc.id = id
-    rc.rev = c.rev
-    rc
-  }
-
-  @GET @Path("config")
-  def getConfig():BrokerDTO = {
-    config()
-  }
-
-  private def config() = {
-    Future[Option[BrokerDTO]] { cb=>
-      configStore.getBroker(id, false)(cb)
-    }.getOrElse(result(NOT_FOUND))
+  def get(@Context uriInfo:UriInfo) = {
+    val ub = uriInfo.getAbsolutePathBuilder()
+    seeOther(ub.path(config.rev.toString).build()).build
   }
 
-  @GET @Path("config/{rev}")
+  @GET @Path("{rev}")
   def getConfig(@PathParam("rev") rev:Int):BrokerDTO = {
     // that rev may have gone away..
-    var c = config()
-    c.rev==rev || result(NOT_FOUND)
-    c
+    config.rev==rev || result(NOT_FOUND)
+    config
   }
 
-  @PUT @Path("config/{rev}")
+  @PUT @Path("{rev}")
   def put(@PathParam("rev") rev:Int, config:BrokerDTO) = {
-    config.id = id;
+    config.id = parent.id;
     config.rev = rev
     Future[Boolean] { cb=>
-      configStore.putBroker(config)(cb)
+      store.putBroker(config)(cb)
     } || result(NOT_FOUND)
   }
 
-  @DELETE @Path("config/{rev}")
+  @DELETE @Path("{rev}")
   def delete(@PathParam("rev") rev:Int) = {
     Future[Boolean] { cb=>
-      configStore.removeBroker(id, rev)(cb)
+      store.removeBroker(parent.id, rev)(cb)
     } || result(NOT_FOUND)
   }
 
-  @Path("status")
-  def status = RuntimeResource(this)
 }
 

Modified: activemq/sandbox/activemq-apollo-actor/activemq-web/src/main/scala/org/apache/activemq/apollo/web/resources/RuntimeResource.scala
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo-actor/activemq-web/src/main/scala/org/apache/activemq/apollo/web/resources/RuntimeResource.scala?rev=961193&r1=961192&r2=961193&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo-actor/activemq-web/src/main/scala/org/apache/activemq/apollo/web/resources/RuntimeResource.scala (original)
+++ activemq/sandbox/activemq-apollo-actor/activemq-web/src/main/scala/org/apache/activemq/apollo/web/resources/RuntimeResource.scala Wed Jul  7 04:16:38 2010
@@ -30,7 +30,8 @@ import collection.mutable.ListBuffer
 
 /**
  * <p>
- * The BrokerStatus is the root container of the runtime status of a broker.
+ * The RuntimeResource resource manages access to the runtime state of a broker.  It is used
+ * to see the status of the broker and to apply management operations against the broker.
  * </p>
  *
  * @author <a href="http://hiramchirino.com">Hiram Chirino</a>