Class WaiterThread<T>

java.lang.Object
java.lang.Thread
i5.las2peer.tools.WaiterThread<T>
Type Parameters:
T -
All Implemented Interfaces:
Runnable

public class WaiterThread<T> extends Thread
A simple thread waiting for a result.
  • Constructor Details

    • WaiterThread

      public WaiterThread(int waitingTime)
      create a new waiter thread with an arbitrary time out value
      Parameters:
      waitingTime -
    • WaiterThread

      public WaiterThread()
      create a new WaiterThread with a default timeout of 10 seconds
  • Method Details

    • run

      public void run()
      the main waiting method
      Specified by:
      run in interface Runnable
      Overrides:
      run in class Thread
    • stopWaiting

      public void stopWaiting()
      stop the main thread from waiting
    • collectResult

      public void collectResult(T result)
      hand over the result to this WaiterThread
      Parameters:
      result -
    • collectException

      public void collectException(Exception e)
      hand over an (occurred) exception to this WaiterThread
      Parameters:
      e -
    • getResult

      public T getResult()
      Returns:
      the collected result, null, if no one has been
    • getException

      public Exception getException()
      Returns:
      a collected exception (if any was collected)
    • isFinished

      public boolean isFinished()
      Returns:
      true, if the thread is finished
    • isSuccess

      public boolean isSuccess()
      Returns:
      true, if the thread is finished and a result is collected
    • hasResult

      public boolean hasResult()
      Returns:
      true, if a result has been collected
    • isTimedOut

      public boolean isTimedOut()
      has this thread time out during waiting for a result?
      Returns:
      true, if the thread is timed out without collecting a result
    • hasException

      public boolean hasException()
      has this thread collected an exception ?
      Returns:
      true, if an exception has been collected