Search in sources :

Example 6 with City

use of data.City in project microservices by pwillhan.

the class MapReduceCountryCityDensity method main.

public static void main(String[] args) throws Exception {
    Config conf = new Config();
    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", 8416535, 1572));
        cities.put(new CityKey("Southampton", "GB"), new City("Southampton", "GB", 242100, 51));
        cities.put(new CityKey("Chicago", "US"), new City("Chicago", "US", 2718782, 606));
        cities.put(new CityKey("Washington DC", "US"), new City("Washington DC", "US", 658893, 177));
        cities.put(new CityKey("Seattle", "US"), new City("Seattle", "US", 652405, 370));
    }
    JobTracker jobTracker = hz.getJobTracker("default");
    KeyValueSource<CityKey, City> sourceData = KeyValueSource.fromMap(cities);
    Job<CityKey, City> job = jobTracker.newJob(sourceData);
    JobCompletableFuture<Map<String, Integer>> future = job.mapper(new CountryCityDensityMapper()).reducer(new IntegerAvgReducerFactory()).submit();
    Map<String, Integer> result = future.get();
    System.err.println(result);
}
Also used : Config(com.hazelcast.config.Config) JobTracker(com.hazelcast.mapreduce.JobTracker) IntegerAvgReducerFactory(mapreduce.reducer.IntegerAvgReducerFactory) City(data.City) HazelcastInstance(com.hazelcast.core.HazelcastInstance) CityKey(data.CityKey) IMap(com.hazelcast.core.IMap) Map(java.util.Map) CountryCityDensityMapper(mapreduce.mapper.CountryCityDensityMapper)

Example 7 with City

use of data.City in project microservices by pwillhan.

the class MapReduceCountryCityPopulation method main.

public static void main(String[] args) throws Exception {
    Config conf = new Config();
    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", 8416535, 1572));
        cities.put(new CityKey("Southampton", "GB"), new City("Southampton", "GB", 242100, 51));
        cities.put(new CityKey("Chicago", "US"), new City("Chicago", "US", 2718782, 606));
        cities.put(new CityKey("Washington DC", "US"), new City("Washington DC", "US", 658893, 177));
        cities.put(new CityKey("Seattle", "US"), new City("Seattle", "US", 652405, 370));
    }
    JobTracker jobTracker = hz.getJobTracker("default");
    KeyValueSource<CityKey, City> sourceData = KeyValueSource.fromMap(cities);
    Job<CityKey, City> job = jobTracker.newJob(sourceData);
    JobCompletableFuture<Map<String, Integer>> future = job.mapper(new CountryCityPopulationMapper()).combiner(new IntegerSumCombinerFactory()).reducer(new IntegerSumReducerFactory()).submit();
    Map<String, Integer> result = future.get();
    System.err.println(result);
}
Also used : Config(com.hazelcast.config.Config) IntegerSumCombinerFactory(mapreduce.combiner.IntegerSumCombinerFactory) City(data.City) HazelcastInstance(com.hazelcast.core.HazelcastInstance) IntegerSumReducerFactory(mapreduce.reducer.IntegerSumReducerFactory) CountryCityPopulationMapper(mapreduce.mapper.CountryCityPopulationMapper) CityKey(data.CityKey) IMap(com.hazelcast.core.IMap) Map(java.util.Map)

Example 8 with City

use of data.City in project microservices by pwillhan.

the class MapSearchPredicateExample method main.

public static void main(String[] args) {
    HazelcastInstance hz = Hazelcast.newHazelcastInstance();
    IMap<String, City> capitals = hz.getMap("capitals");
    capitals.addIndex("name", false);
    capitals.addIndex("population", true);
    capitals.put("GB", new City("London", "GB", 8174100));
    capitals.put("FR", new City("Paris", "FR", 2268265));
    capitals.put("US", new City("Washington DC", "US", 601723));
    capitals.put("AU", new City("Canberra", "AU", 354644));
    EntryObject c = new PredicateBuilder().getEntryObject();
    Predicate londonPredicate = c.get("name").equal("London");
    Collection<City> possibleLondons = capitals.values(londonPredicate);
    System.err.println(possibleLondons);
    Predicate largeCityPredicate = Predicates.greaterThan("population", 1000000);
    Collection<City> largeCities = capitals.values(largeCityPredicate);
    System.err.println(largeCities);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) EntryObject(com.hazelcast.query.EntryObject) PredicateBuilder(com.hazelcast.query.PredicateBuilder) City(data.City) Predicate(com.hazelcast.query.Predicate)

Example 9 with City

use of data.City in project microservices by pwillhan.

the class HibernateExample method main.

public static void main(String[] args) {
    SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
    Session session = sessionFactory.openSession();
    Transaction tx = session.beginTransaction();
    try {
        City london = new City("London", "GB", 8174100);
        session.save(london);
    } catch (Exception e) {
        tx.rollback();
    } finally {
        tx.commit();
    }
    session.close();
    session = sessionFactory.openSession();
    System.err.println(session.get(City.class, "London"));
}
Also used : SessionFactory(org.hibernate.SessionFactory) Configuration(org.hibernate.cfg.Configuration) Transaction(org.hibernate.Transaction) City(data.City) Session(org.hibernate.Session)

Example 10 with City

use of data.City in project microservices by pwillhan.

the class MapSearchExample method main.

public static void main(String[] args) {
    HazelcastInstance hz = Hazelcast.newHazelcastInstance();
    IMap<String, City> capitals = hz.getMap("capitals");
    capitals.addIndex("name", false);
    capitals.addIndex("population", true);
    capitals.put("GB", new City("London", "GB", 8174100));
    capitals.put("FR", new City("Paris", "FR", 2268265));
    capitals.put("US", new City("Washington DC", "US", 601723));
    capitals.put("AU", new City("Canberra", "AU", 354644));
    Collection<City> possibleLondons = capitals.values(new SqlPredicate("name = 'London'"));
    System.err.println(possibleLondons);
    Collection<City> largeCities = capitals.values(new SqlPredicate("population > 1000000"));
    System.err.println(largeCities);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) SqlPredicate(com.hazelcast.query.SqlPredicate) City(data.City)

Aggregations

City (data.City)12 HazelcastInstance (com.hazelcast.core.HazelcastInstance)9 CityKey (data.CityKey)6 Config (com.hazelcast.config.Config)5 Predicate (com.hazelcast.query.Predicate)4 IMap (com.hazelcast.core.IMap)3 Map (java.util.Map)3 MapConfig (com.hazelcast.config.MapConfig)2 MapIndexConfig (com.hazelcast.config.MapIndexConfig)2 Hazelcast (com.hazelcast.core.Hazelcast)1 JobTracker (com.hazelcast.mapreduce.JobTracker)1 Aggregations (com.hazelcast.mapreduce.aggregation.Aggregations)1 PropertyExtractor (com.hazelcast.mapreduce.aggregation.PropertyExtractor)1 Supplier (com.hazelcast.mapreduce.aggregation.Supplier)1 EntryObject (com.hazelcast.query.EntryObject)1 PagingPredicate (com.hazelcast.query.PagingPredicate)1 PredicateBuilder (com.hazelcast.query.PredicateBuilder)1 SqlPredicate (com.hazelcast.query.SqlPredicate)1 ExecutorService (java.util.concurrent.ExecutorService)1 IntegerSumCombinerFactory (mapreduce.combiner.IntegerSumCombinerFactory)1