Kanzi  3.9.5
Java API
MainLoopScheduler Class Reference

MainLoopScheduler implements the Kanzi application main loop in form of a sequence of stages, each consisting of a sequence of tasks, where a task is a callable method. More...

Classes

class  Stage
 Stage instance represent a Stage in the Kanzi main loop. More...
 
interface  Task
 A task that can be added for one-time or repeated execution by MainLoopScheduler. More...
 
class  TaskToken
 The token of the task. More...
 
interface  TimerTask
 A task that can be scheduled for one-time or repeated execution by MainLoopScheduler. More...
 
class  TimerToken
 The token of the timer task. More...
 

Public Member Functions

TaskToken appendTask (Stage stage, String name, TaskRecurrence recurrence, Task task)
 Adds a task to the back of a stage. More...
 
TimerToken appendTimer (Stage stage, String name, TimerRecurrence recurrence, Duration interval, TimerTask task)
 Adds a timer task to be executed after a stage in the main loop. More...
 
void clearTasks (Stage stage)
 Removes all tasks in a stage. More...
 
void enableSuspendWhenIdle (boolean suspendEnabled)
 Sets whether an application allows suspension. More...
 
boolean isCurrentFrameRendered ()
 Returns whether rendering was performed in the current frame. More...
 
boolean isSuspendWhenIdleEnabled ()
 Returns whether an application allows suspension. More...
 
TaskToken prependTask (Stage stage, String name, TaskRecurrence recurrence, Task task)
 Adds a task to the front of a stage. More...
 
TimerToken prependTimer (Stage stage, String name, TimerRecurrence recurrence, Duration interval, TimerTask task)
 Adds a timer task to be executed before a stage in the main loop. More...
 
boolean removeTask (Stage stage, TaskToken token)
 Removes a task from a stage. More...
 
boolean removeTimer (TimerToken token)
 Removes a timer task from the main loop. More...
 
boolean replaceTask (Stage stage, TaskToken token, Task task)
 Replaces a task in a stage with another one. More...
 
void setCurrentFrameRendered ()
 Sets whether rendering was performed in the current frame. More...
 
void setFrameRateLimit (long frameRate)
 Sets the frame rate limit of the application. More...
 

Static Public Attributes

static Stage AnimateStage
 Stage for ticking animations.
 
static Stage InputStage
 Stage for handling input events.
 
static Stage LayoutStage
 Stage for laying out the nodes.
 
static Stage PresentStage
 Stage for presenting the nodes.
 
static Stage RenderStage
 Stage for rendering the nodes.
 
static Stage UserStage
 Stage for executing your application code. More...
 

Detailed Description

MainLoopScheduler implements the Kanzi application main loop in form of a sequence of stages, each consisting of a sequence of tasks, where a task is a callable method.

You can customize the application main loop by extending its stages with additional tasks, replacing existing tasks with your own implementations or adding timer tasks to execute some functionality at regular intervals.

All objects and subsystems in Kanzi are associated with a domain when created. Objects in the same domain share access to the same subsystems. Objects from different domains cannot be used together.

Member Function Documentation

◆ appendTask()

TaskToken appendTask ( Stage  stage,
String  name,
TaskRecurrence  recurrence,
Task  task 
)

Adds a task to the back of a stage.

Parameters
stageThe stage where to add the task.
nameName for the task.
recurrenceRecurrence choice for the task that you want to insert.
taskThe task that you want to insert.
Returns
Token of the added task. You can use that token to remove or replace the task.

◆ appendTimer()

TimerToken appendTimer ( Stage  stage,
String  name,
TimerRecurrence  recurrence,
Duration  interval,
TimerTask  task 
)

Adds a timer task to be executed after a stage in the main loop.

Parameters
stageThe stage where to add the task.
nameName for the task.
recurrenceRecurrence choice for the task that you want to insert.
intervalThe amount of time after which to execute the task.
taskThe task that you want to insert.
Returns
Token of the added task. You can use that token to remove the task.

◆ clearTasks()

void clearTasks ( Stage  stage)

Removes all tasks in a stage.

Parameters
stageThe stage where to remove the tasks.

◆ enableSuspendWhenIdle()

void enableSuspendWhenIdle ( boolean  suspendEnabled)

Sets whether an application allows suspension.

Parameters
suspendEnabledIf the application allows suspension, use true, otherwise false.

◆ isCurrentFrameRendered()

boolean isCurrentFrameRendered ( )

Returns whether rendering was performed in the current frame.

The main loop uses this as a precondition for executing the Present stage for a frame.

Returns
If rendering was performed in the current frame, true, otherwise false.

◆ isSuspendWhenIdleEnabled()

boolean isSuspendWhenIdleEnabled ( )

Returns whether an application allows suspension.

Returns
If the application allows suspension, true, otherwise false.

◆ prependTask()

TaskToken prependTask ( Stage  stage,
String  name,
TaskRecurrence  recurrence,
Task  task 
)

Adds a task to the front of a stage.

Parameters
stageThe stage where to add the task.
nameName for the task.
recurrenceRecurrence choice for the task that you want to insert.
taskThe task that you want to insert.
Returns
Token of the added task. You can use that token to remove or replace the task.

◆ prependTimer()

TimerToken prependTimer ( Stage  stage,
String  name,
TimerRecurrence  recurrence,
Duration  interval,
TimerTask  task 
)

Adds a timer task to be executed before a stage in the main loop.

Parameters
stageThe stage where to add the task.
nameName for the task.
recurrenceRecurrence choice for the task that you want to insert.
intervalThe amount of time after which to execute the task.
taskThe task that you want to insert.
Returns
Token of the added task. You can use that token to remove the task.

◆ removeTask()

boolean removeTask ( Stage  stage,
TaskToken  token 
)

Removes a task from a stage.

Parameters
stageThe stage where to remove the task.
tokenToken of the task.
Returns
If removal is successful, returns true. If the function cannot find the matching token, returns false.

◆ removeTimer()

boolean removeTimer ( TimerToken  token)

Removes a timer task from the main loop.

Parameters
tokenToken of the task.
Returns
If removal is successful, returns true. If the function cannot find the matching token, returns false.

◆ replaceTask()

boolean replaceTask ( Stage  stage,
TaskToken  token,
Task  task 
)

Replaces a task in a stage with another one.

Parameters
stageThe stage where to replace the task.
tokenToken of the task.
taskThe task with which to replace the current task.
Returns
If replacement is successful, returns true. If the function cannot find the matching token, returns false.

◆ setCurrentFrameRendered()

void setCurrentFrameRendered ( )

Sets whether rendering was performed in the current frame.

Call this function from a task in the Render stage to inform the main loop that the task performed rendering. The main loop uses this as a precondition for executing the Present stage for a frame.

◆ setFrameRateLimit()

void setFrameRateLimit ( long  frameRate)

Sets the frame rate limit of the application.

This sets an upper limit on the number of frames rendered by Kanzi every second.

Parameters
frameRateThe number of frames to render every second. To disable frame rate limit, use 0.

Member Data Documentation

◆ UserStage

Stage UserStage
static

Stage for executing your application code.

Includes:

  • Task dispatcher tasks
  • Resource deployment
  • kzb file and prefab loading