com.espertech.esper.core
Class EPRuntimeImpl

java.lang.Object
  extended by com.espertech.esper.core.EPRuntimeImpl
All Implemented Interfaces:
EPRuntime, EPRuntimeEventSender, EPRuntimeSPI, InternalEventRouter, TimerCallback

public class EPRuntimeImpl
extends Object
implements EPRuntimeSPI, EPRuntimeEventSender, TimerCallback, InternalEventRouter

Implements runtime interface. Also accepts timer callbacks for synchronizing time events with regular events sent in.


Constructor Summary
EPRuntimeImpl(EPServicesContext services)
          Constructor.
 
Method Summary
 void addEmittedListener(EmittedListener listener, String channel)
          Register an object that listens for events emitted from the event stream processing runtime on the specified channel.
 void clearEmittedListeners()
          Deregister all emitted event listeners.
 void destroy()
          Destroy for destroying an engine instance: sets references to null and clears thread-locals
 void emit(Object object)
          Emit an event object to any registered EmittedListener instances listening to the default channel.
 void emit(Object object, String channel)
          Emit an event object to any registered EmittedListener instances on the specified channel.
 EPQueryResult executeQuery(String epl)
          Execute a free-form EPL dynamically, non-continuously, in a fire-and-forget fashion, against named windows.
 EventSender getEventSender(String eventTypeAlias)
          Returns a facility to process event objects that are of a known type.
 EventSender getEventSender(URI[] uri)
          For use with plug-in event representations, returns a facility to process event objects that are of one of a number of types that one or more of the registered plug-in event representation extensions can reflect upon and provide an event for.
 long getNumEventsEmitted()
          Number of events emitted over the lifetime of the event stream processing runtime, or since the last resetStats() call
 long getNumEventsReceived()
          Number of events received over the lifetime of the event stream processing runtime, or since the last resetStats() call
 Map<String,Object> getVariableValue(Set<String> variableNames)
          Returns current variable values for each of the variable names passed in, guaranteeing consistency in the face of concurrent updates to the variables.
 Object getVariableValue(String variableName)
          Returns the current variable value.
 Map<String,Object> getVariableValueAll()
          Returns current variable values for all variables, guaranteeing consistency in the face of concurrent updates to the variables.
 EPPreparedQuery prepareQuery(String epl)
          Prepare a non-continuous, fire-and-forget query for repeated execution.
 void processWrappedEvent(EventBean eventBean)
          Equivalent to the sendEvent method of EPRuntime, for use to process an known event.
 void resetStats()
          Reset number of events received and emitted
 void route(EventBean event, EPStatementHandle epStatementHandle)
          Route the event such that the event is processed as required.
 void route(Object event)
          Route the event object back to the event stream processing runtime for internal dispatching.
 void sendEvent(Map map, String eventTypeAlias)
          Send a map containing event property values to the event stream processing runtime.
 void sendEvent(Node document)
          Send an event represented by a DOM node to the event stream processing runtime.
 void sendEvent(Object event)
          Send an event represented by a plain Java object to the event stream processing runtime.
 void setUnmatchedListener(UnmatchedListener listener)
          Sets a listener to receive events that are unmatched by any statement.
 void setVariableValue(Map<String,Object> variableValues)
          Sets the value of multiple variables in one update, applying all or none of the changes to variable values in one atomic transaction.
 void setVariableValue(String variableName, Object variableValue)
          Sets the value of a single variable.
 void timerCallback()
          Invoked by the internal clocking service at regular intervals.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EPRuntimeImpl

public EPRuntimeImpl(EPServicesContext services)
Constructor.

Parameters:
services - - references to services
Method Detail

timerCallback

public void timerCallback()
Description copied from interface: TimerCallback
Invoked by the internal clocking service at regular intervals.

Specified by:
timerCallback in interface TimerCallback

sendEvent

public void sendEvent(Object event)
               throws EPException
Description copied from interface: EPRuntime
Send an event represented by a plain Java object to the event stream processing runtime.

Use the route method for sending events into the runtime from within UpdateListener code.

Specified by:
sendEvent in interface EPRuntime
Parameters:
event - is the event to sent to the runtime
Throws:
EPException - is thrown when the processing of the event lead to an error

sendEvent

public void sendEvent(Node document)
               throws EPException
Description copied from interface: EPRuntime
Send an event represented by a DOM node to the event stream processing runtime.

Use the route method for sending events into the runtime from within UpdateListener code.

Specified by:
sendEvent in interface EPRuntime
Parameters:
document - is the DOM node as an event
Throws:
EPException - is thrown when the processing of the event lead to an error

sendEvent

public void sendEvent(Map map,
                      String eventTypeAlias)
               throws EPException
Description copied from interface: EPRuntime
Send a map containing event property values to the event stream processing runtime.

Use the route method for sending events into the runtime from within UpdateListener code.

Specified by:
sendEvent in interface EPRuntime
Parameters:
map - - map that contains event property values. Keys are expected to be of type String while values can be of any type. Keys and values should match those declared via Configuration for the given eventTypeAlias.
eventTypeAlias - - the alias for the (property name, property type) information for this map
Throws:
EPException - - when the processing of the event leads to an error

getNumEventsReceived

public long getNumEventsReceived()
Description copied from interface: EPRuntime
Number of events received over the lifetime of the event stream processing runtime, or since the last resetStats() call

Specified by:
getNumEventsReceived in interface EPRuntime
Returns:
number of events received

getNumEventsEmitted

public long getNumEventsEmitted()
Description copied from interface: EPRuntime
Number of events emitted over the lifetime of the event stream processing runtime, or since the last resetStats() call

Specified by:
getNumEventsEmitted in interface EPRuntime
Returns:
number of events emitted

resetStats

public void resetStats()
Description copied from interface: EPRuntime
Reset number of events received and emitted

Specified by:
resetStats in interface EPRuntime

route

public void route(Object event)
Description copied from interface: EPRuntime
Route the event object back to the event stream processing runtime for internal dispatching. The route event is processed just like it was sent to the runtime, that is any active expressions seeking that event receive it. The routed event has priority over other events sent to the runtime. In a single-threaded application the routed event is processed before the next event is sent to the runtime through the EPRuntime.sendEvent method.

Specified by:
route in interface EPRuntime
Parameters:
event - to route internally for processing by the event stream processing runtime

route

public void route(EventBean event,
                  EPStatementHandle epStatementHandle)
Description copied from interface: InternalEventRouter
Route the event such that the event is processed as required.

Specified by:
route in interface InternalEventRouter
Parameters:
event - to route
epStatementHandle - provides statement resources

emit

public void emit(Object object)
Description copied from interface: EPRuntime
Emit an event object to any registered EmittedListener instances listening to the default channel.

Specified by:
emit in interface EPRuntime
Parameters:
object - to be emitted to the default channel

emit

public void emit(Object object,
                 String channel)
Description copied from interface: EPRuntime
Emit an event object to any registered EmittedListener instances on the specified channel. Event listeners listening to all channels as well as those listening to the specific channel are called. Supplying a null value in the channel has the same result as the emit(Object object) method.

Specified by:
emit in interface EPRuntime
Parameters:
object - to be emitted
channel - channel to emit the object to, or null if emitting to the default channel

addEmittedListener

public void addEmittedListener(EmittedListener listener,
                               String channel)
Description copied from interface: EPRuntime
Register an object that listens for events emitted from the event stream processing runtime on the specified channel. A null value can be supplied for the channel in which case the emit listener will be invoked for events emitted an any channel.

Specified by:
addEmittedListener in interface EPRuntime
Parameters:
listener - called when an event is emitted by the runtime.
channel - is the channel to add the listener to, a null value can be used to listen to events emitted on all channels

clearEmittedListeners

public void clearEmittedListeners()
Description copied from interface: EPRuntime
Deregister all emitted event listeners.

Specified by:
clearEmittedListeners in interface EPRuntime

processWrappedEvent

public void processWrappedEvent(EventBean eventBean)
Description copied from interface: EPRuntimeEventSender
Equivalent to the sendEvent method of EPRuntime, for use to process an known event.

Specified by:
processWrappedEvent in interface EPRuntimeEventSender
Parameters:
eventBean - is the event object wrapped by an event bean providing the event metadata

destroy

public void destroy()
Destroy for destroying an engine instance: sets references to null and clears thread-locals


setUnmatchedListener

public void setUnmatchedListener(UnmatchedListener listener)
Description copied from interface: EPRuntime
Sets a listener to receive events that are unmatched by any statement.

Events that can be unmatched are all events that are send into a runtime via one of the sendEvent methods, or that have been generated via insert-into clause.

For an event to be unmatched by any statement, the event must not match any statement's event stream filter criteria (a where-clause is NOT a filter criteria for a stream, as below).

Note: In the following statement a MyEvent event does always match this statement's event stream filter criteria, regardless of the value of the 'quantity' property.

select * from MyEvent where quantity > 5

In the following statement only a MyEvent event with a 'quantity' property value of 5 or less does not match this statement's event stream filter criteria:
select * from MyEvent(quantity > 5)

For patterns, if no pattern sub-expression is active for such event, the event is also unmatched.

Specified by:
setUnmatchedListener in interface EPRuntime
Parameters:
listener - is the listener to receive notification of unmatched events, or null to unregister a previously registered listener

setVariableValue

public void setVariableValue(String variableName,
                             Object variableValue)
                      throws EPException
Description copied from interface: EPRuntime
Sets the value of a single variable.

Specified by:
setVariableValue in interface EPRuntime
Parameters:
variableName - is the name of the variable to change the value of
variableValue - is the new value of the variable, with null an allowed value
Throws:
VariableValueException - if the value does not match variable type or cannot be safely coerced to the variable type
VariableNotFoundException - if the variable name has not been declared
EPException

setVariableValue

public void setVariableValue(Map<String,Object> variableValues)
                      throws EPException
Description copied from interface: EPRuntime
Sets the value of multiple variables in one update, applying all or none of the changes to variable values in one atomic transaction.

Specified by:
setVariableValue in interface EPRuntime
Parameters:
variableValues - is the map of variable name and variable value, with null an allowed value
Throws:
VariableValueException - if any value does not match variable type or cannot be safely coerced to the variable type
VariableNotFoundException - if any of the variable names has not been declared
EPException

getVariableValue

public Object getVariableValue(String variableName)
                        throws EPException
Description copied from interface: EPRuntime
Returns the current variable value. A null value is a valid value for a variable.

Specified by:
getVariableValue in interface EPRuntime
Parameters:
variableName - is the name of the variable to return the value for
Returns:
current variable value
Throws:
VariableNotFoundException - if a variable by that name has not been declared
EPException

getVariableValue

public Map<String,Object> getVariableValue(Set<String> variableNames)
                                    throws EPException
Description copied from interface: EPRuntime
Returns current variable values for each of the variable names passed in, guaranteeing consistency in the face of concurrent updates to the variables.

Specified by:
getVariableValue in interface EPRuntime
Parameters:
variableNames - is a set of variable names for which to return values
Returns:
map of variable name and variable value
Throws:
VariableNotFoundException - if any of the variable names has not been declared
EPException

getVariableValueAll

public Map<String,Object> getVariableValueAll()
                                       throws EPException
Description copied from interface: EPRuntime
Returns current variable values for all variables, guaranteeing consistency in the face of concurrent updates to the variables.

Specified by:
getVariableValueAll in interface EPRuntime
Returns:
map of variable name and variable value
Throws:
EPException

executeQuery

public EPQueryResult executeQuery(String epl)
Description copied from interface: EPRuntimeSPI
Execute a free-form EPL dynamically, non-continuously, in a fire-and-forget fashion, against named windows.

Specified by:
executeQuery in interface EPRuntimeSPI
Parameters:
epl - is the EPL to execute
Returns:
query result

prepareQuery

public EPPreparedQuery prepareQuery(String epl)
Description copied from interface: EPRuntimeSPI
Prepare a non-continuous, fire-and-forget query for repeated execution.

Specified by:
prepareQuery in interface EPRuntimeSPI
Parameters:
epl - to prepare
Returns:
proxy to execute upon, that also provides the event type of the returned results

getEventSender

public EventSender getEventSender(String eventTypeAlias)
Description copied from interface: EPRuntime
Returns a facility to process event objects that are of a known type.

Given an event type alias this method returns a sender that allows to send in event objects of that type. The event objects send in via the event sender are expected to match the event type, thus the event sender does not inspect the event object other then perform basic checking.

For events backed by a Java class (JavaBean events), the sender ensures that the object send in matches in class, or implements or extends the class underlying the event type for the given event type alias name.

For events backed by a java.util.Map (Map events), the sender does not perform any checking other then checking that the event object indeed implements Map.

For events backed by a org.w3c.Node (XML DOM events), the sender checks that the root element name indeed does match the root element name for the event type alias.

Specified by:
getEventSender in interface EPRuntime
Parameters:
eventTypeAlias - is the name of the event type
Returns:
sender for fast-access processing of event objects of known type (and content)

getEventSender

public EventSender getEventSender(URI[] uri)
                           throws EventTypeException
Description copied from interface: EPRuntime
For use with plug-in event representations, returns a facility to process event objects that are of one of a number of types that one or more of the registered plug-in event representation extensions can reflect upon and provide an event for.

Specified by:
getEventSender in interface EPRuntime
Parameters:
uri - is the URIs that specify which plug-in event representations may process an event object.

URIs do not need to match event representation URIs exactly, a child (hierarchical) match is enough for an event representation to participate.

The order of URIs is relevant as each event representation's factory is asked in turn to process the event, until the first factory processes the event.

Returns:
sender for processing of event objects of one of the plug-in event representations
Throws:
EventTypeException - thrown to indicate that the URI list was invalid

© 2007 EsperTech Inc.
All rights reserved.
Visit us at espertech.com