Esper engine configuration is entirely optional. Esper has a very small number of configuration parameters that can be used to simplify event pattern and EQL statements, and to tune the engine behavior to specific requirements. The Esper engine works out-of-the-box without configuration.
An instance of net.esper.client.Configuration represents all configuration parameters. The Configuration is used to build an (immutable) EPServiceProvider, which provides the administrative and runtime interfaces for an Esper engine instance.
You may obtain a Configuration instance by instantiating it directly and adding or setting values on it. The Configuration instance is then passed to EPServiceProviderManager to obtain a configured Esper engine.
Configuration configuration = new Configuration(); configuration.addEventMapping("PriceLimit", PriceLimit.class.getName()); configuration.addEventMapping("StockTick", StockTick.class.getName()); EPServiceProvider epService = EPServiceProviderManager.getProvider("MyEngine", configuration);
Note that Configuration is meant only as an initialization-time object. The Esper engine represented by a EPServiceProvider is immutable and does not retain any association back to the Configuration.
An alternative approach to configuration is to specify a configuration in an XML file.
The default name for the XML configuration file is esper.cfg.xml. Esper reads this file from the root of the CLASSPATH as an application resource via the configure method.
Configuration configuration = new Configuration(); configuration.configure();
The Configuration class can read the XML configuration file from other sources as well. The configure method accepts URL, File and String filename parameters.
Configuration configuration = new Configuration(); configuration.configure("myengine.esper.cfg.xml");
Here is an example configuration file. The schema for the configuration file can be found in the etc folder and is named esper-configuration-1-0.
<?xml version="1.0" encoding="UTF-8"?> <esper-configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="esper-configuration-1-0.xsd"> <event name="StockTick" class="net.esper.example.stockticker.event.StockTick"/> <event name="PriceLimit" class="net.esper.example.stockticker.event.PriceLimit"/> </esper-configuration>
This configuration item can be set to allows event pattern statements and EQL statements to use event names rather then the fully qualified Java class name.
every StockTick(symbol='IBM')" // via configuration equivalent to every net.esper.example.stockticker.event.StockTick(symbol='IBM')