Class QueryPublisher<T>

java.lang.Object
io.objectbox.query.QueryPublisher<T>
All Implemented Interfaces:
DataPublisher<List<T>>, Runnable

@Internal class QueryPublisher<T> extends Object implements 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.
  • Field Details

  • Constructor Details

    • QueryPublisher

      QueryPublisher(Query<T> query, Box<T> box)
  • Method Details

    • subscribe

      public void subscribe(DataObserver<List<T>> observer, @Nullable Object param)
      Specified by:
      subscribe in interface DataPublisher<T>
    • publishSingle

      public void publishSingle(DataObserver<List<T>> observer, @Nullable Object param)
      Specified by:
      publishSingle in interface DataPublisher<T>
    • publish

      void publish()
    • queueObserverAndScheduleRun

      private void queueObserverAndScheduleRun(DataObserver<List<T>> observer)
      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.
      Specified by:
      run in interface Runnable
    • unsubscribe

      public void unsubscribe(DataObserver<List<T>> observer, @Nullable Object param)
      Specified by:
      unsubscribe in interface DataPublisher<T>