GenisysPro  for Minecraft PE/Windows 10 v1.1.x
Feature-rich server software for Minecraft PE and Windows 10 Edition
ServerScheduler Class Reference

Public Member Functions

 __construct ()
 
 scheduleTask (Task $task)
 
 scheduleAsyncTask (AsyncTask $task)
 
 scheduleAsyncTaskToWorker (AsyncTask $task, $worker)
 
 getAsyncTaskPoolSize ()
 
 increaseAsyncTaskPoolSize ($newSize)
 
 scheduleDelayedTask (Task $task, $delay)
 
 scheduleRepeatingTask (Task $task, $period)
 
 scheduleDelayedRepeatingTask (Task $task, $delay, $period)
 
 cancelTask ($taskId)
 
 cancelTasks (Plugin $plugin)
 
 cancelAllTasks ()
 
 isQueued ($taskId)
 

Static Public Attributes

static $WORKERS = 2
 

Protected Attributes

 $queue
 
 $tasks = []
 
 $asyncPool
 
 $currentTick = 0
 

Constructor & Destructor Documentation

◆ __construct()

__construct ( )

ServerScheduler constructor.

57  {
58  $this->queue = new ReversePriorityQueue();
59  $this->asyncPool = new AsyncPool(Server::getInstance(), self::$WORKERS);
60  }

Member Function Documentation

◆ cancelAllTasks()

cancelAllTasks ( )
166  {
167  foreach($this->tasks as $task){
168  $task->cancel();
169  }
170  $this->tasks = [];
171  $this->asyncPool->removeTasks();
172  while(!$this->queue->isEmpty()){
173  $this->queue->extract();
174  }
175  $this->ids = 1;
176  }

◆ cancelTask()

cancelTask (   $taskId)
Parameters
int$taskId
146  {
147  if($taskId !== null and isset($this->tasks[$taskId])){
148  $this->tasks[$taskId]->cancel();
149  unset($this->tasks[$taskId]);
150  }
151  }

◆ cancelTasks()

cancelTasks ( Plugin  $plugin)
Parameters
Plugin$plugin
156  {
157  foreach($this->tasks as $taskId => $task){
158  $ptask = $task->getTask();
159  if($ptask instanceof PluginTask and $ptask->getOwner() === $plugin){
160  $task->cancel();
161  unset($this->tasks[$taskId]);
162  }
163  }
164  }

◆ getAsyncTaskPoolSize()

getAsyncTaskPoolSize ( )
Returns
int
101  {
102  return $this->asyncPool->getSize();
103  }

◆ increaseAsyncTaskPoolSize()

increaseAsyncTaskPoolSize (   $newSize)
Parameters
$newSize
108  {
109  $this->asyncPool->increaseSize($newSize);
110  }

◆ isQueued()

isQueued (   $taskId)
Parameters
int$taskId
Returns
bool
183  {
184  return isset($this->tasks[$taskId]);
185  }

◆ scheduleAsyncTask()

scheduleAsyncTask ( AsyncTask  $task)

Submits an asynchronous task to the Worker Pool

Parameters
AsyncTask$task
Returns
void
78  {
79  $id = $this->nextId();
80  $task->setTaskId($id);
81  $this->asyncPool->submitTask($task);
82  }

◆ scheduleAsyncTaskToWorker()

scheduleAsyncTaskToWorker ( AsyncTask  $task,
  $worker 
)

Submits an asynchronous task to a specific Worker in the Pool

Parameters
AsyncTask$task
int$worker
Returns
void
92  {
93  $id = $this->nextId();
94  $task->setTaskId($id);
95  $this->asyncPool->submitTaskToWorker($task, $worker);
96  }

◆ scheduleDelayedRepeatingTask()

scheduleDelayedRepeatingTask ( Task  $task,
  $delay,
  $period 
)
Parameters
Task$task
int$delay
int$period
Returns
null|TaskHandler
139  {
140  return $this->addTask($task, (int) $delay, (int) $period);
141  }

◆ scheduleDelayedTask()

scheduleDelayedTask ( Task  $task,
  $delay 
)
Parameters
Task$task
int$delay
Returns
null|TaskHandler
118  {
119  return $this->addTask($task, (int) $delay, -1);
120  }

◆ scheduleRepeatingTask()

scheduleRepeatingTask ( Task  $task,
  $period 
)
Parameters
Task$task
int$period
Returns
null|TaskHandler
128  {
129  return $this->addTask($task, -1, (int) $period);
130  }

◆ scheduleTask()

scheduleTask ( Task  $task)
Parameters
Task$task
Returns
null|TaskHandler
67  {
68  return $this->addTask($task, -1, -1);
69  }

Field Documentation

◆ $asyncPool

$asyncPool
protected

◆ $currentTick

$currentTick = 0
protected

◆ $queue

$queue
protected

◆ $tasks

$tasks = []
protected

◆ $WORKERS

$WORKERS = 2
static

The documentation for this class was generated from the following file: