Facing a weird issue while fetching data from inventory using java sdk using the code :
final var collection = inventoryApi.getManagedObjectsByFilter(filter);
collection.get(2000).allPages().forEach(managedObject → {
// some code
});
Please let me know if anyone else ever faced such issue and the way to fix this.
Error logs:
java.lang.IllegalStateException: Client instance has been closed. at org.glassfish.jersey.internal.guava.Preconditions.checkState(Preconditions.java:169) at org.glassfish.jersey.client.JerseyClient.checkNotClosed(JerseyClient.java:257) at org.glassfish.jersey.client.JerseyClient.target(JerseyClient.java:272) at com.cumulocity.sdk.client.CumulocityHttpClient.target(CumulocityHttpClient.java:33) at com.cumulocity.sdk.client.CumulocityHttpClient.target(CumulocityHttpClient.java:19) at com.cumulocity.sdk.client.RestConnector.getClientResponse(RestConnector.java:130) at com.cumulocity.sdk.client.RestConnector.get(RestConnector.java:109) at com.cumulocity.sdk.client.PagedCollectionResourceImpl.getCollection(PagedCollectionResourceImpl.java:87) at com.cumulocity.sdk.client.PagedCollectionResourceImpl.getNextPage(PagedCollectionResourceImpl.java:100) at com.cumulocity.sdk.client.PagedCollectionIterable.hasNext(PagedCollectionIterable.java:46) at java.base/java.lang.Iterable.forEach(Iterable.java:74)
I meant, can you try your code without all pages. Just for the first 2000 managed objects.
I don´t know java source code, but maybe it works internally with pages. That could be a problem with many objects. For each page request it starts with page 1. then it iterates over the managed objects until it found the requested page. At this moment he starts delivering the next 2000 manged objects. That can run into a timeout from the database. It tooks too long.
The fleet size doesn’t matter. The only thing that is different with 2000 page size is that you have less requests and your responses might be very big and take very long to retrieve. Having smaller page size is in most cases more efficient as it reduces the response size drastically & even scales better.
Just try the default page size and give us feedback if this resolves your issue. If not I guess you need to debug and find potential managed objects that causing timeouts.