reactor.core.publisher.GroupedFlux Java Examples

The following examples show how to use reactor.core.publisher.GroupedFlux. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BrokerSupplier.java    From data-highway with Apache License 2.0 5 votes vote down vote up
private LogDir logDir(
    Map<String, Disk> diskByLogDir,
    GroupedFlux<String, Tuple3<String, String, PartitionReplica>> byLogDir,
    List<Topic> ts) {
  Disk disk = diskByLogDir.getOrDefault(byLogDir.key(), new Disk(0L, 0L));
  return new LogDir(byLogDir.key(), disk.getFree(), disk.getTotal(), ts);
}
 
Example #2
Source File: R071_GroupBy.java    From reactor-workshop with GNU General Public License v3.0 5 votes vote down vote up
/**
 * TODO Count number of words of each length.
 * Use {@link Flux#groupBy(Function)}
 */
@Test
public void countAndNumberOfWords() throws Exception {
    final Flux<GroupedFlux<Integer, String>> wordsByLength = LoremIpsum
            .wordStream()
            .groupBy(String::length);

    //when
    final Flux<Tuple2<Integer, Long>> lenToCount = null; // TODO

    //then
    final Set<Tuple2<Integer, Long>> pairs = lenToCount
            .collect(toSet())
            .block();

    assertThat(pairs)
            .containsOnly(
                    of(1, 1L),
                    of(2, 8L),
                    of(3, 15L),
                    of(4, 24L),
                    of(5, 25L),
                    of(6, 14L),
                    of(7, 10L),
                    of(8, 6L),
                    of(9, 9L),
                    of(11, 3L),
                    of(12, 2L)
            );
}
 
Example #3
Source File: EmployeeParallelStreamServiceImpl.java    From Spring-5.0-Cookbook with MIT License 5 votes vote down vote up
@Override
public Flux<GroupedFlux<Integer, Integer>> parallelGrpAvg() {
	Function<Employee, Integer> ages = (emp) ->{
		System.out.println("flatMap thread: " + Thread.currentThread().getName());
		return emp.getAge();
	};
	
	Flux<GroupedFlux<Integer, Integer>> parallelEmpFlux = Flux.fromIterable(employeeDaoImpl.getEmployees())
        .delaySubscription(Duration.of(500L, ChronoUnit.MILLIS))
        .parallel(8) 
        .runOn (Schedulers.parallel())
        .map(ages)
        .groups();
       return parallelEmpFlux;
}
 
Example #4
Source File: EmployeeTransformDataStreamImpl.java    From Spring-5.0-Cookbook with MIT License 5 votes vote down vote up
@Override
public Flux<GroupedFlux<String, String>> groupNames() {
	Function<Employee, String> names = (emp) -> emp.getFirstName().toLowerCase();
	Flux<GroupedFlux<String, String>> grpsNames = Flux.fromIterable(employeeDaoImpl.getEmployees())
			.map(names)
			.groupBy(key -> key.charAt(0)+"");
	return grpsNames;
}
 
Example #5
Source File: FluxWindowConsistencyTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Test
public void groupByComplete() throws Exception {
	Flux<GroupedFlux<Integer, Integer>> windows = source.groupBy(i -> i % 2);
	subscribeGroups(windows);
	generateAndComplete(0, 6);
	verifyMainComplete(Arrays.asList(0, 2, 4), Arrays.asList(1, 3, 5));
}
 
Example #6
Source File: FluxWindowConsistencyTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Test
public void groupByMainCancel() throws Exception {
	Flux<GroupedFlux<Integer, Integer>> windows = source.groupBy(i -> i % 2);
	subscribeGroups(windows);
	generateWithCancel(0, 5, 1);
	verifyMainCancel(false, Arrays.asList(0, 2, 4), Arrays.asList(1, 3, 5));
}
 
Example #7
Source File: FluxWindowConsistencyTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Test
public void groupByMainCancelNoNewWindow() throws Exception {
	Flux<GroupedFlux<Integer, Integer>> windows = source.groupBy(i -> i % 2);
	subscribeGroups(windows);
	generateWithCancel(0, 1, 1);
	verifyMainCancelNoNewWindow(0, Arrays.asList(0));
}
 
Example #8
Source File: FluxWindowConsistencyTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Test
public void groupByInnerCancel() throws Exception {
	Flux<GroupedFlux<Integer, Integer>> windows = source.groupBy(i -> i % 2);
	subscribeGroups(windows);
	generateWithCancel(0, 9, 1);
	verifyInnerCancel(0, i -> i < 6, Arrays.asList(0, 2, 4), Arrays.asList(1, 3, 5));
}
 
Example #9
Source File: CassandraMessageIdMapper.java    From james-project with Apache License 2.0 5 votes vote down vote up
private Flux<MailboxMessage> keepMessageIfMailboxExists(GroupedFlux<MailboxId, MailboxMessage> groupedFlux) {
    CassandraId cassandraId = (CassandraId) groupedFlux.key();
    return mailboxDAO.retrieveMailbox(cassandraId)
        .flatMapMany(any -> groupedFlux)
        .switchIfEmpty(groupedFlux.map(message -> {
            LOGGER.info("Mailbox {} have been deleted but message {} is still attached to it.",
                cassandraId.serialize(),
                message.getMessageId().serialize());
            return message;
        }).then(Mono.empty()));
}
 
Example #10
Source File: EvaluationStrategyImpl.java    From semagrow with Apache License 2.0 5 votes vote down vote up
public Flux<BindingSet> evaluateReactorInternal(Group expr, BindingSet bindings)
        throws QueryEvaluationException
{
    Set<String> groupByBindings = expr.getGroupBindingNames();

    Flux<BindingSet> s = evaluateReactorInternal(expr.getArg(), bindings);

    Flux<GroupedFlux<BindingSet, BindingSet>> g = s.groupBy((b) -> bindingSetOps.project(groupByBindings, b, bindings));

    //return g.flatMap((gs) -> Streams.just(gs.key()));
    return g.flatMap((gs) -> aggregate(gs, expr, bindings));
}
 
Example #11
Source File: SensorAverageProcessorApplication.java    From spring-cloud-stream-samples with Apache License 2.0 4 votes vote down vote up
private Mono<Average> calculateAverage(GroupedFlux<Integer, Sensor> group) {
	return group
			.reduce(new Accumulator(0, 0),
					(a, d) -> new Accumulator(a.getCount() + 1, a.getTotalValue() + d.getTemperature()))
			.map(accumulator -> new Average(group.key(), (accumulator.getTotalValue()) / accumulator.getCount()));
}
 
Example #12
Source File: SensorAverageProcessorApplication.java    From spring-cloud-stream-samples with Apache License 2.0 4 votes vote down vote up
private Mono<Average> calculateAverage(GroupedFlux<Integer, Sensor> group) {
	return group
			.reduce(new Accumulator(0, 0),
					(a, d) -> new Accumulator(a.getCount() + 1, a.getTotalValue() + d.getTemperature()))
			.map(accumulator -> new Average(group.key(), (accumulator.getTotalValue()) / accumulator.getCount()));
}
 
Example #13
Source File: FluxWindowConsistencyTest.java    From reactor-core with Apache License 2.0 4 votes vote down vote up
private void subscribeGroups(Flux<GroupedFlux<Integer, Integer>> groups) {
	subscribe(groups.map(m -> m));
}
 
Example #14
Source File: DeletedMessageVaultHook.java    From james-project with Apache License 2.0 4 votes vote down vote up
private Flux<DeletedMessageMailboxContext> addOwnerToMetadata(GroupedFlux<MailboxId, MetadataWithMailboxId> groupedFlux) {
    return retrieveMailboxUser(groupedFlux.key())
        .flatMapMany(owner -> groupedFlux.map(metadata ->
            new DeletedMessageMailboxContext(metadata.getMessageMetaData().getMessageId(), owner, ImmutableList.of(metadata.getMailboxId()))));
}
 
Example #15
Source File: EmployeeParallelStreamService.java    From Spring-5.0-Cookbook with MIT License votes vote down vote up
public Flux<GroupedFlux<Integer, Integer>> parallelGrpAvg(); 
Example #16
Source File: EmployeeTransformDataStream.java    From Spring-5.0-Cookbook with MIT License votes vote down vote up
public Flux<GroupedFlux<String, String>> groupNames();