Package generic.timer

Class ExpiringSwingTimer

  • All Implemented Interfaces:
    GhidraTimer, java.awt.event.ActionListener, java.util.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 Detail

      • ExpiringSwingTimer

        public ExpiringSwingTimer​(int delay,
                                  int expireMs,
                                  java.util.function.BooleanSupplier isReady,
                                  java.lang.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 Detail

      • runWhen

        public static ExpiringSwingTimer runWhen​(java.util.function.BooleanSupplier isReady,
                                                 int expireMs,
                                                 java.lang.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
      • didRun

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

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