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);
}
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);
}
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);
}
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"));
}
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);
}
Aggregations