Package com.streambase.liveview.client
Class LiveResult
- java.lang.Object
-
- com.streambase.liveview.client.LiveResult
-
- All Implemented Interfaces:
QueryListener,EventListener
public class LiveResult extends Object implements QueryListener
A live result is aQueryListenerthe 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 nestedQueryListener. 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
Constructors Constructor Description LiveResult()Construct 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaggMarkBegin(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.voidaggMarkEnd(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.voiddeleteBegin(BeginDeleteEvent event)Event to indicate the start of delete query.voiddeleteEnd(EndDeleteEvent event)Event to indicate the delete query is complete.voidexceptionRaised(QueryExceptionEvent event)Event when an exception occurs during the query.protected LonggetKeyForEvent(AbstractTupleEvent event, boolean remove)protected LonggetKeyFromEvent(AbstractTupleEvent event)TuplegetTuple(KeyValue keyValue)Get a tuple from the KeyValue obtained from an Event.Collection<Tuple>getTuples()Retrieves the current tuples in the result.Collection<Tuple>getTuples(boolean waitForSnapshot)Retrieves the current tuples in the resultbooleanisEmpty()Is the result emptybooleanisSnapshotComplete()Retreives whether or not the LiveResult is up to date.voidqueryClosed(QueryClosedEvent event)Event when a query being listened to is closed.voidsetTimeout(int ms)setTimeout limits the amount of time to wait for the snapshot to complete.intsize()The size of the resultvoidsnapshotBegin(BeginSnapshotEvent event)Event to indicate the start of the result snapshot.voidsnapshotEnd(EndSnapshotEvent event)Event to indicate the query snapshot is complete.voidtupleAdded(TupleAddedEvent event)Event when a new tuple is added to the result.voidtupleRemoved(TupleRemovedEvent event)Event when an existing tuple is removed from the result.voidtupleUpdated(TupleUpdatedEvent event)Event when an existing tuple in the result is updated.voidwaitForSnapshot()Blocking call that waits for the query snapshot to complete.
-
-
-
Constructor Detail
-
LiveResult
public LiveResult(QueryListener listener)
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 Detail
-
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
public Tuple getTuple(KeyValue keyValue)
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
public final Collection<Tuple> getTuples()
Retrieves the current tuples in the result.- Returns:
- the collection of tuples in the result.
-
getTuples
public final Collection<Tuple> getTuples(boolean waitForSnapshot)
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
public void tupleAdded(TupleAddedEvent event)
Event when a new tuple is added to the result.- Specified by:
tupleAddedin interfaceQueryListener- Parameters:
event- add event- Throws:
TupleException
-
getKeyFromEvent
protected Long getKeyFromEvent(AbstractTupleEvent event)
-
getKeyForEvent
protected Long getKeyForEvent(AbstractTupleEvent event, boolean remove)
-
tupleUpdated
public void tupleUpdated(TupleUpdatedEvent event)
Event when an existing tuple in the result is updated.- Specified by:
tupleUpdatedin interfaceQueryListener- Parameters:
event- update event
-
tupleRemoved
public void tupleRemoved(TupleRemovedEvent event)
Event when an existing tuple is removed from the result.- Specified by:
tupleRemovedin interfaceQueryListener- Parameters:
event- remove event
-
snapshotBegin
public void snapshotBegin(BeginSnapshotEvent event)
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:
snapshotBeginin interfaceQueryListener- Parameters:
event- snapshot begin
-
snapshotEnd
public void snapshotEnd(EndSnapshotEvent event)
Event to indicate the query snapshot is complete.- Specified by:
snapshotEndin interfaceQueryListener- Parameters:
event- snapshot end
-
exceptionRaised
public void exceptionRaised(QueryExceptionEvent event)
Event when an exception occurs during the query. Since 1.3, reaching the row limit is considered an exception.- Specified by:
exceptionRaisedin interfaceQueryListener- Parameters:
event- exception event
-
queryClosed
public void queryClosed(QueryClosedEvent event)
Event when a query being listened to is closed.- Specified by:
queryClosedin interfaceQueryListener- Parameters:
event- query closed event
-
deleteBegin
public void deleteBegin(BeginDeleteEvent event)
Description copied from interface:QueryListenerEvent to indicate the start of delete query.- Specified by:
deleteBeginin interfaceQueryListener- Parameters:
event- delete begin
-
deleteEnd
public void deleteEnd(EndDeleteEvent event)
Description copied from interface:QueryListenerEvent to indicate the delete query is complete.- Specified by:
deleteEndin interfaceQueryListener- Parameters:
event- delete end
-
aggMarkEnd
public void aggMarkEnd(EndAggMarkEvent event)
Description copied from interface:QueryListenerEvent 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:
aggMarkEndin interfaceQueryListener- Parameters:
event- theEndAggMarkEvent
-
aggMarkBegin
public void aggMarkBegin(BeginAggMarkEvent event)
Description copied from interface:QueryListenerEvent 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:
aggMarkBeginin 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.
-
-