com.espertech.esper.core
Class StatementLifecycleSvcImpl

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

public class StatementLifecycleSvcImpl
extends Object
implements StatementLifecycleSvc

Provides statement lifecycle services.


Nested Class Summary
 class StatementLifecycleSvcImpl.EPStatementDesc
          Statement information.
 
Field Summary
protected  EPServicesContext services
          Services context for statement lifecycle management.
protected  Map<String,StatementLifecycleSvcImpl.EPStatementDesc> stmtIdToDescMap
          Maps of statement id to descriptor.
protected  Map<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, String eplStatement, StatementContext statementContext)
          Compiles a statement returning the compile (verified, non-serializable) form of a statement.
 EPStatement createAndStart(StatementSpecRaw statementSpec, String expression, boolean isPattern, String optStatementName)
          Create and start the statement.
protected  EPStatement createAndStart(StatementSpecRaw statementSpec, String expression, boolean isPattern, String optStatementName, String statementId, Map<String,Object> optAdditionalContext)
          Creates and starts statement.
protected  EPStatement createStarted(StatementSpecRaw statementSpec, String expression, boolean isPattern, String statementName, String statementId, Map<String,Object> optAdditionalContext)
          Creates a started statement.
protected  StatementLifecycleSvcImpl.EPStatementDesc createStopped(StatementSpecRaw statementSpec, String expression, boolean isPattern, String statementName, String statementId, Map<String,Object> optAdditionalContext)
          Create stopped statement.
 void destroy()
          Destroy the service.
 void destroy(String statementId)
          Destroy statement by statement id.
 void destroyAllStatements()
          Destroys all started statements.
 void dispatchStatementLifecycleEvent(StatementLifecycleEvent event)
          Dispatch event to observers.
 EPStatementSPI getStatementById(String id)
          Returns the statement given a statement id.
 EPStatement getStatementByName(String name)
          Returns the statement by the given name, or null if no such statement exists.
 String[] getStatementNames()
          Returns an array of statement names.
 void init()
          Initialized the service before use.
 void start(String statementId)
          Start statement by statement id.
 void start(String statementId, StatementLifecycleSvcImpl.EPStatementDesc desc, boolean isNewStatement)
          Start the given statement.
 void startAllStatements()
          Starts all stopped statements.
 void stop(String statementId)
          Stop statement by statement id.
 void stopAllStatements()
          Stops all started statements.
 void updatedListeners(String statementId, String statementName, EPStatementListenerSet listeners)
          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 Map<String,StatementLifecycleSvcImpl.EPStatementDesc> stmtIdToDescMap
Maps of statement id to descriptor.


stmtNameToStmtMap

protected final Map<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

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

createAndStart

public EPStatement createAndStart(StatementSpecRaw statementSpec,
                                  String expression,
                                  boolean isPattern,
                                  String optStatementName)
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
Returns:
started statement

createAndStart

protected EPStatement createAndStart(StatementSpecRaw statementSpec,
                                     String expression,
                                     boolean isPattern,
                                     String optStatementName,
                                     String statementId,
                                     Map<String,Object> optAdditionalContext)
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
Returns:
started statement

createStarted

protected EPStatement createStarted(StatementSpecRaw statementSpec,
                                    String expression,
                                    boolean isPattern,
                                    String statementName,
                                    String statementId,
                                    Map<String,Object> optAdditionalContext)
Creates a started statement.

Parameters:
statementSpec - is the statement def
expression - is the expression text
isPattern - is true for patterns,
statementName - is the statement name
statementId - is the statement id
optAdditionalContext - additional context for use by the statement context
Returns:
statement

createStopped

protected StatementLifecycleSvcImpl.EPStatementDesc createStopped(StatementSpecRaw statementSpec,
                                                                  String expression,
                                                                  boolean isPattern,
                                                                  String statementName,
                                                                  String statementId,
                                                                  Map<String,Object> optAdditionalContext)
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
Returns:
stopped statement

start

public void start(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(String statementId,
                  StatementLifecycleSvcImpl.EPStatementDesc desc,
                  boolean isNewStatement)
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

stop

public void stop(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(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(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

getStatementById

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

Parameters:
id - is the statement id
Returns:
statement

getStatementNames

public 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.

updatedListeners

public void updatedListeners(String statementId,
                             String statementName,
                             EPStatementListenerSet listeners)
Description copied from interface: StatementLifecycleSvc
Statements indicate that listeners have been added through this method.

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

compile

protected static StatementSpecCompiled compile(StatementSpecRaw spec,
                                               String eplStatement,
                                               StatementContext statementContext)
                                        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
Returns:
compiled statement
Throws:
EPStatementException - if the statement cannot be compiled

dispatchStatementLifecycleEvent

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

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

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