Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 83 lines (63 sloc) 3.319 kb
75d2714 @krestenkrab Minor cleanups; add README
authored
1 ## Java Client API for Riak based on the Protocol Buffers API
2
3 This is an alternative to
731c34f @krestenkrab Updates to readme.
authored
4 [riak-java-client](http://hg.basho.com/riak-java-client/) which offers
5 significantly better performance because you avoid encoding and
6 decoding content into the HTTP protocol. On my dev machine I see ~
7 10x performance improvement; so that's worth taking.
75d2714 @krestenkrab Minor cleanups; add README
authored
8
731c34f @krestenkrab Updates to readme.
authored
9 The API is reasonably complete with what you can do in the Protocol
10 Buffers API.
75d2714 @krestenkrab Minor cleanups; add README
authored
11
731c34f @krestenkrab Updates to readme.
authored
12 RiakClient riak = new RiakClient("127.0.0.1", 8087);
75d2714 @krestenkrab Minor cleanups; add README
authored
13 byte[] data = new byte[] { 1, 2, 3, 4 };
14 RiakObject ro = new RiakObject("Bucket", "Key",
15 ByteString.copyFrom(data));
16 riak.store(ro);
17
2f0b22e @krestenkrab Update readme.
authored
18 Some of the API uses `com.google.protobuf.ByteString` which represents
19 a chunk of (uninterpreted) bytes. Much of the API supports both
20 `java.lang.String` and `ByteString`; sometimes you have to navigate
21 from one kind of String to another using
22 e.g. `ByteString.copyFromUtf8(String)` and
23 `ByteString.toStringUtf8()`; but this lets you have keys that are
24 arbitrary byte sequences in stead of just strings. You'll find that
25 class in `lib/protobuf-java-2.3.0.jar` which also needs to be in your
26 class path for the library to work.
75d2714 @krestenkrab Minor cleanups; add README
authored
27
28 Here is a complete program to list the entire contents of a riak
29 store.
30
31 RiakClient client = new RiakClient("127.0.0.1");
32 ByteString[] buckets = client.listBuckets();
33 for (ByteString bucket : buckets) {
34 System.out.println("=bucket "+bucket.toStringUtf8());
35 KeySource keys = client.listKeys(bucket);
36 for (ByteString key : keys) {
37 System.out.println("==key "+key.toStringUtf8());
38 RiakObject[] ros = client.fetch(bucket, key);
39 for (RiakObject ro : ros) {
40 System.out.println("==="+ro.toString());
41 }
42 }
43 keys.close();
44 }
45
46 The methods `RiakClient.listKeys` and `RiakClient.mapReduce` return
2f0b22e @krestenkrab Update readme.
authored
47 streaming handlers that should be closed explicitly (unless you run
48 it to completion in which case it closes itself).
75d2714 @krestenkrab Minor cleanups; add README
authored
49
50 If you set a clientID `RiakClient.setClientID`; that client ID is used
51 for all connections coming from the same client. `RiakClient` is
52 "thread safe" so you can use it from several threads at the same time.
53
54 ### Bulk Insert
55
56 The method `RiakClient.store(RiakObject[], RequestMeta)` allows
57 efficient bulk insertion (connection request/responses are handled
58 asynchroneously underneath the covers). To run even faster, you can
59 choose to run this in several threads (resulting in multiple connections).
60
61
62 ## License / Copyright
63
731c34f @krestenkrab Updates to readme.
authored
64 If you use this library, please be so kind to credit Trifork
65 approproately in your system documentation.
66
67
75d2714 @krestenkrab Minor cleanups; add README
authored
68 A Java Client API for Riak based on the Protocol Buffers API
69
70 Copyright (C) 2010 Trifork A/S
71
72 Licensed under the Apache License, Version 2.0 (the "License");
73 you may not use this file except in compliance with the License.
74 You may obtain a copy of the License at
75
76 http://www.apache.org/licenses/LICENSE-2.0
77
78 Unless required by applicable law or agreed to in writing, software
79 distributed under the License is distributed on an "AS IS" BASIS,
80 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
81 See the License for the specific language governing permissions and
82 limitations under the License.
Something went wrong with that request. Please try again.