This chapters outlines the examples that come with Esper in the eg/src folder of the distribution. The code for examples can be found in the net.esper.example packages.
JUnit tests exist for the example code. The JUnit test source code for the examples can be found in the eg/test folder. To build and run the examples and their JUnit tests, use the Maven 2 goal test. The JUnit test source code can also be helpful in understanding the example and in the use of Esper APIs.
The StockTicker example comes from the stock trading domain. The example creates event patterns to filter stock tick events based on price and symbol. When a stock tick event is encountered that falls outside the lower or upper price limit, the example simply displays that stock tick event. The price range itself is dynamically created and changed. This is accomplished by an event patterns that searches for another event class, the price limit event.
The classes net.esper.example.stockticker.event.StockTick and PriceLimit represent our events. The event patterns are created by the class net.esper.example.stockticker.monitor.StockTickerMonitor.
Summary:
Good example to learn the API and get started with event patterns
Dynamically creates and removes event patterns based on price limit events received
Simple, highly-performant filter expressions for event properties in the stock tick event such as symbol and price
In the MatchMaker example every mobile user has an X and Y location, a set of properties (gender, hair color, age range) and a set of preferences (one for each property) to match. The task of the event patterns created by this example is to detect mobile users that are within proximity given a certain range, and for which the properties match preferences.
The event class representing mobile users is net.esper.example.matchmaker.event.MobileUserBean. The net.esper.example.matchmaker.monitor.MatchMakingMonitor class contains the patterns for detecing matches.
Summary:
Dynamically creates and removes event patterns based on mobile user events received
Uses range matching for X and Y properties of mobile user events
This examples develops some code for measuring quality-of-service levels such as for a service-level agreement (SLA). A SLA is a contract between 2 parties that defines service constraints such as maximum latency for service operations or error rates.
The example measures and monitors operation latency and error counts per customer and operation. When one of our operations oversteps these constraints, we want to be alerted right away. Additionally, we would like to have some monitoring in place that checks the health of our service and provides some information on how the operations are used.
Some of the constraints we need to check are:
That the latency (time to finish) of some of the operations is always less then X seconds.
That the latency average is always less then Y seconds over Z operation invocations.
The net.esper.example.qos_sla.events.OperationMeasurement event class with it's latency and status properties is the main event used for the SLA analysis. The other event LatencyLimit serves to set latency limits on the fly.
The net.esper.example.qos_sla.monitor.AverageLatencyMonitor creates an EQL statement that computes latency statistics per customer and operation for the last 100 events. The DynaLatencySpikeMonitor uses an event pattern to listen to spikes in latency with dynamically set limits.The ErrorRateMonitor uses the timer 'at' operator in an event pattern that wakes up periodically and polls the error rate within the last 10 minutes. The ServiceHealthMonitor simply alerts when 3 errors occur, and the SpikeAndErrorMonitor alerts when a fixed latency is overstepped or an error status is reported.
Summary:
This example combines event patterns with EQL statements for event stream analysis.
Shows the use of the timer 'at' operator and followed-by operator -> in event patterns
Outlines basic EQL statements
Shows how to pull data out of EQL statements rather then subscribing to events a statement publishes
The Linear Road example is a very incomplete implementation of the Stream Data Management Benchmark [3] by Standford University.
Linear Road simulates a toll system for the motor vehicle expressways of a large metropolitan area. The main event in this example is a car location report which the class net.esper.example.linearroad.CarLocEvent represents. Currently the event stream joins are performed by JUnit test classes in the eg/test folder. See the net.esper.example.linearroad.TestAccidentNotify and the TestCarSegmentCount classes. Please consider this a work in progress.
Summary:
Shows more complex joins between event streams.