Package io.oxia.client.api
package io.oxia.client.api
The public API for interacting with Oxia.
Getting started
Every client is created throughOxiaClientBuilder. The builder lets
you produce either a blocking or non-blocking client; both speak to the same Oxia cluster and
expose the same operations. Pick whichever fits your code style — if in doubt, start with the
synchronous one.
Synchronous client
try (SyncOxiaClient client = OxiaClientBuilder.create("localhost:6648")
.namespace("my-namespace")
.syncClient()) {
PutResult put = client.put("my-key", "my-value".getBytes(StandardCharsets.UTF_8));
GetResult got = client.get("my-key");
if (got != null) {
String value = new String(got.value(), StandardCharsets.UTF_8);
}
boolean wasPresent = client.delete("my-key");
}
Asynchronous client
AsyncOxiaClient client = OxiaClientBuilder.create("localhost:6648")
.namespace("my-namespace")
.asyncClient()
.join();
client.put("my-key", "my-value".getBytes(StandardCharsets.UTF_8))
.thenCompose(put -> client.get("my-key"))
.thenAccept(got -> System.out.println(new String(got.value(), StandardCharsets.UTF_8)));
Conditional puts and optimistic concurrency
Operations can be made conditional by passing options.
Conditional writes that fail produce an UnexpectedVersionIdException.
// Only insert if the key does not already exist.
client.put("my-key", value, Set.of(PutOption.IfRecordDoesNotExist));
// Read-modify-write with version check.
GetResult current = client.get("my-key");
client.put("my-key", newValue, Set.of(PutOption.IfVersionIdEquals(current.version().versionId())));
Listing and scanning ranges
List<String> keys = client.list("a", "z");
try (CloseableIterable<GetResult> scan = client.rangeScan("a", "z")) {
for (GetResult r : scan) {
// process r
}
}
Watching for changes
client.notifications(n -> {
switch (n) {
case Notification.KeyCreated c -> { /* ... *\/ }
case Notification.KeyModified m -> { /* ... *\/ }
case Notification.KeyDeleted d -> { /* ... *\/ }
case Notification.KeyRangeDelete r -> { /* ... *\/ }
}
});
Package layout
io.oxia.client.api— client interfaces, builder, and result/notification types.io.oxia.client.api.options— operation options (PutOption,GetOption, ...) passed as aSetto each call.io.oxia.client.api.exceptions— checked exceptions raised by client operations.
- See Also:
-
ClassDescriptionNon-blocking client for the Oxia service.Represents an interface for implementing authentication mechanisms.An
Iterablethat holds resources which must be released by callingCloseableIterable.close().The result of a successful get / range-scan operation.A notification from an Oxia server indicating a change to a record associated with a key.A record associated with the key has been created.The record associated with the key has been deleted.The record associated with the key has been modified (updated).The record associated with the key range has been deleted.Entry point for creating an Oxia client.The result of a successful put operation.Callback used byAsyncOxiaClient.rangeScan(String, String, RangeScanConsumer)to deliver records, errors, and the completion signal for a streaming range scan.Blocking client for the Oxia service.Metadata associated with an Oxia record.