com.espertech.esper.core.service
Class EPStatementImpl

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

public class EPStatementImpl
extends java.lang.Object
implements EPStatementSPI

Statement implementation for EPL statements.


Constructor Summary
EPStatementImpl(java.lang.String expressionNoAnnotations, boolean isPattern, DispatchService dispatchService, StatementLifecycleSvc statementLifecycleSvc, long timeLastStateChange, boolean isBlockingDispatch, boolean isSpinBlockingDispatch, long msecBlockingTimeout, TimeSourceService timeSourceService, StatementMetadata statementMetadata, java.lang.Object userObject, StatementContext statementContext, boolean isFailed, boolean nameProvided)
          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 addListenerWithReplay(UpdateListener listener)
          Add an update listener replaying current statement results to the listener.
 void destroy()
          Destroy the statement releasing all statement resources.
 java.lang.annotation.Annotation[] getAnnotations()
          Returns EPL or pattern statement annotations provided in the statement text, if any.
 EventType getEventType()
          Returns the type of events the iterable returns.
 java.lang.String getExpressionNoAnnotations()
          Returns the statements expression without annotations.
 EPStatementListenerSet getListenerSet()
          Returns the set of listeners to the statement.
 java.lang.String getName()
          Returns the statement name.
 java.lang.String getServiceIsolated()
          Returns the name of the isolated service provided is the statement is currently isolated in terms of event visibility and scheduling, or returns null if the statement is live in the engine.
 EPStatementState getState()
          Returns the statement's current state.
 java.util.Iterator<StatementAwareUpdateListener> getStatementAwareListeners()
          Returns an iterator of statement-aware update listeners.
 StatementContext getStatementContext()
          Returns the statement context.
 java.lang.String getStatementId()
          Returns the statement id.
 StatementMetadata getStatementMetadata()
          Returns additional metadata about a statement.
 java.lang.Object getSubscriber()
          Returns the current subscriber instance that receives statement results.
 java.lang.String getText()
          Returns the underlying expression text.
 long getTimeLastStateChange()
          Returns the system time in milliseconds of when the statement last change state.
 java.util.Iterator<UpdateListener> getUpdateListeners()
          Returns an iterator of update listeners.
 java.lang.Object getUserObject()
          Returns the application defined user data object associated with the statement, or null if none was supplied at time of statement creation.
 boolean isDestroyed()
          Returns true if the statement state is destroyed.
 boolean isNameProvided()
          True if an explicit statement name has been provided, false if the statement name is system-generated.
 boolean isPattern()
          Returns true if statement is a pattern
 boolean isStarted()
          Returns true if the statement state is started.
 boolean isStopped()
          Returns true if the statement state is stopped.
 java.util.Iterator<EventBean> iterator()
          Returns a concurrency-unsafe iterator over events representing statement results (pull API).
 java.util.Iterator<EventBean> iterator(ContextPartitionSelector selector)
          For use with statements that have a context declared and that may therefore have multiple context partitions, allows to iterate over context partitions selectively.
 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.
 SafeIterator<EventBean> safeIterator(ContextPartitionSelector selector)
          For use with statements that have a context declared and that may therefore have multiple context partitions, allows to safe-iterate over context partitions selectively.
 void setCurrentState(EPStatementState currentState, long timeLastStateChange)
          Set statement state.
 void setListeners(EPStatementListenerSet listenerSet, boolean isRecovery)
          Sets the statement listeners.
 void setParentView(Viewable viewable)
          Sets the parent view.
 void setServiceIsolated(java.lang.String serviceIsolated)
          Set the statement's isolated service name, or null to clear.
 void setSubscriber(java.lang.Object subscriber)
          Attaches a subscriber to receive statement results, or removes a previously set subscriber (by providing a null value).
 void setSubscriber(java.lang.Object subscriber, java.lang.String methodName)
          Attaches a subscriber to receive statement results by calling the method with the provided method name, or removes a previously set subscriber (by providing a null value).
 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(java.lang.String expressionNoAnnotations,
                       boolean isPattern,
                       DispatchService dispatchService,
                       StatementLifecycleSvc statementLifecycleSvc,
                       long timeLastStateChange,
                       boolean isBlockingDispatch,
                       boolean isSpinBlockingDispatch,
                       long msecBlockingTimeout,
                       TimeSourceService timeSourceService,
                       StatementMetadata statementMetadata,
                       java.lang.Object userObject,
                       StatementContext statementContext,
                       boolean isFailed,
                       boolean nameProvided)
Ctor.

Parameters:
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
timeLastStateChange - the timestamp the statement was created and started
timeSourceService - time source provider
statementMetadata - statement metadata
userObject - the application define user object associated to each statement, if supplied
statementContext - the statement service context
expressionNoAnnotations - expression text witout annotations
isFailed - indicator to start in failed state
nameProvided - true to indicate a statement name has been provided and is not a system-generated name
Method Detail

getStatementId

public java.lang.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 java.lang.String getText()
Description copied from interface: EPStatement
Returns the underlying expression text.

Specified by:
getText in interface EPStatement
Returns:
expression text

getName

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

Specified by:
getName in interface EPStatement
Returns:
statement name

iterator

public java.util.Iterator<EventBean> iterator(ContextPartitionSelector selector)
Description copied from interface: EPStatement
For use with statements that have a context declared and that may therefore have multiple context partitions, allows to iterate over context partitions selectively.

Specified by:
iterator in interface EPStatement
Parameters:
selector - selects context partitions to consider
Returns:
iterator

safeIterator

public SafeIterator<EventBean> safeIterator(ContextPartitionSelector selector)
Description copied from interface: EPStatement
For use with statements that have a context declared and that may therefore have multiple context partitions, allows to safe-iterate over context partitions selectively.

Specified by:
safeIterator in interface EPStatement
Parameters:
selector - selects context partitions to consider
Returns:
safe iterator

iterator

public java.util.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,
                         boolean isRecovery)
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

addListenerWithReplay

public void addListenerWithReplay(UpdateListener listener)
Description copied from interface: EPStatement
Add an update listener replaying current statement results to the listener.

The listener receives current statement results as the first call to the update method of the listener, passing in the newEvents parameter the current statement results as an array of zero or more events. Subsequent calls to the update method of the listener are statement results.

Current statement results are the events returned by the iterator or safeIterator methods.

Delivery of current statement results in the first call is performed by the same thread invoking this method, while subsequent calls to the listener may deliver statement results by the same or other threads.

Note: this is a blocking call, delivery is atomic: Events occurring during iteration and delivery to the listener are guaranteed to be delivered in a separate call and not lost. The listener implementation should minimize long-running or blocking operations.

Delivery is only atomic relative to the current statement. If the same listener instance is registered with other statements it may receive other statement result s simultaneously.

If a statement is not started an therefore does not have current results, the listener receives a single invocation with a null value in newEvents.

Specified by:
addListenerWithReplay in interface EPStatement
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 java.util.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 java.util.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.

setSubscriber

public void setSubscriber(java.lang.Object subscriber)
Description copied from interface: EPStatement
Attaches a subscriber to receive statement results, or removes a previously set subscriber (by providing a null value).

Only a single subscriber may be set for a statement. If this method is invoked twice any previously-set subscriber is no longer used.

Specified by:
setSubscriber in interface EPStatement
Parameters:
subscriber - to attach, or null to remove the previously set subscriber

setSubscriber

public void setSubscriber(java.lang.Object subscriber,
                          java.lang.String methodName)
Description copied from interface: EPStatement
Attaches a subscriber to receive statement results by calling the method with the provided method name, or removes a previously set subscriber (by providing a null value).

Only a single subscriber may be set for a statement. If this method is invoked twice any previously-set subscriber is no longer used.

Specified by:
setSubscriber in interface EPStatement
Parameters:
subscriber - to attach, or null to remove the previously set subscriber
methodName - the name of the method to invoke, or null for the "update" method

getSubscriber

public java.lang.Object getSubscriber()
Description copied from interface: EPStatement
Returns the current subscriber instance that receives statement results.

Specified by:
getSubscriber in interface EPStatement
Returns:
subscriber object, or null to indicate that no subscriber is attached

isPattern

public boolean isPattern()
Description copied from interface: EPStatement
Returns true if statement is a pattern

Specified by:
isPattern in interface EPStatement
Returns:
true if statement is a pattern

getStatementMetadata

public StatementMetadata getStatementMetadata()
Description copied from interface: EPStatementSPI
Returns additional metadata about a statement.

Specified by:
getStatementMetadata in interface EPStatementSPI
Returns:
statement metadata

getUserObject

public java.lang.Object getUserObject()
Description copied from interface: EPStatement
Returns the application defined user data object associated with the statement, or null if none was supplied at time of statement creation.

The user object is a single, unnamed field that is stored with every statement. Applications may put arbitrary objects in this field or a null value.

User objects are passed at time of statement creation as a parameter the create method.

Specified by:
getUserObject in interface EPStatement
Returns:
user object or null if none defined

getAnnotations

public java.lang.annotation.Annotation[] getAnnotations()
Description copied from interface: EPStatement
Returns EPL or pattern statement annotations provided in the statement text, if any.

See the annotation com.espertech.esper.client.annotation package for available annotations.

Specified by:
getAnnotations in interface EPStatement
Returns:
annotations or a zero-length array if no annotaions have been specified.

getStatementContext

public StatementContext getStatementContext()
Description copied from interface: EPStatementSPI
Returns the statement context.

Specified by:
getStatementContext in interface EPStatementSPI
Returns:
statement context

getExpressionNoAnnotations

public java.lang.String getExpressionNoAnnotations()
Description copied from interface: EPStatementSPI
Returns the statements expression without annotations.

Specified by:
getExpressionNoAnnotations in interface EPStatementSPI
Returns:
expression

getServiceIsolated

public java.lang.String getServiceIsolated()
Description copied from interface: EPStatement
Returns the name of the isolated service provided is the statement is currently isolated in terms of event visibility and scheduling, or returns null if the statement is live in the engine.

Specified by:
getServiceIsolated in interface EPStatement
Returns:
isolated service name or null for statements that are not currently isolated

setServiceIsolated

public void setServiceIsolated(java.lang.String serviceIsolated)
Description copied from interface: EPStatementSPI
Set the statement's isolated service name, or null to clear.

Specified by:
setServiceIsolated in interface EPStatementSPI
Parameters:
serviceIsolated - name of isolated service

isNameProvided

public boolean isNameProvided()
Description copied from interface: EPStatementSPI
True if an explicit statement name has been provided, false if the statement name is system-generated.

Specified by:
isNameProvided in interface EPStatementSPI
Returns:
indicator if statement name exists

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