Obtaining a KVStore Handle

To acccess the store for any reason, you must first obtain a KVStore handle, using the KVStoreFactory.getStore() method.

When you get a KVStore handle, provide a KVStoreConfig object to the handle. The configuration object identifies important properties about the store that you are accessing. This section describes the KVStoreConfig class. Minimally, use this class to identify the following information:

  • The store name. The name you provide must be identical to the name used when you installed the store.

  • The network contact information for one or more helper hosts. Such contact information consists of the network name and port information for hosts currently belonging to the store. Identify multiple hosts using an array of strings, from one element to several. We recommend using multiple hosts, since any host can be down temporarily, and other hosts are then useful.

In addition to the KVStoreConfig class object, you can also provide a PasswordCredentials class object to KVStoreFactory.getStore(). Do this if you are using a store configured to require authentication, which is recommended. See Using the Authentication APIs for more information.

For a store that does not require authentication, get a store handle like this:

package kvstore.basicExample;

import oracle.kv.KVStore;
import oracle.kv.KVStoreConfig;
import oracle.kv.KVStoreFactory;

...

String[] hhosts = {"n1.example.org:5088", "n2.example.org:4129"};
KVStoreConfig kconfig = new KVStoreConfig("exampleStore", hhosts);
KVStore kvstore = KVStoreFactory.getStore(kconfig); 

Using the KVStoreConfig Class

Use the KVStoreConfig class to describe properties about a KVStore handle. Most of the properties are optional, and those that are required are provided when you construct a class instance.

The properties that you can provide using KVStoreConfig are as follows:

  • Consistency

    Consistency is a property describing how likely it is that a record read from a replica node is identical to the same record stored on a master node. For more information, see Consistency Guarantees.

  • Durability

    Durability is a property describing how likely it is that a write operation performed on the master node will not be lost if the master node is lost or is shut down abnormally. For more information, see Durability Guarantees.

  • Helper Hosts

    Helper hosts are hostname and port pairs that identify how to contact helper nodes within the store. Use an array of strings to identify multiple helper hosts . Typically, you will obtain these hostname and port pairs from the store's deployer or administrator. For example:

    String[] hhosts = {"n1.example.org:3333", "n2.example.org:3333"};
  • Request Timeout

    Configures the amount of time the KVStore handle will wait for an operation to complete before it times out.

  • Store name

    Identifies the name of the store.

  • Password credentials and optionally a reauthentication handler

    See the next section on authentication.