public class EPStatementImpl extends Object implements EPStatementSPI
Modifier and Type | Field and Description |
---|---|
protected StatementContext |
statementContext |
Constructor and Description |
---|
EPStatementImpl(String expressionNoAnnotations,
boolean isPattern,
DispatchService dispatchService,
StatementLifecycleSvc statementLifecycleSvc,
long timeLastStateChange,
boolean isBlockingDispatch,
boolean isSpinBlockingDispatch,
long msecBlockingTimeout,
TimeSourceService timeSourceService,
StatementMetadata statementMetadata,
Object userObject,
StatementContext statementContext,
boolean isFailed,
boolean nameProvided)
Ctor.
|
Modifier and Type | Method and Description |
---|---|
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.
|
Annotation[] |
getAnnotations()
Returns EPL or pattern statement annotations provided in the statement text, if any.
|
UpdateDispatchViewBase |
getDispatchChildView() |
EventType |
getEventType()
Returns the type of events the iterable returns.
|
String |
getExpressionNoAnnotations()
Returns the statements expression without annotations.
|
EPStatementListenerSet |
getListenerSet()
Returns the set of listeners to the statement.
|
String |
getName()
Returns the statement name.
|
Viewable |
getParentView()
Returns the parent view.
|
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.
|
Iterator<StatementAwareUpdateListener> |
getStatementAwareListeners()
Returns an iterator of statement-aware update listeners.
|
StatementContext |
getStatementContext()
Returns the statement context.
|
int |
getStatementId()
Returns the statement id.
|
StatementMetadata |
getStatementMetadata()
Returns additional metadata about a statement.
|
Object |
getSubscriber()
Returns the current subscriber instance that receives statement results.
|
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.
|
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.
|
Iterator<EventBean> |
iterator()
Returns a concurrency-unsafe iterator over events representing statement results (pull API).
|
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(String serviceIsolated)
Set the statement's isolated service name, or null to clear.
|
void |
setSubscriber(Object subscriber)
Attaches a subscriber to receive statement results,
or removes a previously set subscriber (by providing a null value).
|
void |
setSubscriber(Object subscriber,
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.
|
protected StatementContext statementContext
public EPStatementImpl(String expressionNoAnnotations, boolean isPattern, DispatchService dispatchService, StatementLifecycleSvc statementLifecycleSvc, long timeLastStateChange, boolean isBlockingDispatch, boolean isSpinBlockingDispatch, long msecBlockingTimeout, TimeSourceService timeSourceService, StatementMetadata statementMetadata, Object userObject, StatementContext statementContext, boolean isFailed, boolean nameProvided)
isPattern
- is true to indicate this is a pure pattern expressiondispatchService
- for dispatching events to listeners to the statementstatementLifecycleSvc
- handles lifecycle transitions for the statementisBlockingDispatch
- is true if the dispatch to listeners should block to preserve event generation orderisSpinBlockingDispatch
- true to use spin locks blocking to deliver results, as locks are usually uncontendedmsecBlockingTimeout
- is the max number of milliseconds of block timetimeLastStateChange
- the timestamp the statement was created and startedtimeSourceService
- time source providerstatementMetadata
- statement metadatauserObject
- the application define user object associated to each statement, if suppliedstatementContext
- the statement service contextexpressionNoAnnotations
- expression text witout annotationsisFailed
- indicator to start in failed statenameProvided
- true to indicate a statement name has been provided and is not a system-generated namepublic int getStatementId()
EPStatementSPI
getStatementId
in interface EPStatementSPI
public void start()
EPStatement
start
in interface EPStatement
public void stop()
EPStatement
stop
in interface EPStatement
public void destroy()
EPStatement
A destroyed statement cannot be started again.
destroy
in interface EPStatement
public EPStatementState getState()
EPStatement
getState
in interface EPStatement
public void setCurrentState(EPStatementState currentState, long timeLastStateChange)
EPStatementSPI
setCurrentState
in interface EPStatementSPI
currentState
- new current statetimeLastStateChange
- the timestamp the statement changed statepublic Viewable getParentView()
EPStatementSPI
getParentView
in interface EPStatementSPI
public void setParentView(Viewable viewable)
EPStatementSPI
setParentView
in interface EPStatementSPI
viewable
- is the statement viewablepublic String getText()
EPStatement
getText
in interface EPStatement
public String getName()
EPStatement
getName
in interface EPStatement
public Iterator<EventBean> iterator(ContextPartitionSelector selector)
EPStatement
iterator
in interface EPStatement
selector
- selects context partitions to considerpublic SafeIterator<EventBean> safeIterator(ContextPartitionSelector selector)
EPStatement
safeIterator
in interface EPStatement
selector
- selects context partitions to considerpublic Iterator<EventBean> iterator()
EPIterable
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.
iterator
in interface EPIterable
public SafeIterator<EventBean> safeIterator()
EPIterable
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.
safeIterator
in interface EPIterable
public EventType getEventType()
EPIterable
getEventType
in interface EPIterable
public EPStatementListenerSet getListenerSet()
getListenerSet
in interface EPStatementSPI
public void setListeners(EPStatementListenerSet listenerSet, boolean isRecovery)
EPStatementSPI
Care must be taken in the use of this method as unsynchronized modification to the listeners of a statement can yield problems.
setListeners
in interface EPStatementSPI
listenerSet
- setisRecovery
- whether we are recoveringpublic void addListener(UpdateListener listener)
addListener
in interface EPListenable
listener
- to addpublic void addListenerWithReplay(UpdateListener listener)
EPStatement
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.
addListenerWithReplay
in interface EPStatement
listener
- to addpublic void removeListener(UpdateListener listener)
removeListener
in interface EPListenable
listener
- to removepublic void removeAllListeners()
removeAllListeners
in interface EPListenable
public void addListener(StatementAwareUpdateListener listener)
EPListenable
addListener
in interface EPListenable
listener
- to addpublic void removeListener(StatementAwareUpdateListener listener)
EPListenable
removeListener
in interface EPListenable
listener
- to removepublic Iterator<StatementAwareUpdateListener> getStatementAwareListeners()
EPListenable
The returned iterator does not allow the remove operation.
getStatementAwareListeners
in interface EPListenable
public Iterator<UpdateListener> getUpdateListeners()
EPListenable
The returned iterator does not allow the remove operation.
getUpdateListeners
in interface EPListenable
public long getTimeLastStateChange()
EPStatement
getTimeLastStateChange
in interface EPStatement
public boolean isStarted()
EPStatement
isStarted
in interface EPStatement
public boolean isStopped()
EPStatement
isStopped
in interface EPStatement
public boolean isDestroyed()
EPStatement
isDestroyed
in interface EPStatement
public void setSubscriber(Object subscriber)
EPStatement
Only a single subscriber may be set for a statement. If this method is invoked twice any previously-set subscriber is no longer used.
setSubscriber
in interface EPStatement
subscriber
- to attach, or null to remove the previously set subscriberpublic void setSubscriber(Object subscriber, String methodName)
EPStatement
Only a single subscriber may be set for a statement. If this method is invoked twice any previously-set subscriber is no longer used.
setSubscriber
in interface EPStatement
subscriber
- to attach, or null to remove the previously set subscribermethodName
- the name of the method to invoke, or null for the "update" methodpublic Object getSubscriber()
EPStatement
getSubscriber
in interface EPStatement
public boolean isPattern()
EPStatement
isPattern
in interface EPStatement
public StatementMetadata getStatementMetadata()
EPStatementSPI
getStatementMetadata
in interface EPStatementSPI
public Object getUserObject()
EPStatement
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.
getUserObject
in interface EPStatement
public Annotation[] getAnnotations()
EPStatement
See the annotation com.espertech.esper.client.annotation
package for
available annotations.
getAnnotations
in interface EPStatement
public StatementContext getStatementContext()
EPStatementSPI
getStatementContext
in interface EPStatementSPI
public String getExpressionNoAnnotations()
EPStatementSPI
getExpressionNoAnnotations
in interface EPStatementSPI
public String getServiceIsolated()
EPStatement
getServiceIsolated
in interface EPStatement
public void setServiceIsolated(String serviceIsolated)
EPStatementSPI
setServiceIsolated
in interface EPStatementSPI
serviceIsolated
- name of isolated servicepublic boolean isNameProvided()
EPStatementSPI
isNameProvided
in interface EPStatementSPI
public UpdateDispatchViewBase getDispatchChildView()