private static StormTopology advancedPrimitives(FeederBatchSpout spout) throws IOException {
TridentTopology topology = new TridentTopology();
topology
.newStream("aggregation", spout)
.groupBy(new Fields("city"))
.chainedAgg()
.aggregate(new Count(), new Fields("count"))
.aggregate(new Fields("age"), new Sum(), new Fields("age_sum"))
.chainEnd()
.each(new Fields("age_sum", "count"), new DivideAsDouble(), new Fields("mean_age"))
.each(new Fields("city", "mean_age"), new Print())
;
topology
.newStream("further",spout)
.groupBy(new Fields("city"))
.persistentAggregate(new MemoryMapState.Factory(), new Count(), new Fields("count"))
.newValuesStream()
.each(new Fields("city", "count"), new Print());
return topology.build();
}