Permalink
Browse files

wip

  • Loading branch information...
1 parent 2c51267 commit aeb491efb3b296557b32ddb6b702707ce86d5238 Dave Parfitt committed Mar 23, 2013
Showing with 508 additions and 313 deletions.
  1. +20 −19 src/main/java/com/basho/contact/ContactWalker.java
  2. +24 −0 src/main/java/com/basho/contact/RiakCommand.java
  3. +18 −0 src/main/java/com/basho/contact/actions/ActionParams.java
  4. +1 −0 src/main/java/com/basho/contact/actions/Binding.java
  5. +19 −21 src/main/java/com/basho/contact/actions/ContactActionListener.java
  6. +0 −47 src/main/java/com/basho/contact/actions/FetchActionParams.java
  7. +40 −87 src/main/java/com/basho/contact/actions/JSActionListener.java
  8. +18 −8 src/main/java/com/basho/contact/commands/ConnectCommand.java
  9. +25 −0 src/main/java/com/basho/contact/commands/ConnectParams.java
  10. +6 −1 src/main/java/com/basho/contact/commands/DeleteCommand.java
  11. +13 −0 src/main/java/com/basho/contact/commands/DeleteParams.java
  12. +23 −21 src/main/java/com/basho/contact/commands/FetchCommand.java
  13. +25 −0 src/main/java/com/basho/contact/commands/FetchParams.java
  14. +6 −1 src/main/java/com/basho/contact/commands/GetBucketPropsCommand.java
  15. +13 −0 src/main/java/com/basho/contact/commands/GetBucketPropsParams.java
  16. +12 −3 src/main/java/com/basho/contact/commands/ListBucketsCommand.java
  17. +18 −0 src/main/java/com/basho/contact/commands/ListBucketsParams.java
  18. +15 −5 src/main/java/com/basho/contact/commands/ListKeysCommand.java
  19. +16 −0 src/main/java/com/basho/contact/commands/ListKeysParams.java
  20. +11 −0 src/main/java/com/basho/contact/commands/MapRedParams.java
  21. +6 −1 src/main/java/com/basho/contact/commands/MapredCommand.java
  22. +32 −26 src/main/java/com/basho/contact/commands/Query2iCommand.java
  23. +40 −0 src/main/java/com/basho/contact/commands/Query2iParams.java
  24. +0 −14 src/main/java/com/basho/contact/commands/RiakCommand.java
  25. +4 −0 src/main/java/com/basho/contact/commands/SetBucketProps.java
  26. +11 −0 src/main/java/com/basho/contact/commands/SetBucketPropsParams.java
  27. +64 −59 src/main/java/com/basho/contact/commands/StoreCommand.java
  28. +28 −0 src/main/java/com/basho/contact/commands/StoreParams.java
@@ -41,7 +41,6 @@
import com.basho.contact.commands.ListBucketsCommand;
import com.basho.contact.commands.ListKeysCommand;
import com.basho.contact.commands.Query2iCommand;
-import com.basho.contact.commands.RiakCommand;
import com.basho.contact.commands.StoreCommand;
import com.basho.contact.symbols.ContactSymbol;
import com.basho.contact.symbols.ContactSymbol.SymbolType;
@@ -79,8 +78,8 @@ public void exitUsing(UsingContext ctx) {
String bucket = stripQuotes(ctx.bucket.getText());
Object o = getValue(ctx.op_with_options());
if(o instanceof RiakCommand) {
- RiakCommand<?> c = (RiakCommand<?>)o;
- c.bucket = bucket;
+ RiakCommand<?,?> c = (RiakCommand<?,?>)o;
+ c.params.bucket = bucket;
}
trace("Using bucket " + bucket);
setValue(ctx, o);
@@ -105,11 +104,13 @@ public void exitStat(StatContext ctx) {
if(o != null) {
//System.out.println("Executing " + o.getClass().getName());
if( o != null && o instanceof RiakCommand) {
- RiakCommand<?> cmd = (RiakCommand<?>)o;
- if(cmd.bucket == null) {
- cmd.bucket = runtimeCtx.getCurrentBucket();
+ RiakCommand<?,?> cmd = (RiakCommand<?,?>)o;
+
+ if(cmd.params.bucket == null) {
+ cmd.params.bucket = runtimeCtx.getCurrentBucket();
}
- ContactSymbol<?> sym = cmd.exec(runtimeCtx);
+ cmd.params.ctx = runtimeCtx;
+ ContactSymbol<?> sym = cmd.exec(runtimeCtx);
runtimeCtx.lastResult = sym;
if(ctx.assignment() != null) {
String name = (String)getValue(ctx.assignment());
@@ -237,8 +238,8 @@ public void exitOp_with_options(Op_with_optionsContext ctx) {
o = getValue(ctx.listkeys());
}
if(o instanceof RiakCommand) {
- RiakCommand<?> c = (RiakCommand<?>)o;
- c.options = (Map<String, Object>)options;
+ RiakCommand<?,?> c = (RiakCommand<?,?>)o;
+ c.params.options = (Map<String, Object>)options;
setValue(ctx, c);
}
super.exitOp_with_options(ctx);
@@ -249,7 +250,7 @@ public void exitOp_with_options(Op_with_optionsContext ctx) {
@Override
public void exitFetch(FetchContext ctx) {
FetchCommand fetch = new FetchCommand();
- fetch.key = stripQuotes(ctx.key.getText());
+ fetch.params.key = stripQuotes(ctx.key.getText());
//System.out.println("Fetching key " + fetch.key);
setValue(ctx, fetch);
super.exitFetch(ctx);
@@ -260,15 +261,15 @@ public void exitFetch(FetchContext ctx) {
@Override
public void exitStore(StoreContext ctx) {
StoreCommand store = new StoreCommand();
- store.key = stripQuotes(ctx.key.getText());
- store.content = (Content)getValue(ctx.content_string());
+ store.params.key = stripQuotes(ctx.key.getText());
+ store.params.content = (Content)getValue(ctx.content_string());
if(ctx.store_indexes() != null) {
List<PairContext> pctxs = (List<PairContext>)getValue(ctx.store_indexes());
List<Pair> indexes = new ArrayList<Pair>();
for(PairContext pc : pctxs) {
indexes.add((Pair)getValue(pc));
}
- store.indexes = indexes;
+ store.params.indexes = indexes;
}
setValue(ctx, store);
super.exitStore(ctx);
@@ -305,12 +306,12 @@ public void exitDelete(DeleteContext ctx) {
@Override
public void exitQuery2i(Query2iContext ctx) {
Query2iCommand query = new Query2iCommand();
- query.indexName = stripQuotes(ctx.index.getText());
+ query.params.indexName = stripQuotes(ctx.index.getText());
if(ctx.exact != null) {
- query.indexVal = stripQuotes(ctx.exact.getText());
+ query.params.indexVal = stripQuotes(ctx.exact.getText());
} else {
- query.min = stripQuotes(ctx.vmin.getText());
- query.max = stripQuotes(ctx.vmax.getText());
+ query.params.min = stripQuotes(ctx.vmin.getText());
+ query.params.max = stripQuotes(ctx.vmax.getText());
}
setValue(ctx, query);
@@ -380,8 +381,8 @@ public void exitConnect(ConnectContext ctx) {
int pbPort = Integer.parseInt(ctx.pbport.getText());
ConnectCommand command = new ConnectCommand();
- command.host = host;
- command.pbPort = pbPort;
+ command.params.host = host;
+ command.params.pbPort = pbPort;
setValue(ctx, command);
super.exitConnect(ctx);
@@ -0,0 +1,24 @@
+package com.basho.contact;
+
+import java.util.Map;
+
+import com.basho.contact.Content;
+import com.basho.contact.RuntimeContext;
+import com.basho.contact.actions.ActionParams;
+import com.basho.contact.symbols.ContactSymbol;
+
+public abstract class RiakCommand<K extends ContactSymbol<?>, O extends ActionParams> {
+ public O params;
+ private Class<O> clazz;
+
+ public abstract K exec(RuntimeContext ctx);
+
+ public RiakCommand(Class<O> c) {
+ clazz = c;
+ try {
+ params = clazz.newInstance();
+ } catch(Exception e) {
+ e.printStackTrace();
+ }
+ }
+}
@@ -0,0 +1,18 @@
+package com.basho.contact.actions;
+
+import com.basho.contact.Content;
+import com.basho.contact.RuntimeContext;
+
+import java.util.Map;
+
+public class ActionParams {
+ @Binding(name = "bucket", copy=true)
+ public String bucket = null;
+
+ @Binding(name="options", copy=true)
+ public Map<String, Object> options = null;
+
+ @Binding(name="contact", copy=true)
+ public RuntimeContext ctx;
+
+}
@@ -9,4 +9,5 @@
@Retention(RetentionPolicy.RUNTIME)
public @interface Binding {
String name() default "";
+ boolean copy() default true;
}
@@ -4,43 +4,41 @@
import java.util.Map;
import java.util.Set;
+import com.basho.contact.commands.*;
import com.basho.riak.client.IRiakClient;
import com.basho.riak.client.IRiakObject;
-import com.basho.riak.client.operations.FetchObject;
import com.basho.riak.client.operations.StoreObject;
import com.basho.riak.client.query.indexes.FetchIndex;
public interface ContactActionListener{
public void init();
public void term();
-// public void preFetchAction(FetchObject<IRiakObject> fetchObj);
-// public void postFetchAction(IRiakObject obj);
+ public void preConnectAction(ConnectParams.Pre params);
+ public void postConnectAction(ConnectParams.Post params);
- public FetchActionParams.Pre preFetchAction(FetchActionParams.Pre params);
- public FetchActionParams.Post postFetchAction(FetchActionParams.Post params);
+ public void preFetchAction(FetchParams.Pre params);
+ public void postFetchAction(FetchParams.Post params);
- public void preStoreAction(StoreObject<IRiakObject> storeObj);
- public void postStoreAction(IRiakObject obj);
+ public void preStoreAction(StoreParams.Pre params);
+ public void postStoreAction(StoreParams.Post params);
- public void preDeleteAction();
- public void postDeleteAction(IRiakObject obj);
+ public void preDeleteAction(DeleteParams.Pre params);
+ public void postDeleteAction(DeleteParams.Post params);
- public void preQuery2iAction(FetchIndex<?> idx);
- public void postQuery2iAction(List<?> data);
+ public void preQuery2iAction(Query2iParams.Pre params);
+ public void postQuery2iAction(Query2iParams.Post params);
- public void preMapredAction();
- public void postMapredAction();
+ public void preMapredAction(MapRedParams.Pre params);
+ public void postMapredAction(MapRedParams.Post params);
- public void preListBucketsAction();
- public void postListBucketsAction(Set<String> buckets);
+ public void preListBucketsAction(ListBucketsParams.Pre params);
+ public void postListBucketsAction(ListBucketsParams.Post params);
- public void preListKeysAction(String bucket);
- public void postListKeysAction(List<String> keys);
+ public void preListKeysAction(ListKeysParams.Pre params);
+ public void postListKeysAction(ListKeysParams.Post params);
- public void preGetBucketPropsAction(String bucket);
- public void postGetBucketPropsAction(Map<String, Object> props);
+ public void preGetBucketPropsAction(GetBucketPropsParams.Pre params);
+ public void postGetBucketPropsAction(GetBucketPropsParams.Post params);
- public void preConnectAction(String host, String port);
- public void postConnectAction(String host, String port, IRiakClient client);
}
@@ -1,47 +0,0 @@
-package com.basho.contact.actions;
-
-
-import com.basho.riak.client.IRiakObject;
-import com.basho.riak.client.operations.FetchObject;
-
-import java.lang.reflect.Field;
-import java.util.Map;
-
-public class FetchActionParams {
- public static class Pre {
- @Binding(name = "bucket")
- public String bucket;
-
- @Binding(name = "key")
- public String key;
-
- @Binding(name = "options")
- public Map<String, Object> options;
-
- @Binding(name = "fetchObj")
- public FetchObject<IRiakObject> fetchObj;
- }
-
- public static class Post {
- @Binding(name = "bucket")
- public String bucket;
-
- @Binding(name = "key")
- public String key;
-
- @Binding(name = "options")
- public Map<String, Object> options;
-
- @Binding(name = "obj")
- public IRiakObject object;
- }
-
-
-
-// public static void main(String args[]) {
-// FetchActionParams.Pre p = new FetchActionParams.Pre();
-// p.bucket = "foo";
-// p.key = "bar";
-// wrapObjectWithAnnotations(p);
-// }
-}
Oops, something went wrong.

0 comments on commit aeb491e

Please sign in to comment.