public class EsperEngine extends Object implements stream.service.Service, stream.Configurable
Abstract class that provides basic Esper support for the Streams platform.
Esper is a Complex Event Processing (CEP) platform for the Java and .Net languages. Esper must be started from custom code. It provides parallel execution but no distribution. The Streams stream processing platform allows to distribute Esper over different processes.
This package on the other hand allows integrating Complex Event Processing with a high level query language, i.e., the Event Processing Language (EPL). The EPL is a SQL-like language. For further information please refer to the Esper documentation.
The configuration of an Esper engine as a Streams Service follows the
Xml configuration of the Streams platform. The configuration may include an
Esper config. EPL statements are added as Streams Processor in
the form of Streams-Esper Query objects.
Example Configuration:
<Service class="streams.esper.EsperEngineService" id="esperEngine01">
<config>
<esper-configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.espertech.com/schema/esper"
xsi:schemaLocation="http://www.espertech.com/schema/esper http://www.espertech.com/schema/esper/esper-configuration-2.0.xsd">
<engine-settings>
<defaults>
<threading>
<internal-timer msec-resolution="1" enabled="false" />
</threading>
</defaults>
</engine-settings>
<event-type name="LeftEvent">
<java-util-map start-timestamp-property-name="timestamp">
<map-property name="timestamp" class="long" />
<map-property name="id" class="string" />
</java-util-map>
</event-type>
<event-type name="RightEvent">
<java-util-map start-timestamp-property-name="timestamp">
<map-property name="timestamp" class="long" />
<map-property name="id" class="string" />
</java-util-map>
</event-type>
</esper-configuration>
</config>
</Service>
Query| Modifier and Type | Field and Description |
|---|---|
protected com.espertech.esper.client.EPRuntime |
_epRuntime |
protected com.espertech.esper.client.EPServiceProvider |
_epService |
static String |
DEFAULT_ID |
static long |
DEFAULT_TIME_TOLERANCE
The default amount of difference in time up to which events are still
considered for processing.
|
static String |
ESPER_CONFIG_LOCAL_NAME |
static String |
ESPER_NS |
static String |
ESPER_STATEMENT_LOCAL_NAME |
static String |
EVENT_TYPE_KEY |
| Constructor and Description |
|---|
EsperEngine()
Initializes the following components:
an empty Esper
Configuration,
the maps for types with a start and an end timsestamp,
the list of Esper statements ( Query ), and
the default values for the time tolerance. |
| Modifier and Type | Method and Description |
|---|---|
void |
addEsperQuery(EsperStatementBean epStatement)
Add a statement to the Esper engine.
|
void |
addEsperQuery(EsperStatementBean epStatement,
boolean increaseShutdownCount) |
protected static Class<?> |
classForName(String name) |
void |
configure(Element document)
Parses the <configuration> ...
|
com.espertech.esper.client.Configuration |
getConfiguration()
Getter for the Esper configuration.
|
static EsperEngine |
getEsperEngine(String id)
If the engine with the specified id has not yet been registered but the
id is equal to the default id, then a new engine with the default id will
be created and registered and finally returned.
|
String |
getId()
Getter for the id of this service.
|
long |
getInitialTime()
Getter for the initial timestamp of the Esper engine.
|
String |
getProviderUri()
Getter for the URI of the Esper engine.
|
long |
getTimeTolerance()
Getter for the maximal difference a timestamp may reach into the past.
|
String[] |
getTypes()
Getter for the map of Esper types to Java classes via a streams
attribute.
|
void |
init()
Initializes the Esper service.
|
void |
notifyShutdown()
|
void |
reset()
Calls
EPServiceProvider.destroy(). |
void |
setId(String id) |
void |
setInitialTime(long initialTime) |
void |
setProviderUri(String providerUri) |
void |
setTimeTolerance(long timeTolerance) |
void |
setTypes(String[] types) |
boolean |
write(stream.Data input)
Decodes a
Data input item and sends it to the Esper
engine. |
public static final String ESPER_CONFIG_LOCAL_NAME
public static final String ESPER_NS
public static final String EVENT_TYPE_KEY
public static final String ESPER_STATEMENT_LOCAL_NAME
public static final String DEFAULT_ID
public static final long DEFAULT_TIME_TOLERANCE
protected transient com.espertech.esper.client.EPServiceProvider _epService
protected transient com.espertech.esper.client.EPRuntime _epRuntime
public EsperEngine()
Initializes the following components:
Configuration,Query ), andpublic static EsperEngine getEsperEngine(String id)
If the engine with the specified id has not yet been registered but the id is equal to the default id, then a new engine with the default id will be created and registered and finally returned.
id - protected static Class<?> classForName(String name)
name - public void init()
throws Exception
Exceptionpublic boolean write(stream.Data input)
throws Exception
Decodes a Data input item and sends it to the Esper
engine. The result of the processing in the Esper engine is output to
Sink objects asynchonously.
The method determines the type of input by evaluating the field
"@stream". It sends a copy of the input Data item to the
Esper EPRuntime.It removes the values for "@stream" and
"@stream:id" from the copied Data item before sending it.
The the input Data item defines a start time, then this
start time is compared with the current data time. If the time stamp of
the input Data item is larger than the current data time,
then the current data time is set to the input Data item's
start time. A time event with the Data item's start time
is sent to the Esper EPRuntime.
Exceptionpublic void reset()
throws Exception
Calls EPServiceProvider.destroy().
public void configure(Element document)
Parses the <configuration> ... </configuration> tag if provided.
The configuration may contain the following elements:
configure in interface stream.Configurablepublic void addEsperQuery(EsperStatementBean epStatement, boolean increaseShutdownCount)
public void addEsperQuery(EsperStatementBean epStatement)
Add a statement to the Esper engine.
Note that subscribers are added only for those statements that declare an output sink.
epStatement - public com.espertech.esper.client.Configuration getConfiguration()
@Parameter(defaultValue="",
description="The URI of the Esper Runtime.",
required=false)
public String getProviderUri()
public void setProviderUri(String providerUri)
public long getInitialTime()
@Parameter(required=false) public void setInitialTime(long initialTime)
public long getTimeTolerance()
Getter for the maximal difference a timestamp may reach into the past.
@Parameter(name="timeTolerance",
defaultValue="100000",
description="The tolerance how many msecs a time event may reach into the past to be still processed.",
required=false)
public void setTimeTolerance(long timeTolerance)
public void setId(String id)
public String getId()
Getter for the id of this service.
public String[] getTypes()
Getter for the map of Esper types to Java classes via a streams attribute.
@Parameter(required=false,
description="Simple key:value mapping of properties")
public void setTypes(String[] types)
types - Copyright © 2013-2017 University of Dortmund. All Rights Reserved.