2016-08-22 06:40:48 +02:00
|
|
|
<?php declare(strict_types = 1);
|
2016-08-18 18:04:48 +02:00
|
|
|
|
2016-08-23 23:47:40 +02:00
|
|
|
namespace Amp\Parallel\Worker;
|
2015-08-14 19:25:07 +02:00
|
|
|
|
|
|
|
/**
|
2015-12-05 06:50:32 +01:00
|
|
|
* An interface for worker pools.
|
2015-08-14 19:25:07 +02:00
|
|
|
*/
|
2016-08-18 18:04:48 +02:00
|
|
|
interface Pool extends Worker {
|
2015-12-16 22:53:53 +01:00
|
|
|
/**
|
|
|
|
* @var int The default minimum pool size.
|
|
|
|
*/
|
|
|
|
const DEFAULT_MIN_SIZE = 4;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var int The default maximum pool size.
|
|
|
|
*/
|
|
|
|
const DEFAULT_MAX_SIZE = 32;
|
|
|
|
|
2016-01-15 01:54:53 +01:00
|
|
|
/**
|
|
|
|
* Gets a worker from the pool. The worker is marked as busy and will only be reused if the pool runs out of
|
|
|
|
* idle workers. The worker will be automatically marked as idle once no references to the returned worker remain.
|
|
|
|
*
|
2016-08-23 23:47:40 +02:00
|
|
|
* @return \Amp\Parallel\Worker\Worker
|
2016-01-15 01:54:53 +01:00
|
|
|
*
|
2016-08-23 23:47:40 +02:00
|
|
|
* @throws \Amp\Parallel\StatusError If the queue is not running.
|
2016-01-15 01:54:53 +01:00
|
|
|
*/
|
2016-01-23 07:00:56 +01:00
|
|
|
public function get(): Worker;
|
2016-01-15 01:54:53 +01:00
|
|
|
|
2015-08-29 03:30:53 +02:00
|
|
|
/**
|
2015-12-05 06:50:32 +01:00
|
|
|
* Gets the number of workers currently running in the pool.
|
2015-08-28 05:51:50 +02:00
|
|
|
*
|
2015-12-05 06:50:32 +01:00
|
|
|
* @return int The number of workers.
|
2015-08-28 05:51:50 +02:00
|
|
|
*/
|
2016-01-23 07:00:56 +01:00
|
|
|
public function getWorkerCount(): int;
|
2015-08-28 05:51:50 +02:00
|
|
|
|
|
|
|
/**
|
2015-12-05 06:50:32 +01:00
|
|
|
* Gets the number of workers that are currently idle.
|
2015-08-28 05:51:50 +02:00
|
|
|
*
|
2015-12-05 06:50:32 +01:00
|
|
|
* @return int The number of idle workers.
|
2015-08-28 05:51:50 +02:00
|
|
|
*/
|
2016-01-23 07:00:56 +01:00
|
|
|
public function getIdleWorkerCount(): int;
|
2015-12-16 22:53:53 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the minimum number of workers the pool may have idle.
|
|
|
|
*
|
|
|
|
* @return int The minimum number of workers.
|
|
|
|
*/
|
2016-01-23 07:00:56 +01:00
|
|
|
public function getMinSize(): int;
|
2015-12-16 22:53:53 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the maximum number of workers the pool may spawn to handle concurrent tasks.
|
|
|
|
*
|
|
|
|
* @return int The maximum number of workers.
|
|
|
|
*/
|
2016-01-23 07:00:56 +01:00
|
|
|
public function getMaxSize(): int;
|
2015-08-14 19:25:07 +02:00
|
|
|
}
|