0

The minimal working example below presents some (simplified) processing where:

  • each event is processed individually (no windowing),
  • each event belongs to a certain group,
  • each event updates a group state, which then is used to generate some output value.
public class RollingExample {
    public static void main(String[] args) {
        JetInstance jet = Jet.newJetInstance();

        Pipeline p = Pipeline.create();
        p.readFrom(TestSources.itemStream(10))
                .withoutTimestamps()
                .groupingKey(event -> event.sequence() % 10) //simulates 10 groups
                .rollingAggregate(AggregateOperation
                        .withCreate(DoubleAccumulator::new) //group state simulated by a single double value
                        .andAccumulate((DoubleAccumulator acc, SimpleEvent event) -> acc.accumulate(event.sequence())) //update group state with given event
                        .andCombine(DoubleAccumulator::combine)
                        .andDeduct(DoubleAccumulator::deduct)
                        .andExportFinish(DoubleAccumulator::export))
                .map(x -> x.getKey() + " -> " + x.getValue()) //map group state to some output value
                .writeTo(Sinks.logger());

        jet.newJob(p).join();
    }
}

Given the above example, is it possible to query individual group states from outside, e.g. using Hazelcast Client? By "query" I mean programmatically getting current value of an accumulator for given group.

user3078523
  • 1,520
  • 18
  • 27
  • The aggregation state is local to a processor, so you can't query it from the outside. You may consider using `mapUsingService` instead and use an IMap to store the aggregated state. – Marko Topolnik Feb 25 '21 at 10:28
  • Thank you for the comment. Could you please add a code example - maybe as an answer? – user3078523 Feb 25 '21 at 10:59

0 Answers0