com.espertech.esper.core.service
Class StatementLifecycleSvcImpl

java.lang.Object
  extended by com.espertech.esper.core.service.StatementLifecycleSvcImpl
All Implemented Interfaces:
StatementLifecycleSvc

public class StatementLifecycleSvcImpl
extends java.lang.Object
implements StatementLifecycleSvc

Provides statement lifecycle services.


Nested Class Summary
static class StatementLifecycleSvcImpl.EPStatementDesc
          Statement information.
 
Field Summary
protected  EPServicesContext services
          Services context for statement lifecycle management.
protected  java.util.Map<java.lang.String,StatementLifecycleSvcImpl.EPStatementDesc> stmtIdToDescMap
          Maps of statement id to descriptor.
protected  java.util.Map<java.lang.String,EPStatement> stmtNameToStmtMap
          Map of statement name to statement.
 
Constructor Summary
StatementLifecycleSvcImpl(EPServiceProvider epServiceProvider, EPServicesContext services)
          Ctor.
 
Method Summary
 void addObserver(StatementLifecycleObserver observer)
          Add an observer to be called back when statement-state or listener/subscriber changes are registered.
protected static StatementSpecCompiled compile(StatementSpecRaw spec, java.lang.String eplStatement, StatementContext statementContext, boolean isSubquery, boolean isOnDemandQuery, java.lang.annotation.Annotation[] annotations, java.util.List<ExprSubselectNode> subselectNodes, java.util.List<ExprDeclaredNode> declaredNodes, EPServicesContext servicesContext)
          Compiles a statement returning the compile (verified, non-serializable) form of a statement.
static SelectClauseSpecCompiled compileSelectAllowSubselect(SelectClauseSpecRaw spec)
          Compile a select clause allowing subselects.
 EPStatement createAndStart(StatementSpecRaw statementSpec, java.lang.String expression, boolean isPattern, java.lang.String optStatementName, java.lang.Object userObject, EPIsolationUnitServices isolationUnitServices, java.lang.String statementId, EPStatementObjectModel optionalModel)
          Create and start the statement.
protected  StatementLifecycleSvcImpl.EPStatementDesc createStopped(StatementSpecRaw statementSpec, java.lang.annotation.Annotation[] annotations, java.lang.String expression, boolean isPattern, java.lang.String statementName, boolean nameProvided, java.lang.String statementId, java.util.Map<java.lang.String,java.lang.Object> optAdditionalContext, java.lang.Object statementUserObject, EPIsolationUnitServices isolationUnitServices, boolean isFailed, EPStatementObjectModel optionalModel)
          Create stopped statement.
protected  StatementLifecycleSvcImpl.EPStatementDesc createStoppedAssignName(StatementSpecRaw statementSpec, java.lang.String expression, boolean isPattern, java.lang.String optStatementName, java.lang.String statementId, java.util.Map<java.lang.String,java.lang.Object> optAdditionalContext, java.lang.Object userObject, EPIsolationUnitServices isolationUnitServices, EPStatementObjectModel optionalModel)
          Creates and starts statement.
 void destroy()
          Destroy the service.
 void destroy(java.lang.String statementId)
          Destroy statement by statement id.
 void destroyAllStatements()
          Destroys all started statements.
 void dispatchStatementLifecycleEvent(StatementLifecycleEvent theEvent)
          Dispatch event to observers.
 EPStatementSPI getStatementById(java.lang.String id)
          Returns the statement given a statement id.
 EPStatement getStatementByName(java.lang.String name)
          Returns the statement by the given name, or null if no such statement exists.
 java.lang.String getStatementNameById(java.lang.String id)
           
 java.lang.String[] getStatementNames()
          Returns an array of statement names.
 StatementSpecCompiled getStatementSpec(java.lang.String statementId)
           
 java.util.Map<java.lang.String,EPStatement> getStmtNameToStmt()
           
 void init()
          Initialized the service before use.
 void removeObserver(StatementLifecycleObserver observer)
          Remove an observer to be called back when statement-state or listener/subscriber changes are registered.
 void start(java.lang.String statementId)
          Start statement by statement id.
 void start(java.lang.String statementId, StatementLifecycleSvcImpl.EPStatementDesc desc, boolean isNewStatement, boolean isRecoveringStatement, boolean isResilient)
          Start the given statement.
 void startAllStatements()
          Starts all stopped statements.
 void stop(java.lang.String statementId)
          Stop statement by statement id.
 void stopAllStatements()
          Stops all started statements.
 void updatedListeners(EPStatement statement, EPStatementListenerSet listeners, boolean isRecovery)
          Statements indicate that listeners have been added through this method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

services

protected final EPServicesContext services
Services context for statement lifecycle management.


stmtIdToDescMap

protected final java.util.Map<java.lang.String,StatementLifecycleSvcImpl.EPStatementDesc> stmtIdToDescMap
Maps of statement id to descriptor.


stmtNameToStmtMap

protected final java.util.Map<java.lang.String,EPStatement> stmtNameToStmtMap
Map of statement name to statement.

Constructor Detail

StatementLifecycleSvcImpl

public StatementLifecycleSvcImpl(EPServiceProvider epServiceProvider,
                                 EPServicesContext services)
Ctor.

Parameters:
epServiceProvider - is the engine instance to hand to statement-aware listeners
services - is engine services
Method Detail

addObserver

public void addObserver(StatementLifecycleObserver observer)
Description copied from interface: StatementLifecycleSvc
Add an observer to be called back when statement-state or listener/subscriber changes are registered.

The observers list is backed by a Set.

Specified by:
addObserver in interface StatementLifecycleSvc
Parameters:
observer - to add

removeObserver

public void removeObserver(StatementLifecycleObserver observer)
Description copied from interface: StatementLifecycleSvc
Remove an observer to be called back when statement-state or listener/subscriber changes are registered.

Specified by:
removeObserver in interface StatementLifecycleSvc
Parameters:
observer - to remove

destroy

public void destroy()
Description copied from interface: StatementLifecycleSvc
Destroy the service.

Specified by:
destroy in interface StatementLifecycleSvc

init

public void init()
Description copied from interface: StatementLifecycleSvc
Initialized the service before use.

Specified by:
init in interface StatementLifecycleSvc

getStmtNameToStmt

public java.util.Map<java.lang.String,EPStatement> getStmtNameToStmt()
Specified by:
getStmtNameToStmt in interface StatementLifecycleSvc

createAndStart

public EPStatement createAndStart(StatementSpecRaw statementSpec,
                                  java.lang.String expression,
                                  boolean isPattern,
                                  java.lang.String optStatementName,
                                  java.lang.Object userObject,
                                  EPIsolationUnitServices isolationUnitServices,
                                  java.lang.String statementId,
                                  EPStatementObjectModel optionalModel)
Description copied from interface: StatementLifecycleSvc
Create and start the statement.

Specified by:
createAndStart in interface StatementLifecycleSvc
Parameters:
statementSpec - is the statement definition in bean object form, raw unvalidated and unoptimized.
expression - is the expression text
isPattern - is an indicator on whether this is a pattern statement and thus the iterator must return the last result, versus for non-pattern statements the iterator returns view content.
optStatementName - is an optional statement name, null if none was supplied
userObject - the application define user object associated to each statement, if supplied
isolationUnitServices - isolated service services
Returns:
started statement

createStoppedAssignName

protected StatementLifecycleSvcImpl.EPStatementDesc createStoppedAssignName(StatementSpecRaw statementSpec,
                                                                            java.lang.String expression,
                                                                            boolean isPattern,
                                                                            java.lang.String optStatementName,
                                                                            java.lang.String statementId,
                                                                            java.util.Map<java.lang.String,java.lang.Object> optAdditionalContext,
                                                                            java.lang.Object userObject,
                                                                            EPIsolationUnitServices isolationUnitServices,
                                                                            EPStatementObjectModel optionalModel)
Creates and starts statement.

Parameters:
statementSpec - defines the statement
expression - is the EPL
isPattern - is true for patterns
optStatementName - is the optional statement name
statementId - is the statement id
optAdditionalContext - additional context for use by the statement context
userObject - the application define user object associated to each statement, if supplied
isolationUnitServices - isolated service services
Returns:
started statement

createStopped

protected StatementLifecycleSvcImpl.EPStatementDesc createStopped(StatementSpecRaw statementSpec,
                                                                  java.lang.annotation.Annotation[] annotations,
                                                                  java.lang.String expression,
                                                                  boolean isPattern,
                                                                  java.lang.String statementName,
                                                                  boolean nameProvided,
                                                                  java.lang.String statementId,
                                                                  java.util.Map<java.lang.String,java.lang.Object> optAdditionalContext,
                                                                  java.lang.Object statementUserObject,
                                                                  EPIsolationUnitServices isolationUnitServices,
                                                                  boolean isFailed,
                                                                  EPStatementObjectModel optionalModel)
Create stopped statement.

Parameters:
statementSpec - - statement definition
expression - is the expression text
isPattern - is true for patterns, false for non-patterns
statementName - is the statement name assigned or given
statementId - is the statement id
optAdditionalContext - additional context for use by the statement context
statementUserObject - the application define user object associated to each statement, if supplied
isolationUnitServices - isolated service services
isFailed - to start the statement in failed state
nameProvided - true when an explicit statement name is provided
Returns:
stopped statement

start

public void start(java.lang.String statementId)
Description copied from interface: StatementLifecycleSvc
Start statement by statement id.

Specified by:
start in interface StatementLifecycleSvc
Parameters:
statementId - of the statement to start.

start

public void start(java.lang.String statementId,
                  StatementLifecycleSvcImpl.EPStatementDesc desc,
                  boolean isNewStatement,
                  boolean isRecoveringStatement,
                  boolean isResilient)
Start the given statement.

Parameters:
statementId - is the statement id
desc - is the cached statement info
isNewStatement - indicator whether the statement is new or a stop-restart statement
isRecoveringStatement - if the statement is recovering or new
isResilient - true if recovering a resilient stmt

stop

public void stop(java.lang.String statementId)
Description copied from interface: StatementLifecycleSvc
Stop statement by statement id.

Specified by:
stop in interface StatementLifecycleSvc
Parameters:
statementId - of the statement to stop.

destroy

public void destroy(java.lang.String statementId)
Description copied from interface: StatementLifecycleSvc
Destroy statement by statement id.

Specified by:
destroy in interface StatementLifecycleSvc
Parameters:
statementId - statementId of the statement to destroy

getStatementByName

public EPStatement getStatementByName(java.lang.String name)
Description copied from interface: StatementLifecycleSvc
Returns the statement by the given name, or null if no such statement exists.

Specified by:
getStatementByName in interface StatementLifecycleSvc
Parameters:
name - is the statement name
Returns:
statement for the given name, or null if no such statement existed

getStatementSpec

public StatementSpecCompiled getStatementSpec(java.lang.String statementId)
Specified by:
getStatementSpec in interface StatementLifecycleSvc

getStatementById

public EPStatementSPI getStatementById(java.lang.String id)
Returns the statement given a statement id.

Specified by:
getStatementById in interface StatementLifecycleSvc
Parameters:
id - is the statement id
Returns:
statement

getStatementNames

public java.lang.String[] getStatementNames()
Description copied from interface: StatementLifecycleSvc
Returns an array of statement names. If no statement has been created, an empty array is returned.

Only returns started and stopped statements.

Specified by:
getStatementNames in interface StatementLifecycleSvc
Returns:
statement names

startAllStatements

public void startAllStatements()
                        throws EPException
Description copied from interface: StatementLifecycleSvc
Starts all stopped statements. First statement to fail supplies the exception.

Specified by:
startAllStatements in interface StatementLifecycleSvc
Throws:
EPException - to indicate a start error.

stopAllStatements

public void stopAllStatements()
                       throws EPException
Description copied from interface: StatementLifecycleSvc
Stops all started statements. First statement to fail supplies the exception.

Specified by:
stopAllStatements in interface StatementLifecycleSvc
Throws:
EPException - to indicate a start error.

destroyAllStatements

public void destroyAllStatements()
                          throws EPException
Description copied from interface: StatementLifecycleSvc
Destroys all started statements. First statement to fail supplies the exception.

Specified by:
destroyAllStatements in interface StatementLifecycleSvc
Throws:
EPException - to indicate a start error.

getStatementNameById

public java.lang.String getStatementNameById(java.lang.String id)
Specified by:
getStatementNameById in interface StatementLifecycleSvc

updatedListeners

public void updatedListeners(EPStatement statement,
                             EPStatementListenerSet listeners,
                             boolean isRecovery)
Description copied from interface: StatementLifecycleSvc
Statements indicate that listeners have been added through this method.

Specified by:
updatedListeners in interface StatementLifecycleSvc
Parameters:
statement - is the statement for which listeners were added
listeners - is the set of listeners after adding the new listener

compile

protected static StatementSpecCompiled compile(StatementSpecRaw spec,
                                               java.lang.String eplStatement,
                                               StatementContext statementContext,
                                               boolean isSubquery,
                                               boolean isOnDemandQuery,
                                               java.lang.annotation.Annotation[] annotations,
                                               java.util.List<ExprSubselectNode> subselectNodes,
                                               java.util.List<ExprDeclaredNode> declaredNodes,
                                               EPServicesContext servicesContext)
                                        throws EPStatementException
Compiles a statement returning the compile (verified, non-serializable) form of a statement.

Parameters:
spec - is the statement specification
eplStatement - the statement to compile
statementContext - the statement services
isSubquery - is true for subquery compilation or false for statement compile
annotations - statement annotations
Returns:
compiled statement
Throws:
EPStatementException - if the statement cannot be compiled

compileSelectAllowSubselect

public static SelectClauseSpecCompiled compileSelectAllowSubselect(SelectClauseSpecRaw spec)
                                                            throws ExprValidationException
Compile a select clause allowing subselects.

Parameters:
spec - to compile
Returns:
select clause compiled
Throws:
ExprValidationException - when validation fails

dispatchStatementLifecycleEvent

public void dispatchStatementLifecycleEvent(StatementLifecycleEvent theEvent)
Description copied from interface: StatementLifecycleSvc
Dispatch event to observers.

Specified by:
dispatchStatementLifecycleEvent in interface StatementLifecycleSvc
Parameters:
theEvent - to dispatch

© 2006-2015 EsperTech Inc.
All rights reserved.
Visit us at espertech.com