Permalink
Browse files

Define new API for riak-java-client

  • Loading branch information...
0 parents commit 736572a0af49bec181b9be491c369119145ec8cc @russelldb russelldb committed Mar 22, 2011
Showing with 1,014 additions and 0 deletions.
  1. +4 −0 .gitignore
  2. +35 −0 README
  3. +49 −0 pom.xml
  4. +20 −0 src/main/java/com/basho/riak/client/newapi/AnonymousFunction.java
  5. +41 −0 src/main/java/com/basho/riak/client/newapi/Bucket.java
  6. +23 −0 src/main/java/com/basho/riak/client/newapi/Builder.java
  7. +39 −0 src/main/java/com/basho/riak/client/newapi/DeleteCAP.java
  8. +40 −0 src/main/java/com/basho/riak/client/newapi/FetchCAP.java
  9. +22 −0 src/main/java/com/basho/riak/client/newapi/Function.java
  10. +53 −0 src/main/java/com/basho/riak/client/newapi/NamedErlangFunction.java
  11. +20 −0 src/main/java/com/basho/riak/client/newapi/NamedFunction.java
  12. +28 −0 src/main/java/com/basho/riak/client/newapi/Quorum.java
  13. +92 −0 src/main/java/com/basho/riak/client/newapi/RiakClient.java
  14. +22 −0 src/main/java/com/basho/riak/client/newapi/RiakLink.java
  15. +36 −0 src/main/java/com/basho/riak/client/newapi/RiakObject.java
  16. +46 −0 src/main/java/com/basho/riak/client/newapi/RiakServerInfo.java
  17. +60 −0 src/main/java/com/basho/riak/client/newapi/StoreCAP.java
  18. +22 −0 src/main/java/com/basho/riak/client/newapi/VClock.java
  19. +66 −0 src/main/java/com/basho/riak/client/newapi/VClockPruneBuilder.java
  20. +147 −0 src/main/java/com/basho/riak/client/newapi/VClockPruning.java
  21. +24 −0 src/main/java/com/basho/riak/client/newapi/query/MapReduceBuilder.java
  22. +48 −0 src/main/java/com/basho/riak/client/newapi/query/MapReduceResult.java
  23. +26 −0 src/main/java/com/basho/riak/client/newapi/query/MapReduceSpec.java
  24. +26 −0 src/main/java/com/basho/riak/client/newapi/query/WalkResult.java
  25. +25 −0 src/main/java/com/basho/riak/client/newapi/query/WalkSpec.java
@@ -0,0 +1,4 @@
+.project
+.classpath
+target/
+.settings/
35 README
@@ -0,0 +1,35 @@
+# Riak Java Client API - request for comments
+
+## What's wrong?
+Accusations have been made against the current [riak-java-client](https://github.com/basho/riak-java-client). Certainly it leaks implementation details (Apache HttpClient, JSONArray, JSONObject, ByteString etc) into client code. And there are *3* different possible client interfaces:
+
+* An Http style client
+* A more OO client that uses the Http client
+* A protocol buffers client
+
+All of these leak their abstractions and force the user to make an upfront choice about transport/features and then code to that decision.
+
+Some people don't like Apache HttpClient, and that is fair enough, so it would be ideal if we didn't force it on those people. Better yet make it easy to create new implementations for the transport (using Netty or RestTemplate or carrier pigeon).
+
+## What am I doing?
+In an attempt to alliviate this I/we am/are attempting to design a simple API (and SPI (more later)) so that we can use the riak-java-client and not have to be concerened with the underlying transport, serialization format and other implementation trivia. Which is good, 'cos you *want* to use the protobufs client, m'kay?
+
+## What can *you* do?
+This repo is a request for comments. It is just a starting point and I'll be pushing a lot over the next few days, but I'd really appreciate any riak Java client users (past, present or future) to look over this API and let me know your thoughts. It is, hopefully, the bare minimum API that is needed to speak to riak. Please contact me however you like[1] but ideally the [riak-users mailing list](http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com) so the discussion is public and archived.
+
+## What next?
+I'm going to start adapting the existing clients to this interface and duplicating the existing tests and then coding up the [riak fast track](http://wiki.basho.com/The-Riak-Fast-Track.html) ASAP, from that I hope to learn 2 things:
+
+1. Will it work as an API
+2. What is the simplest SPI for plugging in new transports
+
+With the feedback garnered hopefully I can start working the client into the new API and the future will be rosy.
+
+---
+
+[1] alt. contact
+* #riak on freenode
+* the wiki for this repo
+* pull requests
+* [twitter](http://twitter.com/#!/russelldb)
+* email (look in the pom)
49 pom.xml
@@ -0,0 +1,49 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>com.basho.riak</groupId>
+ <artifactId>riak-java-client-api</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>jar</packaging>
+
+ <name>riak-client-api</name>
+ <description>Tentative common API for riak java client</description>
+ <url>http://github.com/russelldb/riak-java-client-api</url>
+
+ <licenses>
+ <license>
+ <name>The Apache Software License, Version 2.0</name>
+ <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
+ </license>
+ </licenses>
+
+ <developers>
+ <developer>
+ <name>Russell Brown</name>
+ <email>russelldb@basho.com</email>
+ </developer>
+ </developers>
+
+ <scm>
+ <url>http://github.org/basho/riak-java-client</url>
+ <connection>scm:git:git://github.com/russelldb/riak-java-client-api</connection>
+ </scm>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
@@ -0,0 +1,20 @@
+/*
+ * This file is provided 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 com.basho.riak.client.newapi;
+
+/**
+ * @author russell
+ *
+ */
+public interface AnonymousFunction extends Function {}
@@ -0,0 +1,41 @@
+/*
+ * This file is provided 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 com.basho.riak.client.newapi;
+
+import java.util.Collection;
+
+/**
+ * Models a Riak Bucket.
+ *
+ * @author russell
+ *
+ */
+public interface Bucket extends Iterable<RiakObject> {
+ boolean isAllowSiblings();
+ boolean isLastWriteWins();
+ int getNVal();
+ String getBackend();
+ int getSmallVClock();
+ int getBigVClock();
+ long getYoungVClock();
+ long getOldVClock();
+ Collection<NamedFunction> getPrecommitHooks();
+ Collection<NamedErlangFunction> getPostCommitHooks();
+ NamedErlangFunction getChashKeyFunction();
+ NamedErlangFunction getLinkWalkFunction();
+ Quorum getR();
+ Quorum getW();
+ Quorum getDW();
+ Quorum getRW();
+}
@@ -0,0 +1,23 @@
+/*
+ * This file is provided 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 com.basho.riak.client.newapi;
+
+/**
+ * Common interface for object builders.
+ * @author russell
+ *
+ */
+public interface Builder<T> {
+ T build();
+}
@@ -0,0 +1,39 @@
+/*
+ * This file is provided 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 com.basho.riak.client.newapi;
+
+/**
+ * Per request tunable CAP settings for a delete operation.
+ *
+ * @author russell
+ *
+ */
+public final class DeleteCAP {
+ private final Integer rw;
+
+ public DeleteCAP(int rw) {
+ this.rw = rw;
+ }
+
+ /**
+ * @return the rw
+ */
+ public int getRw() {
+ return rw;
+ }
+
+ public static DeleteCAP rw(int rw) {
+ return new DeleteCAP(rw);
+ }
+}
@@ -0,0 +1,40 @@
+/*
+ * This file is provided 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 com.basho.riak.client.newapi;
+
+/**
+ * Tunable CAP properties on a fetch operation.
+ *
+ * @author russell
+ *
+ */
+public final class FetchCAP {
+ private final Integer r;
+
+ public FetchCAP(int r) {
+ this.r = r;
+ }
+
+ /**
+ * @return the r
+ */
+ public int getR() {
+ return r;
+ }
+
+ public static FetchCAP r(int r) {
+ return new FetchCAP(r);
+ }
+
+}
@@ -0,0 +1,22 @@
+/*
+ * This file is provided 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 com.basho.riak.client.newapi;
+
+/**
+ * Marker interface for a function.
+ *
+ * @author russell
+ *
+ */
+public interface Function {}
@@ -0,0 +1,53 @@
+/*
+ * This file is provided 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 com.basho.riak.client.newapi;
+
+/**
+ * Models a named erlang function.
+ *
+ * Immutable.
+ *
+ * @author russell
+ *
+ */
+public class NamedErlangFunction implements NamedFunction {
+ private final String mod;
+ private final String fun;
+
+ /**
+ * @param mod
+ * the module that contains the function.
+ * @param fun
+ * the function name.
+ */
+ public NamedErlangFunction(String mod, String fun) {
+ this.mod = mod;
+ this.fun = fun;
+ }
+
+ /**
+ * @return the erlang module that contains the function.
+ */
+ public String getMod() {
+ return mod;
+ }
+
+ /**
+ * @return the function name.
+ */
+ public String getFun() {
+ return fun;
+ }
+
+}
@@ -0,0 +1,20 @@
+/*
+ * This file is provided 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 com.basho.riak.client.newapi;
+
+/**
+ * @author russell
+ *
+ */
+public interface NamedFunction extends Function {}
@@ -0,0 +1,28 @@
+/*
+ * This file is provided 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 com.basho.riak.client.newapi;
+
+/**
+ * @author russell
+ *
+ */
+public enum Quorum {
+ ALL, ONE, QUORUM, OTHER;
+
+ private int intVal;
+
+ public int toInt() {
+ return this.intVal;
+ }
+}
Oops, something went wrong.

0 comments on commit 736572a

Please sign in to comment.