Class QueryPublisher<T>

  • All Implemented Interfaces:
    DataPublisher<java.util.List<T>>, java.lang.Runnable

    @Internal
    class QueryPublisher<T>
    extends java.lang.Object
    implements DataPublisher<java.util.List<T>>, java.lang.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 Detail

      • query

        private final Query<T> query
      • box

        private final Box<T> box
      • observers

        private final java.util.Set<DataObserver<java.util.List<T>>> observers
      • publishQueue

        private final java.util.Deque<DataObserver<java.util.List<T>>> publishQueue
      • publisherRunning

        private volatile boolean publisherRunning
      • objectClassObserver

        private DataObserver<java.lang.Class<T>> objectClassObserver
    • Constructor Detail

      • QueryPublisher

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

      • publish

        void publish()
      • queueObserverAndScheduleRun

        private void queueObserverAndScheduleRun​(DataObserver<java.util.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 java.lang.Runnable