public class RiakClient extends Object
List addresses = new LinkedList();
addresses.add("192.168.1.1");
addresses.add("192.168.1.2");
addresses.add("192.168.1.3");
RiakClient client = RiakClient.newClient(addresses);
For more complex configurations, you can instantiate a RiakCluster from the
core packages and supply it to the RiakClient constructor.
Once you have a client, commands from the com.basho.riak.client.api.commands.*
packages are built then executed by the client:
Namespace ns = new Namespace("default","my_bucket");
Location loc = new Location(ns, "my_key");
FetchValue fv = new FetchValue.Builder(loc).build();
FetchValue.Response response = client.execute(fv);
RiakObject obj = response.getValue(RiakObject.class);
| Constructor and Description |
|---|
RiakClient(RiakCluster cluster)
Create a new RiakClient to perform operations on the given cluster.
|
| Modifier and Type | Method and Description |
|---|---|
<T,S> T |
execute(RiakCommand<T,S> command)
Execute a command against Riak
|
<T,S> RiakFuture<T,S> |
executeAsync(RiakCommand<T,S> command)
Execute a command asynchronously against Riak.
|
static RiakClient |
newClient()
Static factory method to create a new client instance.
|
static RiakClient |
newClient(int port,
List<String> remoteAddresses)
Static factory method to create a new client instance.
|
static RiakClient |
newClient(List<String> remoteAddresses)
Static factory method to create a new client instance.
|
Future<Boolean> |
shutdown()
Shutdown the client and the underlying cluster.
|
public RiakClient(RiakCluster cluster)
The RiakClient provides a user API on top of the client core. Once instantiated, commands are submitted to it for execution on Riak.
RiakClient client = RiakClient.newClient();
Namespace ns = new Namespace("default","my_bucket");
Location loc = new Location(ns, "my_key");
FetchValue fv = new FetchValue.Builder(loc).build();
FetchValue.Response response = client.execute(fv);
RiakObject obj = response.getValue(RiakObject.class);
client.shutdown();
cluster - the started RiakCluster to use.public static RiakClient newClient() throws UnknownHostException
UnknownHostExceptionpublic static RiakClient newClient(List<String> remoteAddresses) throws UnknownHostException
remoteAddresses - a list of IP addresses or hostnamesUnknownHostException - if a supplied hostname cannot be resolved.public static RiakClient newClient(int port, List<String> remoteAddresses) throws UnknownHostException
remoteAddresses - a list of IP addresses or hostnamesport - the port to connect to on the supplied hosts.UnknownHostException - if a supplied hostname cannot be resolved.public <T,S> T execute(RiakCommand<T,S> command) throws ExecutionException, InterruptedException
T - The command's return typecommand - The commandExecutionExceptionInterruptedExceptionpublic <T,S> RiakFuture<T,S> executeAsync(RiakCommand<T,S> command)
command - The command to execute.Copyright © 2014. All rights reserved.