Permalink
Browse files

Move to granular handlers: Made core rest handler abstract so handleR…

…equestAsync gets implemented by action-specfic handlers
  • Loading branch information...
1 parent 08418d4 commit 94ed204bf4165e5c43a9c3fbe32d3b6ab6608f3c @zznate committed Mar 6, 2013
@@ -21,7 +21,7 @@
* @author zznate
* @author boneill42
*/
-public class IntraHandlerRest extends IntraHandlerBase {
+public abstract class IntraHandlerRest extends IntraHandlerBase {
private final Logger logger = LoggerFactory.getLogger(IntraHandlerRest.class);
private static ObjectMapper mapper = new ObjectMapper();
@@ -34,7 +34,7 @@ public IntraHandlerRest(Vertx vertx) {
super(vertx);
}
- public void handleRequestAsync(final HttpServerRequest request, Buffer buffer) {
+ public void handleRequestAsyncProctected(final HttpServerRequest request, Buffer buffer) {
Map<String,String> reqParams = request.params();
logger.debug("Rest request [{}] : [{}]", request.method , reqParams);
@@ -60,7 +60,7 @@ public void handle(Message<JsonObject> event) {
}
public void registerRequestHandler() {
- vertx.eventBus().registerHandler("data.keyspaceMeta", new KeyspaceMetaHandler());
+ //vertx.eventBus().registerHandler("data.keyspaceMeta", new KeyspaceMetaHandler());
}
@@ -50,6 +50,8 @@ public static ConsistencyLevel fromHeader(HttpServerRequest request) {
return ConsistencyLevel.ONE;
}
+
+
/**
* Returns the JSONObject for the event bus that represents a set operation.
*/
@@ -1,16 +1,45 @@
package org.usergrid.vx.handler.rest;
+import org.apache.cassandra.config.Schema;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.usergrid.vx.experimental.IntraReq;
+import org.usergrid.vx.experimental.Operations;
import org.vertx.java.core.Handler;
+import org.vertx.java.core.Vertx;
+import org.vertx.java.core.buffer.Buffer;
import org.vertx.java.core.eventbus.Message;
+import org.vertx.java.core.http.HttpServerRequest;
import org.vertx.java.core.json.JsonObject;
+import java.util.List;
+
/**
+ * REST Handler for listing non-system keyspaces via
+ * {@link org.apache.cassandra.config.Schema#getNonSystemTables()}
+ *
* @author zznate
*/
-public class KeyspaceMetaHandler implements Handler<Message<JsonObject>> {
+public class KeyspaceMetaHandler extends IntraHandlerRest {
+
+ private Logger log = LoggerFactory.getLogger(KeyspaceMetaHandler.class);
+
+ public KeyspaceMetaHandler(Vertx vertx) {
+ super(vertx);
+ }
@Override
- public void handle(Message<JsonObject> jsonObjectMessage) {
+ public void handleRequestAsync(final HttpServerRequest request, Buffer buffer) {
+ log.debug("In KeyspaceMetaHandler#handleRequestAsync");
+ IntraReq req = new IntraReq();
+ req.add(Operations.listKeyspacesOp());
+ vertx.eventBus().send("request.json", req.toJson(), new Handler<Message<JsonObject>>() {
+ @Override
+ public void handle(Message<JsonObject> event) {
+ request.response.end(event.body.toString());
+ }
+ });
}
+
}
@@ -3,24 +3,25 @@
import java.util.List;
import org.apache.cassandra.config.Schema;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.vertx.java.core.Handler;
import org.vertx.java.core.eventbus.Message;
import org.vertx.java.core.json.JsonArray;
import org.vertx.java.core.json.JsonObject;
public class ListKeyspacesHandler implements Handler<Message<JsonObject>> {
- @Override
- public void handle(Message<JsonObject> event) {
- JsonObject params = event.body.getObject("op");
- Integer id = event.body.getInteger("id");
+ private Logger log = LoggerFactory.getLogger(ListKeyspacesHandler.class);
- JsonArray keyspaces = new JsonArray();
- for (String ks : Schema.instance.getNonSystemTables()) {
- keyspaces.addString(ks);
- }
- JsonObject response = new JsonObject().putArray(id.toString(), new JsonArray((List)Schema.instance.getNonSystemTables()));
+ @Override
+ public void handle(Message<JsonObject> event) {
+ log.debug("in ListKeyspaceHandler#handle");
- event.reply(response);
- }
+ Integer id = event.body.getInteger("id");
+
+ JsonObject response = new JsonObject().putArray(id.toString(), new JsonArray((List)Schema.instance.getNonSystemTables()));
+
+ event.reply(response);
+ }
}

0 comments on commit 94ed204

Please sign in to comment.