Search in sources :

Example 1 with AverageCityPopulationCallable

use of tasks.AverageCityPopulationCallable in project microservices by pwillhan.

the class AverageCityPopulationCallableExample method main.

public static void main(String[] args) throws Exception {
    Config conf = new Config();
    MapConfig citiesConf = conf.getMapConfig("cities");
    citiesConf.addMapIndexConfig(new MapIndexConfig("country", false));
    HazelcastInstance hz = Hazelcast.newHazelcastInstance(conf);
    IMap<CityKey, City> cities = hz.getMap("cities");
    if (cities.isEmpty()) {
        cities.put(new CityKey("London", "GB"), new City("London", "GB", 7322403, 2001));
        cities.put(new CityKey("Southampton", "GB"), new City("Southampton", "GB", 226698, 2006));
        cities.put(new CityKey("Plymouth", "GB"), new City("Plymouth", "GB", 244037, 2004));
        cities.put(new CityKey("York", "GB"), new City("York", "GB", 195070, 2010));
        cities.put(new CityKey("Paris", "FR"), new City("Paris", "FR", 2268265, 2013));
    }
    ExecutorService exec = hz.getExecutorService("exec");
    Future<Integer> avgTask = exec.submit(new AverageCityPopulationCallable("GB"));
    Integer avgPop = avgTask.get();
    System.err.println("Average GB city population: " + avgPop);
}
Also used : AverageCityPopulationCallable(tasks.AverageCityPopulationCallable) MapIndexConfig(com.hazelcast.config.MapIndexConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapConfig(com.hazelcast.config.MapConfig) Config(com.hazelcast.config.Config) MapIndexConfig(com.hazelcast.config.MapIndexConfig) ExecutorService(java.util.concurrent.ExecutorService) MapConfig(com.hazelcast.config.MapConfig) City(data.City) CityKey(data.CityKey)

Aggregations

Config (com.hazelcast.config.Config)1 MapConfig (com.hazelcast.config.MapConfig)1 MapIndexConfig (com.hazelcast.config.MapIndexConfig)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 City (data.City)1 CityKey (data.CityKey)1 ExecutorService (java.util.concurrent.ExecutorService)1 AverageCityPopulationCallable (tasks.AverageCityPopulationCallable)1