kontent-ai / kontent-ai/java-packages
Add synchronous support to the DeliveryClient
- Dominant language
- Java
- Stars
- 17
- Forks
- 27
- PR merge metrics
- No merged PRs in 30d
Description
### Motivation
After updating a large application to the latest version of the Java SDK, all calls to the DeliveryClient had to wrapped in a synchronous wrapper. It would be helpful if there were a built-in way to call the DeliveryClient synchronously rather than introducing additional code to the project.
### Proposed solution
Add alternate methods for working with the DeliveryClient synchronously, for example:
`deliveryClient.getItems().toSync()` or `deliveryClient.getItemsSynchronously()`
### Additional context
Here is the wrapper class that I had to write:
```
public class DeliveryClientHelper {
public static T toSync(CompletionStage completionStage) {
try {
return completionStage.toCompletableFuture().get();
} catch (InterruptedException e) {
log.error("Error converting completion stage: {}", e.getMessage());
} catch (ExecutionException e) {
log.error("Error converting completion stage: {}", e.getMessage());
}
return null;
}
}
```
An example call using the wrapper:
```
List blogHomepages = DeliveryClientHelper.toSync(deliveryClient.getItems(AgencySiteBlogLanding.class));
```
An ideal way to use the DeliveryClient
```
List blogHomepages = deliveryClient.getItems(AgencySiteBlogLanding.class).toSync();
```
Contributor guide
Research direction
Start by reading the DeliveryClient methods and the CompletionStage-based return values described in the issue, then compare them with the provided DeliveryClientHelper wrapper. Define how synchronous alternatives should expose results and failures, and consider the example calls as the completion criteria.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100