Package sc.fiji.snt

Record Class SNTUtils.BackgroundTask<T>

java.lang.Object
java.lang.Record
sc.fiji.snt.SNTUtils.BackgroundTask<T>
Enclosing class:
SNTUtils

public static record SNTUtils.BackgroundTask<T>(Future<T> future, ExecutorService executor) extends Record
Handle to a task submitted via SNTUtils.submitBackground(java.util.concurrent.Callable<T>, java.lang.String): the running Future plus the single-thread ExecutorService backing it, so a caller can wait on the same future repeatedly (e.g. across a retry-prompt loop) and cancel/shut it down exactly once when done with it.
  • Constructor Details

    • BackgroundTask

      public BackgroundTask(Future<T> future, ExecutorService executor)
      Creates an instance of a BackgroundTask record class.
      Parameters:
      future - the value for the future record component
      executor - the value for the executor record component
  • Method Details

    • cancel

      public void cancel()
      Best-effort cancels future and shuts down executor. No-op if already done.
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • future

      public Future<T> future()
      Returns the value of the future record component.
      Returns:
      the value of the future record component
    • executor

      public ExecutorService executor()
      Returns the value of the executor record component.
      Returns:
      the value of the executor record component