Class RefreshListeners

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, org.apache.lucene.search.ReferenceManager.RefreshListener

    public final class RefreshListeners
    extends java.lang.Object
    implements org.apache.lucene.search.ReferenceManager.RefreshListener, java.io.Closeable
    Allows for the registration of listeners that are called when a change becomes visible for search. This functionality is exposed from IndexShard but kept here so it can be tested without standing up the entire thing. When Closeable.close()d it will no longer accept listeners and flush any existing listeners.
    • Constructor Summary

      Constructors 
      Constructor Description
      RefreshListeners​(java.util.function.IntSupplier getMaxRefreshListeners, java.lang.Runnable forceRefresh, java.util.concurrent.Executor listenerExecutor, org.apache.logging.log4j.Logger logger, ThreadContext threadContext, MeanMetric refreshMetric)  
    • Method Summary

      Modifier and Type Method Description
      boolean addOrNotify​(Translog.Location location, java.util.function.Consumer<java.lang.Boolean> listener)
      Add a listener for refreshes, calling it immediately if the location is already visible.
      void afterRefresh​(boolean didRefresh)  
      void beforeRefresh()  
      void close()  
      Releasable forceRefreshes()
      Force-refreshes newly added listeners and forces a refresh if there are currently listeners registered.
      int pendingCount()
      The number of pending listeners.
      boolean refreshNeeded()
      Returns true if there are pending listeners.
      void setCurrentRefreshLocationSupplier​(java.util.function.Supplier<Translog.Location> currentRefreshLocationSupplier)
      Setup the translog used to find the last refreshed location.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • RefreshListeners

        public RefreshListeners​(java.util.function.IntSupplier getMaxRefreshListeners,
                                java.lang.Runnable forceRefresh,
                                java.util.concurrent.Executor listenerExecutor,
                                org.apache.logging.log4j.Logger logger,
                                ThreadContext threadContext,
                                MeanMetric refreshMetric)
    • Method Detail

      • forceRefreshes

        public Releasable forceRefreshes()
        Force-refreshes newly added listeners and forces a refresh if there are currently listeners registered. See refreshForcers.
      • addOrNotify

        public boolean addOrNotify​(Translog.Location location,
                                   java.util.function.Consumer<java.lang.Boolean> listener)
        Add a listener for refreshes, calling it immediately if the location is already visible. If this runs out of listener slots then it forces a refresh and calls the listener immediately as well.
        Parameters:
        location - the location to listen for
        listener - for the refresh. Called with true if registering the listener ran it out of slots and forced a refresh. Called with false otherwise.
        Returns:
        did we call the listener (true) or register the listener to call later (false)?
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException
      • refreshNeeded

        public boolean refreshNeeded()
        Returns true if there are pending listeners.
      • pendingCount

        public int pendingCount()
        The number of pending listeners.
      • setCurrentRefreshLocationSupplier

        public void setCurrentRefreshLocationSupplier​(java.util.function.Supplier<Translog.Location> currentRefreshLocationSupplier)
        Setup the translog used to find the last refreshed location.
      • beforeRefresh

        public void beforeRefresh()
                           throws java.io.IOException
        Specified by:
        beforeRefresh in interface org.apache.lucene.search.ReferenceManager.RefreshListener
        Throws:
        java.io.IOException
      • afterRefresh

        public void afterRefresh​(boolean didRefresh)
                          throws java.io.IOException
        Specified by:
        afterRefresh in interface org.apache.lucene.search.ReferenceManager.RefreshListener
        Throws:
        java.io.IOException