Skip to content

Getting Started

Ali edited this page Nov 27, 2013 · 3 revisions

To be able to use MapAggregator first you have to configure it in Hazelcast Config

final ServiceConfig serviceConfig = new ServiceConfig();
serviceConfig.setEnabled(true);
serviceConfig.setClassName(MapAggregatorService.class.getName());
serviceConfig.setName(MapAggregatorService.SERVICE_NAME);
config.getServicesConfig().addServiceConfig(serviceConfig);

Now we can say Hazelcast give me a MapAggregator like this

MapAggregator mapAggregator = instance.getDistributedObject(MapAggregatorService.SERVICE_NAME, "students");

Now we have a mapAggregator which will perform aggregations on the map named 'students' Here is a built-in aggregator example, we want to get the note average of students who belongs to class B

final Predicate predicate = Predicates.equal("className", "B");
final Number average = mapAggregator.aggregate(predicate, new NumberAverageAggregator("note"));

Here is the Student POJO

public class Student implements Serializable {
    public String name;
    public String className;
    public int note
}

Don't forget to checkout tests :

CompositeAggregator -> https://github.com/gurbuzali/hazel-map-aggregator/blob/master/src/test/java/co/gurbuz/hazel/mapaggregator/MainTest.java#L137

DistinctValuesAggregator -> https://github.com/gurbuzali/hazel-map-aggregator/blob/master/src/test/java/co/gurbuz/hazel/mapaggregator/MainTest.java#L184

GroupByAggregator -> https://github.com/gurbuzali/hazel-map-aggregator/blob/master/src/test/java/co/gurbuz/hazel/mapaggregator/MainTest.java#L294

Clone this wiki locally