Package smile.util

Class IterativeAlgorithmController<T>

java.lang.Object
smile.util.IterativeAlgorithmController<T>
Type Parameters:
T - the type of algorithm progress status objects.
All Implemented Interfaces:
AutoCloseable

public class IterativeAlgorithmController<T> extends Object implements AutoCloseable
A controller for iterative algorithms.
  • Constructor Details

    • IterativeAlgorithmController

      public IterativeAlgorithmController()
      Constructor.
    • IterativeAlgorithmController

      public IterativeAlgorithmController(Executor executor, int maxBufferCapacity)
      Constructor.
      Parameters:
      executor - the executor to use for async delivery, supporting creation of at least one independent thread.
      maxBufferCapacity - the maximum capacity for each subscriber's buffer.
  • Method Details

    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
    • isInterrupted

      public final boolean isInterrupted()
      Checks if keep algorithm going.
      Returns:
      true if keep algorithm going; false to early stop.
    • stop

      public void stop()
      Early stops the algorithm.
    • subscribe

      public void subscribe(Flow.Subscriber<T> subscriber)
      Adds the given subscriber for algorithm progress.
      Parameters:
      subscriber - the subscriber.
    • submit

      public void submit(T status)
      Publishes the algorithm status to each current subscriber asynchronously.
      Parameters:
      status - the algorithm progress information.