Class AsyncLoader


  • public class AsyncLoader
    extends java.lang.Object
    A locking mechanism for loading or reloading an initially unknown number of items. The "producer" is the thread that loads items, informing the Loader when each item is loaded and how many items there are (when that fact becomes known). Other threads can await the completion of a (re)loading process.
    • Constructor Summary

      Constructors 
      Constructor Description
      AsyncLoader​(int timeoutSeconds)
      Create an AsyncLoader with the specified timeout.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void awaitLoadDone()
      Wait upon the consumer to finish loading items.
      void increment()
      Increment the number of items loaded by 1.
      void setNumItems​(java.lang.Integer n)
      Set the number of items.
      void shutdown()  
      void startLoading()
      Acquire the lock as a producer and reset progress-tracking variables.
      • Methods inherited from class java.lang.Object

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

      • AsyncLoader

        public AsyncLoader​(int timeoutSeconds)
        Create an AsyncLoader with the specified timeout. If timeoutSeconds > 0, startLoading() will start a timer that will forcibly unlock the loader after the specified timeout.
    • Method Detail

      • startLoading

        public void startLoading()
        Acquire the lock as a producer and reset progress-tracking variables.
      • increment

        public void increment()
        Increment the number of items loaded by 1. If the number of items is known and that many items have been loaded, unlock the loader. If the loader is not currently loading, does nothing.
      • setNumItems

        public void setNumItems​(java.lang.Integer n)
        Set the number of items. If the number of items already loaded is equal to or greater than the number, unlock the loader.
      • awaitLoadDone

        public void awaitLoadDone()
                           throws java.lang.InterruptedException
        Wait upon the consumer to finish loading items.
        Throws:
        java.lang.InterruptedException - if the thread is interrupted while waiting for the loading lock. This can happen due to timeout.
      • shutdown

        public void shutdown()