net.esper.core
Class EPStatementImpl

java.lang.Object
  extended by net.esper.core.EPStatementImpl
All Implemented Interfaces:
EPIterable, EPListenable, EPStatement, EPStatementSPI

public class EPStatementImpl
extends Object
implements EPStatementSPI

Statement implementation for EQL statements.


Constructor Summary
EPStatementImpl(EPServiceProvider epServiceProvider, String statementId, String statementName, String expressionText, boolean isPattern, DispatchService dispatchService, StatementLifecycleSvc statementLifecycleSvc, long timeLastStateChange, boolean isBlockingDispatch, boolean isSpinBlockingDispatch, long msecBlockingTimeout, EPStatementHandle epStatementHandle, VariableService variableService)
          Ctor.
 
Method Summary
 void addListener(StatementAwareUpdateListener listener)
          Add a statement-aware listener that observes events.
 void addListener(UpdateListener listener)
          Add a listener to the statement.
 void destroy()
          Destroy the statement releasing all statement resources.
 EventType getEventType()
          Returns the type of events the iterable returns.
 EPStatementListenerSet getListenerSet()
          Returns the set of listeners to the statement.
 String getName()
          Returns the statement name.
 EPStatementState getState()
          Returns the statement's current state.
 Iterator<StatementAwareUpdateListener> getStatementAwareListeners()
          Returns an iterator of statement-aware update listeners.
 String getStatementId()
          Returns the statement id.
 String getText()
          Returns the underlying expression text.
 long getTimeLastStateChange()
          Returns the system time in milliseconds of when the statement last change state.
 Iterator<UpdateListener> getUpdateListeners()
          Returns an iterator of update listeners.
 boolean isDestroyed()
          Returns true if the statement state is destroyed.
 boolean isStarted()
          Returns true if the statement state is started.
 boolean isStopped()
          Returns true if the statement state is stopped.
 Iterator<EventBean> iterator()
          Returns a concurrency-unsafe iterator over events representing statement results (pull API).
 void removeAllListeners()
          Remove all listeners to a statement.
 void removeListener(StatementAwareUpdateListener listener)
          Remove a statement-aware listener that observes events.
 void removeListener(UpdateListener listener)
          Remove a listeners to a statement.
 SafeIterator<EventBean> safeIterator()
          Returns a concurrency-safe iterator that iterates over events representing statement results (pull API) in the face of concurrent event processing by further threads.
 void setCurrentState(EPStatementState currentState, long timeLastStateChange)
          Set statement state.
 void setListeners(EPStatementListenerSet listenerSet)
          Sets the statement listeners.
 void setParentView(Viewable viewable)
          Sets the parent view.
 void start()
          Start the statement.
 void stop()
          Stop the statement.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EPStatementImpl

public EPStatementImpl(EPServiceProvider epServiceProvider,
                       String statementId,
                       String statementName,
                       String expressionText,
                       boolean isPattern,
                       DispatchService dispatchService,
                       StatementLifecycleSvc statementLifecycleSvc,
                       long timeLastStateChange,
                       boolean isBlockingDispatch,
                       boolean isSpinBlockingDispatch,
                       long msecBlockingTimeout,
                       EPStatementHandle epStatementHandle,
                       VariableService variableService)
Ctor.

Parameters:
statementId - is a unique ID assigned by the engine for the statement
statementName - is the statement name assigned during creation, or the statement id if none was assigned
expressionText - is the EQL and/or pattern expression
isPattern - is true to indicate this is a pure pattern expression
dispatchService - for dispatching events to listeners to the statement
statementLifecycleSvc - handles lifecycle transitions for the statement
isBlockingDispatch - is true if the dispatch to listeners should block to preserve event generation order
isSpinBlockingDispatch - true to use spin locks blocking to deliver results, as locks are usually uncontended
msecBlockingTimeout - is the max number of milliseconds of block time
epServiceProvider - is the engine instance to provide to statement-aware update listeners
timeLastStateChange - the timestamp the statement was created and started
epStatementHandle - the handle and statement lock associated with the statement
variableService - provides access to variable values
Method Detail

getStatementId

public String getStatementId()
Description copied from interface: EPStatementSPI
Returns the statement id.

Specified by:
getStatementId in interface EPStatementSPI
Returns:
statement id

start

public void start()
Description copied from interface: EPStatement
Start the statement.

Specified by:
start in interface EPStatement

stop

public void stop()
Description copied from interface: EPStatement
Stop the statement.

Specified by:
stop in interface EPStatement

destroy

public void destroy()
Description copied from interface: EPStatement
Destroy the statement releasing all statement resources.

A destroyed statement cannot be started again.

Specified by:
destroy in interface EPStatement

getState

public EPStatementState getState()
Description copied from interface: EPStatement
Returns the statement's current state.

Specified by:
getState in interface EPStatement
Returns:
state enum

setCurrentState

public void setCurrentState(EPStatementState currentState,
                            long timeLastStateChange)
Description copied from interface: EPStatementSPI
Set statement state.

Specified by:
setCurrentState in interface EPStatementSPI
Parameters:
currentState - new current state
timeLastStateChange - the timestamp the statement changed state

setParentView

public void setParentView(Viewable viewable)
Description copied from interface: EPStatementSPI
Sets the parent view.

Specified by:
setParentView in interface EPStatementSPI
Parameters:
viewable - is the statement viewable

getText

public String getText()
Description copied from interface: EPStatement
Returns the underlying expression text.

Specified by:
getText in interface EPStatement
Returns:
expression text

getName

public String getName()
Description copied from interface: EPStatement
Returns the statement name.

Specified by:
getName in interface EPStatement
Returns:
statement name

iterator

public Iterator<EventBean> iterator()
Description copied from interface: EPIterable
Returns a concurrency-unsafe iterator over events representing statement results (pull API).

The iterator is useful for applications that are single-threaded, or that coordinate the iterating thread with event processing threads that use the sendEvent method using application code locks or synchronization.

The iterator returned by this method does not make any guarantees towards correctness of results and fail-behavior, if your application processes events into the engine instance using the sendEvent method by multiple threads.

Use the safeIterator method for concurrency-safe iteration. Note the safe iterator requires applications to explicitly close the safe iterator when done iterating.

Specified by:
iterator in interface EPIterable
Returns:
event iterator

safeIterator

public SafeIterator<EventBean> safeIterator()
Description copied from interface: EPIterable
Returns a concurrency-safe iterator that iterates over events representing statement results (pull API) in the face of concurrent event processing by further threads.

In comparison to the regular iterator, the safe iterator guarantees correct results even as events are being processed by other threads. The cost is that the iterator holds one or more locks that must be released via the close method. Any locks are acquired at the time this method is called.

This method is a blocking method. It may block until statement processing locks are released such that the safe iterator can acquire any required locks.

An application MUST explicitly close the safe iterator instance using the close method, to release locks held by the iterator. The call to the close method should be done in a finally block to make sure the iterator gets closed.

Multiple safe iterators may be not be used at the same time by different application threads. A single application thread may hold and use multiple safe iterators however this is discouraged.

Specified by:
safeIterator in interface EPIterable
Returns:
safe iterator; NOTE: Must use the close method to close the safe iterator, preferably in a finally block

getEventType

public EventType getEventType()
Description copied from interface: EPIterable
Returns the type of events the iterable returns.

Specified by:
getEventType in interface EPIterable
Returns:
event type of events the iterator returns

getListenerSet

public EPStatementListenerSet getListenerSet()
Returns the set of listeners to the statement.

Specified by:
getListenerSet in interface EPStatementSPI
Returns:
statement listeners

setListeners

public void setListeners(EPStatementListenerSet listenerSet)
Description copied from interface: EPStatementSPI
Sets the statement listeners.

Care must be taken in the use of this method as unsynchronized modification to the listeners of a statement can yield problems.

Specified by:
setListeners in interface EPStatementSPI
Parameters:
listenerSet - set

addListener

public void addListener(UpdateListener listener)
Add a listener to the statement.

Specified by:
addListener in interface EPListenable
Parameters:
listener - to add

removeListener

public void removeListener(UpdateListener listener)
Remove a listeners to a statement.

Specified by:
removeListener in interface EPListenable
Parameters:
listener - to remove

removeAllListeners

public void removeAllListeners()
Remove all listeners to a statement.

Specified by:
removeAllListeners in interface EPListenable

addListener

public void addListener(StatementAwareUpdateListener listener)
Description copied from interface: EPListenable
Add a statement-aware listener that observes events.

Specified by:
addListener in interface EPListenable
Parameters:
listener - to add

removeListener

public void removeListener(StatementAwareUpdateListener listener)
Description copied from interface: EPListenable
Remove a statement-aware listener that observes events.

Specified by:
removeListener in interface EPListenable
Parameters:
listener - to remove

getStatementAwareListeners

public Iterator<StatementAwareUpdateListener> getStatementAwareListeners()
Description copied from interface: EPListenable
Returns an iterator of statement-aware update listeners.

The returned iterator does not allow the remove operation.

Specified by:
getStatementAwareListeners in interface EPListenable
Returns:
iterator of statement-aware update listeners

getUpdateListeners

public Iterator<UpdateListener> getUpdateListeners()
Description copied from interface: EPListenable
Returns an iterator of update listeners.

The returned iterator does not allow the remove operation.

Specified by:
getUpdateListeners in interface EPListenable
Returns:
iterator of update listeners

getTimeLastStateChange

public long getTimeLastStateChange()
Description copied from interface: EPStatement
Returns the system time in milliseconds of when the statement last change state.

Specified by:
getTimeLastStateChange in interface EPStatement
Returns:
time in milliseconds of last statement state change

isStarted

public boolean isStarted()
Description copied from interface: EPStatement
Returns true if the statement state is started.

Specified by:
isStarted in interface EPStatement
Returns:
true for started statements, false for stopped or destroyed statements.

isStopped

public boolean isStopped()
Description copied from interface: EPStatement
Returns true if the statement state is stopped.

Specified by:
isStopped in interface EPStatement
Returns:
true for stopped statements, false for started or destroyed statements.

isDestroyed

public boolean isDestroyed()
Description copied from interface: EPStatement
Returns true if the statement state is destroyed.

Specified by:
isDestroyed in interface EPStatement
Returns:
true for destroyed statements, false for started or stopped statements.

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