Package com.streambase.liveview.client
Class LiveResult
java.lang.Object
com.streambase.liveview.client.LiveResult
- All Implemented Interfaces:
QueryListener
,EventListener
A live result is a
QueryListener
the receives and maintains a local copy of tuples. Methods exists to
retrieve the current list of tuples maintained locally. The live results can also be constructed with a nested
QueryListener
. In this mode the live result will propagate events it received to the nested listener. It will
also modify update and remove events to include the old or removed tuple (in addition to the new tuple.)-
Constructor Summary
ConstructorDescriptionConstruct a LiveResult that will maintain the list of tuples for you which you can query at your leisure.LiveResult
(QueryListener listener) Contruct a LiveResult that will maintain the tuples for you, plus you can also be informed of all the events. -
Method Summary
Modifier and TypeMethodDescriptionvoid
aggMarkBegin
(BeginAggMarkEvent event) Event to indicate that the set of aggregation results may be changing so some results may be from an older generation while other may be from a newer one.void
aggMarkEnd
(EndAggMarkEvent event) Event to indicate that the set of aggregation results since the last aggMarkBegin event are now consistent and will not change until the next aggMarkBegin.void
deleteBegin
(BeginDeleteEvent event) Event to indicate the start of delete query.void
deleteEnd
(EndDeleteEvent event) Event to indicate the delete query is complete.void
Event when an exception occurs during the query.protected Long
getKeyForEvent
(AbstractTupleEvent event, boolean remove) protected Long
Get a tuple from the KeyValue obtained from an Event.final Collection<Tuple>
Retrieves the current tuples in the result.final Collection<Tuple>
getTuples
(boolean waitForSnapshot) Retrieves the current tuples in the resultfinal boolean
isEmpty()
Is the result emptyboolean
Retreives whether or not the LiveResult is up to date.void
queryClosed
(QueryClosedEvent event) Event when a query being listened to is closed.void
setTimeout
(int ms) setTimeout limits the amount of time to wait for the snapshot to complete.final int
size()
The size of the resultvoid
snapshotBegin
(BeginSnapshotEvent event) Event to indicate the start of the result snapshot.void
snapshotEnd
(EndSnapshotEvent event) Event to indicate the query snapshot is complete.void
tupleAdded
(TupleAddedEvent event) Event when a new tuple is added to the result.void
tupleRemoved
(TupleRemovedEvent event) Event when an existing tuple is removed from the result.void
tupleUpdated
(TupleUpdatedEvent event) Event when an existing tuple in the result is updated.final void
Blocking call that waits for the query snapshot to complete.
-
Constructor Details
-
LiveResult
Contruct a LiveResult that will maintain the tuples for you, plus you can also be informed of all the events. All events will be passed on to your listener. However, the update events will be populated with a complete old and new tuples. (Without the LiveResult, then update events only have the- Parameters:
listener
- The listener to dispatch events to when changes occur on this LiveResult
-
LiveResult
public LiveResult()Construct a LiveResult that will maintain the list of tuples for you which you can query at your leisure.
-
-
Method Details
-
setTimeout
public void setTimeout(int ms) setTimeout limits the amount of time to wait for the snapshot to complete.- Parameters:
ms
- - number of milliseconds to wait before abandoning waiting for snapshot complete.- Since:
- 1.4.1
-
isEmpty
public final boolean isEmpty()Is the result empty- Returns:
- true is the result is empty
-
size
public final int size()The size of the result- Returns:
- the size
-
getTuple
Get a tuple from the KeyValue obtained from an Event. Note that this will return null if the tuple is not in the list of tuples, that is, before it has been added or after it has been removed. -
getTuples
Retrieves the current tuples in the result.- Returns:
- the collection of tuples in the result.
-
getTuples
Retrieves the current tuples in the result- Parameters:
waitForSnapshot
- waits for the query snapshot to complete before returning from the call- Returns:
- the collection of tuples in the result
-
waitForSnapshot
public final void waitForSnapshot()Blocking call that waits for the query snapshot to complete. -
tupleAdded
Event when a new tuple is added to the result.- Specified by:
tupleAdded
in interfaceQueryListener
- Parameters:
event
- add event- Throws:
TupleException
-
getKeyFromEvent
-
getKeyForEvent
-
tupleUpdated
Event when an existing tuple in the result is updated.- Specified by:
tupleUpdated
in interfaceQueryListener
- Parameters:
event
- update event
-
tupleRemoved
Event when an existing tuple is removed from the result.- Specified by:
tupleRemoved
in interfaceQueryListener
- Parameters:
event
- remove event
-
snapshotBegin
Event to indicate the start of the result snapshot. This is the first method called when a query starts returning results, but this method is also called to indicate a reset (a complete restart of the query.)- Specified by:
snapshotBegin
in interfaceQueryListener
- Parameters:
event
- snapshot begin
-
snapshotEnd
Event to indicate the query snapshot is complete.- Specified by:
snapshotEnd
in interfaceQueryListener
- Parameters:
event
- snapshot end
-
exceptionRaised
Event when an exception occurs during the query. Since 1.3, reaching the row limit is considered an exception.- Specified by:
exceptionRaised
in interfaceQueryListener
- Parameters:
event
- exception event
-
queryClosed
Event when a query being listened to is closed.- Specified by:
queryClosed
in interfaceQueryListener
- Parameters:
event
- query closed event
-
deleteBegin
Description copied from interface:QueryListener
Event to indicate the start of delete query.- Specified by:
deleteBegin
in interfaceQueryListener
- Parameters:
event
- delete begin
-
deleteEnd
Description copied from interface:QueryListener
Event to indicate the delete query is complete.- Specified by:
deleteEnd
in interfaceQueryListener
- Parameters:
event
- delete end
-
aggMarkEnd
Description copied from interface:QueryListener
Event to indicate that the set of aggregation results since the last aggMarkBegin event are now consistent and will not change until the next aggMarkBegin.- Specified by:
aggMarkEnd
in interfaceQueryListener
- Parameters:
event
- theEndAggMarkEvent
-
aggMarkBegin
Description copied from interface:QueryListener
Event to indicate that the set of aggregation results may be changing so some results may be from an older generation while other may be from a newer one.- Specified by:
aggMarkBegin
in interfaceQueryListener
- Parameters:
event
- theBeginAggMarkEvent
-
isSnapshotComplete
public boolean isSnapshotComplete()Retreives whether or not the LiveResult is up to date.- Returns:
- true if the LiveResult is up to date.
-