private int getShardAndIncrement() { return (int) (counter.getAndIncrement() % queue.getNumShards()); }
private Optional<TargetedSweeperLock> tryToAcquireLockForNextShardAndStrategy() { return IntStream.range(0, queue.getNumShards()) .map(ignore -> getShardAndIncrement()) .mapToObj(shard -> TargetedSweeperLock.tryAcquire(shard, sweepStrategy, timeLock)) .filter(Optional::isPresent) .map(Optional::get) .findFirst(); }
private int getShardAndIncrement() { return (int) (counter.getAndIncrement() % queue.getNumShards()); }
private Optional<TargetedSweeperLock> tryToAcquireLockForNextShardAndStrategy() { return IntStream.range(0, queue.getNumShards()) .map(ignore -> getShardAndIncrement()) .mapToObj(shard -> TargetedSweeperLock.tryAcquire(shard, sweepStrategy, timeLock)) .filter(Optional::isPresent) .map(Optional::get) .findFirst(); }