This project demonstrates Apache Geode's Lucene indexing capabilities for geospatial data, using spatial queries over indexed locations.
The project consists of three parts:
- Base Library: Contains all common classes.
- Simulator: Uses a KML file of active truck lanes in California to randomly move vehicles around the state.
- Web Server: Hosts a mapping application.
The focus of this project is on showcasing Apache Geode application development rather than creating a complex application. However, it can easily be extended to correlate tracking information with "beacon" information, providing a 360-degree view of the beacon.
This 360-degree profile enrichment is accomplished using "cache listeners," "async event listeners," or "cache writer." The key is to stage the data with the identifier for the beacon, allowing for high throughput with in-memory performance. Geode enhances this by co-locating regions, ensuring beacons operate on the servers holding the data.
The choice of technique depends on the use case:
- CacheListener - Synchronous, triggered after the data has been persisted in the context of a "put".
- CacheWriter - Synchronous, triggered before the data has been persisted in the context of a "put". A CacheWriter can also prohibit a data item from being actually stored. This could be treated as a data validation.
- AsyncCacheListener - Asynchronous, triggered after the data has been stored and operates outside the context of a "put".
Follow these steps to install Apache Geode:
- Install Geode: Download and unpack the Apache Geode distribution.
Before starting Geode, build the libraries for our domain objects in the asset tracker library by running the gradlew bootJar command, then copy runtime dependencies:
gradlew bootJargradlew tracker-lib:copyLuceneLibsThis copies Geode’s Lucene/Spatial runtime jars into tracker-lib/build/lucene-libs so the server classpath can pick them up when starting Geode.
To simplify running Geode, batch scripts are provided for local setup and configuration. For Windows, use the following command:
cd <project>\scripts
startGeode.batThis command starts Geode with one locator and two servers, then deploys the necessary classes for Geode Lucene indexing and searching. The deployed project is located in the library.
The script also creates the index and a region for the demo.
The simulator injects the current location of assets we are tracking. It simulates movement around California using trucking lanes data. The development setting configures 100k assets moving around.
cd <project>
gradlew tracker-simulator:bootRunThe web application uses OpenLayers for mapping capabilities and provides a REST interface to query beacons in a given area. The code for querying beacons can be found here.
cd <project>
gradlew tracker-web-app:bootRunOpen your browser and navigate to http://localhost:8080. Use Ctrl+Drag (or Command+Drag on Mac) to draw boxes over California to query the beacons. Start with smaller boxes to gauge your browser's performance, as no result limiting was implemented to keep the code simple.
To kill all Java processes, use the following command:
taskkill /f /im java.execurl "http://localhost:8080/query?minLng=-117.1208548486265&minLat=32.83976867526056&maxLng=-117.11506127715433&maxLat=32.843590641384694" [{"lat":32.84179,"lng":-117.11903,"uid":"95299"},{"lat":32.841824,"lng":-117.11555,"uid":"60688"},{"lat":32.84179,"lng":-117.11868,"uid":"83857"},{"lat":32.841812,"lng":-117.11744,"uid":"74060"},{"lat":32.84179,"lng":-117.11903,"uid":"98491"},{"lat":32.841812,"lng":-117.11744,"uid":"73182"},{"lat":32.841824,"lng":-117.11555,"uid":"58739"},{"lat":32.84182,"lng":-117.11689,"uid":"66694"},{"lat":32.84179,"lng":-117.11903,"uid":"92442"},{"lat":32.84179,"lng":-117.11903,"uid":"92325"},{"lat":32.841866,"lng":-117.11413,"uid":"52801"},{"lat":32.84182,"lng":-117.11689,"uid":"69312"},{"lat":32.841866,"lng":-117.11413,"uid":"53019"},{"lat":32.841812,"lng":-117.11744,"uid":"81841"},{"lat":32.841824,"lng":-117.11555,"uid":"57492"},{"lat":32.84179,"lng":-117.11903,"uid":"96609"},{"lat":32.841824,"lng":-117.11555,"uid":"56277"},{"lat":32.84179,"lng":-117.11903,"uid":"95898"},{"lat":32.841812,"lng":-117.11744,"uid":"75009"}]