In Microsoft graph sdk 6.4.0 using new PageIterator - how do you iterate page item results with multiple threads?

13 Views Asked by At

There is a new PageIterator in 6.4.0 version of Microsoft Graph Java SDK.

https://github.com/microsoftgraph/msgraph-sdk-java/blob/dev/docs/upgrade-to-v6.md#pageiterator

The Microsoft Graph Java SDK example for iterating through items looks like this:

PageIterator<ListItem, ListItemCollectionResponse> pageIterator = new PageIterator.Builder<ListItem, ListItemCollectionResponse>()
    .client(graphClient)
    // The first page of the collection is passed to the collectionPage method
    .collectionPage(response)
    // CollectionPageFactory is called to create a new collection page from the nextLink
    .collectionPageFactory(ListItemCollectionResponse::createFromDiscriminatorValue)
    // ProcessPageItemCallback is called for each item in the collection
    .processPageItemCallback(li -> {
        String driveItemId = li.getDriveItem().getId();
        InputStream is = graphClient.drives().byDriveId(siteDriveId)
                .items()
                .byDriveItemId(driveItemId)
                .content()
                .get();
        try {
            byte[] bytes = IOUtils.toByteArray(is);
            LOGGER.info("Read {} bytes", bytes.length);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return true;
    }).build();
pageIterator.iterate();

Is there a way to iterate over results in a multi-threaded fashion?

0

There are 0 best solutions below