Package generic.timer

Class ExpiringSwingTimer

java.lang.Object
generic.timer.GhidraSwingTimer
generic.timer.ExpiringSwingTimer
All Implemented Interfaces:
GhidraTimer, ActionListener, EventListener

public class ExpiringSwingTimer extends GhidraSwingTimer
This class allows clients to run swing action at some point in the future, when the given condition is met, allowing for the task to timeout. While this class implements the GhidraTimer interface, it is really meant to be used to execute a code snippet one time at some point in the future.

Both the call to check for readiness and the actual client code will be run on the Swing thread.

  • Constructor Details

    • ExpiringSwingTimer

      public ExpiringSwingTimer(int delay, int expireMs, BooleanSupplier isReady, Runnable runnable)
      Constructor

      Note: this class sets the parent's initial delay to 0. This is to allow the client code to be executed without delay when the ready condition is true.

      Parameters:
      delay - the delay between calls to check isReady
      isReady - true if the code should be run
      expireMs - the amount of time past which the code will not be run
      runnable - the code to run
  • Method Details

    • runWhen

      public static ExpiringSwingTimer runWhen(BooleanSupplier isReady, int expireMs, Runnable runnable)
      Runs the given client runnable when the given condition returns true. The returned timer will be running.

      Once the timer has performed the work, any calls to start the returned timer will not perform any work. You can check didRun() to see if the work has been completed.

      Parameters:
      isReady - true if the code should be run
      expireMs - the amount of time past which the code will not be run
      runnable - the code to run
      Returns:
      the timer object that is running, which will execute the given code when ready
    • get

      public static <T> ExpiringSwingTimer get(Supplier<T> supplier, int expireMs, Consumer<T> consumer)
      Calls the given consumer with the non-null value returned from the given supplier. The returned timer will be running.

      Once the timer has performed the work, any calls to start the returned timer will not perform any work. You can check didRun() to see if the work has been completed.

      Type Parameters:
      T - the type used by the supplier and consumer
      Parameters:
      supplier - the supplier of the desired value
      expireMs - the amount of time past which the code will not be run
      consumer - the consumer to be called with the supplier's value
      Returns:
      the timer object that is running, which will execute the given code when ready
    • didRun

      public boolean didRun()
      Returns true if the client runnable was run
      Returns:
      true if the client runnable was run
    • start

      public void start()
      Specified by:
      start in interface GhidraTimer
      Overrides:
      start in class GhidraSwingTimer
    • isExpired

      public boolean isExpired()
      Returns true the initial expiration period has passed
      Returns:
      true if expired
    • setTimerCallback

      public void setTimerCallback(TimerCallback callback)
      Specified by:
      setTimerCallback in interface GhidraTimer
      Overrides:
      setTimerCallback in class GhidraSwingTimer