Class TaskManager

  • All Implemented Interfaces:
    ITaskManager

    public final class TaskManager
    extends AbstractLogger
    implements ITaskManager
    This class uses Java scheduler (ScheduledFuture) to manage your tasks. The scheduler is used to schedule a thread or task that executes at a certain period of time or periodically at a fixed interval. It's useful when you want to create a time counter before starting a match or send messages periodically for one player.
    Author:
    kong
    See Also:
    ITaskManager
    • Constructor Summary

      Constructors 
      Constructor Description
      TaskManager()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()
      Kill or stop all running tasks.
      void create​(java.lang.String id, java.util.concurrent.ScheduledFuture<?> task)
      Create a new task.
      int getRemainTime​(java.lang.String id)
      Retrieve the remain time of one task.
      void kill​(java.lang.String id)
      Kill or stop a running task.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • TaskManager

        public TaskManager()
    • Method Detail

      • create

        public void create​(java.lang.String id,
                           java.util.concurrent.ScheduledFuture<?> task)
        Description copied from interface: ITaskManager
        Create a new task.
        Specified by:
        create in interface ITaskManager
        Parameters:
        id - the unique id for management
        task - the running task, see ScheduledFuture
      • kill

        public void kill​(java.lang.String id)
        Description copied from interface: ITaskManager
        Kill or stop a running task.
        Specified by:
        kill in interface ITaskManager
        Parameters:
        id - the unique id
      • clear

        public void clear()
        Description copied from interface: ITaskManager
        Kill or stop all running tasks.
        Specified by:
        clear in interface ITaskManager
      • getRemainTime

        public int getRemainTime​(java.lang.String id)
        Description copied from interface: ITaskManager
        Retrieve the remain time of one task.
        Specified by:
        getRemainTime in interface ITaskManager
        Parameters:
        id - the unique for retrieving the desired task
        Returns:
        the left time