The Lattice SDK Java library provides convenient access to the Lattice API from Java.
API reference documentation is available here.
This repository is tested against Java 1.8 or later.
Add the dependency in your build.gradle
file:
dependencies {
implementation 'com.anduril:lattice-sdk'
}
Add the dependency in your pom.xml
file:
<dependency>
<groupId>com.anduril</groupId>
<artifactId>lattice-sdk</artifactId>
<version>2.1.1</version>
</dependency>
For support with this library please reach out to your Anduril representative.
Instantiate and use the client with the following:
package com.example.usage;
import com.anduril.Lattice;
import com.anduril.resources.entities.requests.EntityEventRequest;
public class Example {
public static void main(String[] args) {
Lattice client = Lattice
.builder()
.token("<token>")
.build();
client.entities().longPollEntityEvents(
EntityEventRequest
.builder()
.sessionToken("sessionToken")
.build()
);
}
}
This SDK allows you to configure different environments for API requests.
import com.anduril.Lattice;
import com.anduril.core.Environment;
Lattice client = Lattice
.builder()
.environment(Environment.Default)
.build();
You can set a custom base URL when constructing the client.
import com.anduril.Lattice;
Lattice client = Lattice
.builder()
.url("https://example.com")
.build();
When the API returns a non-success status code (4xx or 5xx response), an API exception will be thrown.
import com.anduril.core.AndurilApiApiException;
try {
client.entities().longPollEntityEvents(...);
} catch (AndurilApiApiException e) {
// Do something with the API exception...
}
This SDK is built to work with any instance of OkHttpClient
. By default, if no client is provided, the SDK will construct one.
However, you can pass your own client like so:
import com.anduril.Lattice;
import okhttp3.OkHttpClient;
OkHttpClient customClient = ...;
Lattice client = Lattice
.builder()
.httpClient(customClient)
.build();
The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long as the request is deemed retryable and the number of retry attempts has not grown larger than the configured retry limit (default: 2).
A request is deemed retryable when any of the following HTTP status codes is returned:
Use the maxRetries
client option to configure this behavior.
import com.anduril.Lattice;
Lattice client = Lattice
.builder()
.maxRetries(1)
.build();
The SDK defaults to a 60 second timeout. You can configure this with a timeout option at the client or request level.
import com.anduril.Lattice;
import com.anduril.core.RequestOptions;
// Client level
Lattice client = Lattice
.builder()
.timeout(10)
.build();
// Request level
client.entities().longPollEntityEvents(
...,
RequestOptions
.builder()
.timeout(10)
.build()
);