Java
Java SDK provides additional features to control how requests are executed. This guide covers how to set request timeouts, configure retries for failed requests, and make asynchronous calls.Setting request timeouts for Oso Cloud
You may configure your client to abort requests to Oso Cloud that exceed given timeouts. When a timeout is exceeded, the SDK will throw acom.osohq.oso_cloud.OsoTimeoutException
.
Setting a default timeout for all requests
UsewithDefaultTimeoutMilliseconds
to set a timeout that applies to all requests.
Setting separate timeouts for read and write requests
- Use
withReadTimeoutMilliseconds
to set a timeout that applies only to requests that read data from Oso Cloud; such asauthorize
andget
. - Use
withWriteTimeoutMilliseconds
to set a timeout that applies only to requests that write data to Oso Cloud; such asinsert
anddelete
.
withDefaultTimeoutMilliseconds
, that default timeout will
NOT be applied to requests for which a more specific timeout was set.
Retrying failed requests
The Oso Cloud client automatically retries requests that failed for any of the following reasons:- HTTP 429 (Too Many Requests)
- HTTP 5xx (Server Errors)
- Connection errors
- Timeouts
Making non-blocking CompletableFuture
requests with Oso.Async
By default, the Oso Cloud client is blocking: calling a function will block the execution of the current thread until the function returns.
In versions 1.4 and above, you can use the Oso.Async
API to make non-blocking requests that run on an
Executor
.
Oso.Async
supports all the same functions as Oso
, but each function returns a
CompletableFuture
,
which you can get()
or cancel()
as necessary.
Cancelling the futures returned by these functions will abort any in-progress HTTP requests.
You can obtain an Oso.Async
instance by calling withAsyncExecutor(Executor)
on an Oso
instance:
await
ing a CompletableFuture
returned by Oso.Async
will cooperatively propagate cancellations.
When a parent coroutine is cancelled, any in-progress HTTP requests in the await
ed future will be aborted.
Note that while calls to Oso.Async
will not block the current thread, the underlying Runnable
HTTP requests submitted to the Executor
are fundamentally blocking and can block threads on your Executor
when they run.
You may wish to use an Executor
with its own thread pool for Oso.Async
, to avoid thread starvation in other parts of your application.