Skip to content
Browse files

Minor cleanups; add README

  • Loading branch information...
1 parent a5d72e4 commit 75d271411a2c00de9781f3b0e0989971de2dfdbd @krestenkrab committed Jun 25, 2010
Showing with 78 additions and 9 deletions.
  1. +67 −0 README.markdown
  2. +10 −8 src/com/trifork/riak/RiakClient.java
  3. +1 −1 src/com/trifork/riak/mapreduce/MapReduceBuilder.java
View
67 README.markdown
@@ -0,0 +1,67 @@
+## Java Client API for Riak based on the Protocol Buffers API
+
+This is an alternative to
+(riak-java-client)[http://hg.basho.com/riak-java-client/] which offers
+significantly better performance because you avoid encoding and decoding
+content into the HTTP protocol.
+
+
+ RiakClient riak = new RiakClient("127.0.0.1");
+ byte[] data = new byte[] { 1, 2, 3, 4 };
+ RiakObject ro = new RiakObject("Bucket", "Key",
+ ByteString.copyFrom(data));
+ riak.store(ro);
+
+Some of the API uses `com.google.protobuf.ByteString` which represents a
+chunk of (uninterpreted) bytes.
+
+Here is a complete program to list the entire contents of a riak
+store.
+
+ RiakClient client = new RiakClient("127.0.0.1");
+ ByteString[] buckets = client.listBuckets();
+ for (ByteString bucket : buckets) {
+ System.out.println("=bucket "+bucket.toStringUtf8());
+ KeySource keys = client.listKeys(bucket);
+ for (ByteString key : keys) {
+ System.out.println("==key "+key.toStringUtf8());
+ RiakObject[] ros = client.fetch(bucket, key);
+ for (RiakObject ro : ros) {
+ System.out.println("==="+ro.toString());
+ }
+ }
+ keys.close();
+ }
+
+The methods `RiakClient.listKeys` and `RiakClient.mapReduce` return
+streaming handlers that should be closed when done.
+
+If you set a clientID `RiakClient.setClientID`; that client ID is used
+for all connections coming from the same client. `RiakClient` is
+"thread safe" so you can use it from several threads at the same time.
+
+### Bulk Insert
+
+The method `RiakClient.store(RiakObject[], RequestMeta)` allows
+efficient bulk insertion (connection request/responses are handled
+asynchroneously underneath the covers). To run even faster, you can
+choose to run this in several threads (resulting in multiple connections).
+
+
+## License / Copyright
+
+ A Java Client API for Riak based on the Protocol Buffers API
+
+ Copyright (C) 2010 Trifork A/S
+
+ Licensed 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.
View
18 src/com/trifork/riak/RiakClient.java
@@ -405,7 +405,7 @@ public void store(RiakObject value) throws IOException {
// /////////////////////
- void delete(String bucket, String key, int rw) throws IOException {
+ public void delete(String bucket, String key, int rw) throws IOException {
delete(ByteString.copyFromUtf8(bucket), ByteString.copyFromUtf8(key),
rw);
}
@@ -425,7 +425,7 @@ public void delete(ByteString bucket, ByteString key, int rw)
}
- void delete(String bucket, String key) throws IOException {
+ public void delete(String bucket, String key) throws IOException {
delete(ByteString.copyFromUtf8(bucket), ByteString.copyFromUtf8(key));
}
@@ -506,8 +506,6 @@ public void setBucketProperties(ByteString bucket, BucketProperties props)
public KeySource listKeys(ByteString bucket) throws IOException {
- List<ByteString> keys = new ArrayList<ByteString>();
-
RiakConnection c = getConnection();
c.send(MSG_ListKeysReq, RPB.RpbListKeysReq.newBuilder().setBucket(
bucket).build());
@@ -517,14 +515,18 @@ public KeySource listKeys(ByteString bucket) throws IOException {
// /////////////////////
- MapReduceResponseSource mapreduce(JSONObject obj) throws IOException {
- return mapreduce(ByteString.copyFromUtf8(obj.toString()),
+ public MapReduceResponseSource mapReduce(JSONObject obj) throws IOException {
+ return mapReduce(ByteString.copyFromUtf8(obj.toString()),
new RequestMeta().contentType("application/json"));
}
- public MapReduceResponseSource mapreduce(ByteString request,
+ public MapReduceResponseSource mapReduce(String request,
+ RequestMeta meta) throws IOException {
+ return mapReduce(ByteString.copyFromUtf8(request), meta);
+ }
+
+ public MapReduceResponseSource mapReduce(ByteString request,
RequestMeta meta) throws IOException {
- List<MapReduceResponse> out = new ArrayList<MapReduceResponse>();
RiakConnection c = getConnection();
ByteString contentType = meta.getContentType();
View
2 src/com/trifork/riak/mapreduce/MapReduceBuilder.java
@@ -317,7 +317,7 @@ public MapReduceBuilder link(String bucket, String tag, boolean keep) {
public MapReduceResponseSource submit(RequestMeta meta) throws IOException {
if (riak == null)
throw new IllegalStateException("Cannot perform map reduce without a RiakClient");
- return riak.mapreduce(ByteString.copyFromUtf8( toJSON().toString() ), meta);
+ return riak.mapReduce(ByteString.copyFromUtf8( toJSON().toString() ), meta);
}
public MapReduceResponseSource submit() throws JSONException, IOException {

0 comments on commit 75d2714

Please sign in to comment.
Something went wrong with that request. Please try again.