Interface TaskListener

All Known Subinterfaces:
OnceTaskListener

public interface TaskListener
Task listener callback, used in scenarios such as: one-time delayed tasks, scheduled tasks, lightweight controllable delayed tasks, lightweight periodic persistence helper functions, and other extended scenarios. Documentation
These usage scenarios share a common feature: listener callbacks. The interface provides 4 methods, as follows:
1. CommonTaskListener.onUpdate(), listener callback
2. CommonTaskListener.triggerUpdate(), whether to trigger the CommonTaskListener.onUpdate() listener callback method
3. CommonTaskListener.onException(Throwable) , exception callback. If an exception is thrown during the execution of CommonTaskListener.triggerUpdate() and CommonTaskListener.onUpdate() methods, it will be caught by this method.
4. CommonTaskListener.getExecutor(), specify the executor to run the above methods, with the goal of not occupying business threads.
Since:
21.9
Author:
渔民小镇
date:
2023-12-06
  • Method Summary

    Modifier and Type
    Method
    Description
    default Executor
    The executor for executing onUpdate
    default void
    Exception callback
    void
    Timer listener callback
    default boolean
    Whether to trigger the onUpdate listener callback method
  • Method Details

    • triggerUpdate

      default boolean triggerUpdate()
      Whether to trigger the onUpdate listener callback method
      Returns:
      true to execute the onUpdate method
    • onUpdate

      void onUpdate()
      Timer listener callback
    • onException

      default void onException(Throwable e)
      Exception callback
      When the triggerUpdate or onUpdate method throws an exception, it will be passed here.
      
      Parameters:
      e - e
    • getExecutor

      default Executor getExecutor()
      The executor for executing onUpdate
      If null is returned, it will be executed within HashedWheelTimer.
      
      If there are time-consuming tasks, such as those involving IO operations, it is recommended to specify an executor to run the current callback (onUpdate method) to avoid blocking other tasks.
      
      Example
      default Executor getExecutor() {
      // Time-consuming task, specify an executor to consume the current onUpdate
      return TaskKit.getCacheExecutor();
      }
      
      
      Returns:
      If the return value is null, execution will use the current thread (default HashedWheelTimer), otherwise, the specified executor will be used.