Class GameTaskQueue

java.lang.Object
com.ardor3d.util.GameTaskQueue

public class GameTaskQueue extends Object
GameTaskQueue is a simple queuing system to enqueue tasks that need to be accomplished in a specific thread or phase of the application execution (for example, the OpenGL rendering thread.) Upon sending in a task, the caller gets back a Future object useful for retrieving a return from the Callable that was passed in.
See Also:
  • Field Details

  • Constructor Details

    • GameTaskQueue

      public GameTaskQueue()
  • Method Details

    • addExecutionExceptionListener

      public void addExecutionExceptionListener(GameTaskQueue.ExecutionExceptionListener l)
    • removeExecutionExceptionListener

      public boolean removeExecutionExceptionListener(GameTaskQueue.ExecutionExceptionListener l)
    • isExecuteAll

      public boolean isExecuteAll()
      The state of this GameTaskQueue if it will execute all enqueued Callables on an execute invokation.
      Returns:
      boolean
    • setExecuteMultiple

      public void setExecuteMultiple(boolean executeMultiple)
      Parameters:
      executeMultiple - if false, only one task at most is executed per call to execute. If true, we will execute as many tasks as are available, bounded by the max execution time.
      See Also:
    • setExecutionTime

      public void setExecutionTime(int msecs)
      Sets the minimum amount of time the queue will execute tasks per frame. If this is set, executeMultiple is automatically set to true and the execute() loop will execute as many tasks as it can before the execution window threshold is passed. Any remaining tasks will be executed in the following frame.
      Parameters:
      msecs - the maximum number of milliseconds to start tasks. Note that this does not guarantee the tasks will finish under this time, only start.
    • getExecutionTime

      public long getExecutionTime()
      min time queue is permitted to execute tasks per frame
      Returns:
      -1 if executeAll is false, else min time allocated for task execution per frame
    • enqueue

      public <V> Future<V> enqueue(Callable<V> callable)
      Adds the Callable to the internal queue to invoked and returns a Future that wraps the return. This is useful for checking the status of the task as well as being able to retrieve the return object from Callable asynchronously.
      Type Parameters:
      V - the return type of the callable
      Parameters:
      callable - the callable to enqueue
      Returns:
      the task
    • enqueue

      public <V> void enqueue(GameTask<V> task)
      Adds the given task to the internal queue to be invoked later.
      Type Parameters:
      V - the return type of the task
      Parameters:
      task - the task
    • execute

      public void execute()
      Execute the tasks from this queue. Note that depending on the queue type, tasks may expect to be run in a certain context (for example, the Render queue expects to be run from the Thread owning a GL context.)
    • execute

      public void execute(Renderer renderer)
      Execute the tasks from this queue. Note that depending on the queue type, tasks may expect to be run in a certain context (for example, the Render queue expects to be run from the Thread owning a GL context.)
      Parameters:
      renderer - the renderer
    • clear

      public void clear()
      Remove all tasks from this queue without executing them.
    • enqueueAll

      public void enqueueAll(GameTaskQueue queue)
      Move the tasks from the given queue to this one.
      Parameters:
      queue - the queue containing the tasks to move
    • size

      public int size()
      Returns:
      count of tasks in queue.