public class LiveResult extends java.lang.Object implements QueryListener
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 and 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.
|
Modifier and Type | Method and Description |
---|---|
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 |
exceptionRaised(QueryExceptionEvent event)
Event when an exception occurs during the query.
|
protected java.lang.Long |
getKeyForEvent(AbstractTupleEvent event,
boolean remove) |
protected java.lang.Long |
getKeyFromEvent(AbstractTupleEvent event) |
Tuple |
getTuple(KeyValue keyValue)
Get a tuple from the KeyValue obtained from an Event.
|
java.util.Collection<Tuple> |
getTuples()
Retrieves the current tuples in the result
|
java.util.Collection<Tuple> |
getTuples(boolean waitForSnapshot)
Retrieves the current tuples in the result
|
boolean |
isEmpty()
Is the result empty
|
boolean |
isSnapshotComplete()
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.
|
int |
size()
The size of the result
|
void |
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.
|
void |
waitForSnapshot()
Blocking call that waits for the query snapshot to complete.
|
public LiveResult(QueryListener listener)
listener
- The listener to dispatch events to when changes occur on this LiveResultpublic LiveResult()
public void setTimeout(int ms)
ms
- - number of milliseconds to wait before abandoning waiting for snapshot complete.public final boolean isEmpty()
public final int size()
public Tuple getTuple(KeyValue keyValue)
keyValue
- public final java.util.Collection<Tuple> getTuples()
public final java.util.Collection<Tuple> getTuples(boolean waitForSnapshot)
waitForSnapshot
- waits for the query snapshot to complete before returning from the callpublic final void waitForSnapshot()
public void tupleAdded(TupleAddedEvent event)
tupleAdded
in interface QueryListener
event
- add eventprotected java.lang.Long getKeyFromEvent(AbstractTupleEvent event)
protected java.lang.Long getKeyForEvent(AbstractTupleEvent event, boolean remove)
public void tupleUpdated(TupleUpdatedEvent event)
tupleUpdated
in interface QueryListener
event
- update eventpublic void tupleRemoved(TupleRemovedEvent event)
tupleRemoved
in interface QueryListener
event
- remove eventpublic void snapshotBegin(BeginSnapshotEvent event)
snapshotBegin
in interface QueryListener
event
- snapshot beginpublic void snapshotEnd(EndSnapshotEvent event)
snapshotEnd
in interface QueryListener
event
- snapshot endpublic void exceptionRaised(QueryExceptionEvent event)
exceptionRaised
in interface QueryListener
event
- exception eventpublic void queryClosed(QueryClosedEvent event)
queryClosed
in interface QueryListener
event
- query closed eventpublic void deleteBegin(BeginDeleteEvent event)
QueryListener
deleteBegin
in interface QueryListener
event
- delete beginpublic void deleteEnd(EndDeleteEvent event)
QueryListener
deleteEnd
in interface QueryListener
event
- delete endpublic boolean isSnapshotComplete()