Example usage for java.util.stream LongStream empty

List of usage examples for java.util.stream LongStream empty

Introduction

In this page you can find the example usage for java.util.stream LongStream empty.

Prototype

public static LongStream empty() 

Source Link

Document

Returns an empty sequential LongStream .

Usage

From source file:Main.java

public static void main(String[] args) {
    LongStream b = LongStream.empty();

    System.out.println(b.count());
}

From source file:Main.java

public static void main(String[] args) {
    LongStream b = LongStream.empty();
    PrimitiveIterator.OfLong o = b.iterator();
    while (o.hasNext()) {
        System.out.println(o.next());
    }//from ww w.j  a va  2 s  .c  o m
}

From source file:com.homeadvisor.kafdrop.service.CuratorKafkaMonitor.java

private Map<Integer, Long> getTopicPartitionSizes(TopicVO topic, long time) {
    try {/*ww w . java  2  s.  c o m*/
        PartitionOffsetRequestInfo requestInfo = new PartitionOffsetRequestInfo(time, 1);

        return threadPool.submit(() -> topic.getPartitions().parallelStream().filter(p -> p.getLeader() != null)
                .collect(Collectors.groupingBy(p -> p.getLeader().getId())) // Group partitions by leader broker id
                .entrySet().parallelStream().map(entry -> {
                    final Integer brokerId = entry.getKey();
                    final List<TopicPartitionVO> brokerPartitions = entry.getValue();
                    try {
                        // Get the size of the partitions for a topic from the leader.
                        final OffsetResponse offsetResponse = sendOffsetRequest(brokerId, topic, requestInfo,
                                brokerPartitions);

                        // Build a map of partitionId -> topic size from the response
                        return brokerPartitions.stream()
                                .collect(Collectors.toMap(TopicPartitionVO::getId, partition -> Optional
                                        .ofNullable(offsetResponse.offsets(topic.getName(), partition.getId()))
                                        .map(Arrays::stream).orElse(LongStream.empty()).findFirst()
                                        .orElse(-1L)));
                    } catch (Exception ex) {
                        LOG.error("Unable to get partition log size for topic {} partitions ({})",
                                topic.getName(), brokerPartitions.stream().map(TopicPartitionVO::getId)
                                        .map(String::valueOf).collect(Collectors.joining(",")),
                                ex);

                        // Map each partition to -1, indicating we got an error
                        return brokerPartitions.stream()
                                .collect(Collectors.toMap(TopicPartitionVO::getId, tp -> -1L));
                    }
                }).map(Map::entrySet).flatMap(Collection::stream)
                .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))).get();
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw Throwables.propagate(e);
    } catch (ExecutionException e) {
        throw Throwables.propagate(e.getCause());
    }
}