Package io.objectbox.query
Class QueryPublisher<T>
java.lang.Object
io.objectbox.query.QueryPublisher<T>
- All Implemented Interfaces:
DataPublisher<List<T>>,Runnable
A
DataPublisher that subscribes to an ObjectClassPublisher if there is at least one observer.
Publishing is requested if the ObjectClassPublisher reports changes, a subscription is
observed or Query.publish() is called.
For publishing the query is re-run and the result delivered to the current observers.
Results are published on a single thread, one at a time, in the order publishing was requested.-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate DataObserver<Class<T>> private DataSubscriptionprivate final Set<DataObserver<List<T>>> private booleanprivate final Deque<DataObserver<List<T>>> private final QueryPublisher.SubscribedObservers<T> Placeholder observer to use if all subscribed observers should be notified. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) voidpublish()voidpublishSingle(DataObserver<List<T>> observer, Object param) private voidqueueObserverAndScheduleRun(DataObserver<List<T>> observer) Non-blocking: will just enqueue the changes for a separate thread.voidrun()Processes publish requests for this query on a single thread to prevent older query results getting delivered after newer query results.voidsubscribe(DataObserver<List<T>> observer, Object param) voidunsubscribe(DataObserver<List<T>> observer, Object param)
-
Field Details
-
query
-
box
-
observers
-
publishQueue
-
publisherRunning
private volatile boolean publisherRunning -
SUBSCRIBED_OBSERVERS
Placeholder observer to use if all subscribed observers should be notified. -
objectClassObserver
-
objectClassSubscription
-
-
Constructor Details
-
QueryPublisher
-
-
Method Details
-
subscribe
- Specified by:
subscribein interfaceDataPublisher<T>
-
publishSingle
- Specified by:
publishSinglein interfaceDataPublisher<T>
-
publish
void publish() -
queueObserverAndScheduleRun
Non-blocking: will just enqueue the changes for a separate thread. -
run
public void run()Processes publish requests for this query on a single thread to prevent older query results getting delivered after newer query results. To speed up processing each loop publishes to all queued observers instead of just the next in line. This reduces time spent querying and waiting for DataObserver.onData() and their potential DataTransformers. -
unsubscribe
- Specified by:
unsubscribein interfaceDataPublisher<T>
-