Search in sources :

Example 1 with Jitter

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()));
}
Also used : Validated(org.springframework.validation.annotation.Validated) EntityId(com.hedera.mirror.common.domain.entity.EntityId) Collection(java.util.Collection) RequiredArgsConstructor(lombok.RequiredArgsConstructor) Set(java.util.Set) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Jitter(reactor.retry.Jitter) AtomicReference(java.util.concurrent.atomic.AtomicReference) Repeat(reactor.retry.Repeat) AddressBookEntry(com.hedera.mirror.common.domain.addressbook.AddressBookEntry) EntityType(com.hedera.mirror.common.domain.entity.EntityType) AddressBookEntryRepository(com.hedera.mirror.grpc.repository.AddressBookEntryRepository) Value(lombok.Value) EntityNotFoundException(com.hedera.mirror.grpc.exception.EntityNotFoundException) AtomicLong(java.util.concurrent.atomic.AtomicLong) Flux(reactor.core.publisher.Flux) Log4j2(lombok.extern.log4j.Log4j2) AddressBookRepository(com.hedera.mirror.grpc.repository.AddressBookRepository) Schedulers(reactor.core.scheduler.Schedulers) Named(javax.inject.Named) AddressBookFilter(com.hedera.mirror.grpc.domain.AddressBookFilter) EntityNotFoundException(com.hedera.mirror.grpc.exception.EntityNotFoundException)

Aggregations

AddressBookEntry (com.hedera.mirror.common.domain.addressbook.AddressBookEntry)1 EntityId (com.hedera.mirror.common.domain.entity.EntityId)1 EntityType (com.hedera.mirror.common.domain.entity.EntityType)1 AddressBookFilter (com.hedera.mirror.grpc.domain.AddressBookFilter)1 EntityNotFoundException (com.hedera.mirror.grpc.exception.EntityNotFoundException)1 AddressBookEntryRepository (com.hedera.mirror.grpc.repository.AddressBookEntryRepository)1 AddressBookRepository (com.hedera.mirror.grpc.repository.AddressBookRepository)1 Collection (java.util.Collection)1 Set (java.util.Set)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Named (javax.inject.Named)1 RequiredArgsConstructor (lombok.RequiredArgsConstructor)1 Value (lombok.Value)1 Log4j2 (lombok.extern.log4j.Log4j2)1 Validated (org.springframework.validation.annotation.Validated)1 Flux (reactor.core.publisher.Flux)1 Schedulers (reactor.core.scheduler.Schedulers)1 Jitter (reactor.retry.Jitter)1