Issue while fetching inventory data using cumulocity java sdk

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)

Haven’t faced this issue but I would assume two things

  1. Are you using any proxy in between your client + C8Y?
  2. Why get(2000)? This could take very long and might run into client timeouts. Stick with the default page-size get() or try a smaller number.
  1. No proxy in between.
  2. this code needs to run for my entire fleet (around 400000 devices). So I am using 2000 as chunk size

Hi,

does your code work for first 2000 objects, without allPages?

greets

Helmut

No, I have allPages in my code :
collection.get(2000).allPages().forEach(managedObject → {

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.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.