use of reactor.retry.Jitter in project hedera-mirror-node by hashgraph.
the class NetworkServiceImpl method getNodes.
@Override
public Flux<AddressBookEntry> getNodes(AddressBookFilter filter) {
var fileId = filter.getFileId();
if (!VALID_FILE_IDS.contains(fileId)) {
throw new IllegalArgumentException(INVALID_FILE_ID);
}
long timestamp = addressBookRepository.findLatestTimestamp(fileId.getId()).orElseThrow(() -> new EntityNotFoundException(fileId));
var context = new AddressBookContext(timestamp);
return Flux.defer(() -> page(context)).repeatWhen(Repeat.onlyIf(c -> !context.isComplete()).randomBackoff(addressBookProperties.getMinPageDelay(), addressBookProperties.getMaxPageDelay()).jitter(Jitter.random()).withBackoffScheduler(Schedulers.parallel())).take(filter.getLimit() > 0 ? filter.getLimit() : Long.MAX_VALUE).name("addressBook").metrics().doOnNext(context::onNext).doOnSubscribe(s -> log.info("Querying for address book: {}", filter)).doOnComplete(() -> log.info("Retrieved {} nodes from the address book", context.getCount()));
}
Aggregations