class Memory in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/lib/Drupal/Core/Queue/Memory.php \Drupal\Core\Queue\Memory
Static queue implementation.
This allows "undelayed" variants of processes relying on the Queue interface. The queue data resides in memory. It should only be used for items that will be queued and dequeued within a given page request.
Hierarchy
- class \Drupal\Core\Queue\Memory implements QueueInterface
Expanded class hierarchy of Memory
Related topics
1 file declares its use of Memory
- QueueTest.php in core/
modules/ system/ src/ Tests/ Queue/ QueueTest.php - Contains \Drupal\system\Tests\Queue\QueueTest.
File
- core/
lib/ Drupal/ Core/ Queue/ Memory.php, line 19 - Contains \Drupal\Core\Queue\Memory.
Namespace
Drupal\Core\QueueView source
class Memory implements QueueInterface {
/**
* The queue data.
*
* @var array
*/
protected $queue;
/**
* Counter for item ids.
*
* @var int
*/
protected $idSequence;
/**
* Constructs a Memory object.
*
* @param string $name
* An arbitrary string. The name of the queue to work with.
*/
public function __construct($name) {
$this->queue = array();
$this->idSequence = 0;
}
/**
* {@inheritdoc}
*/
public function createItem($data) {
$item = new \stdClass();
$item->item_id = $this->idSequence++;
$item->data = $data;
$item->created = time();
$item->expire = 0;
$this->queue[$item->item_id] = $item;
return $item->item_id;
}
/**
* {@inheritdoc}
*/
public function numberOfItems() {
return count($this->queue);
}
/**
* {@inheritdoc}
*/
public function claimItem($lease_time = 30) {
foreach ($this->queue as $key => $item) {
if ($item->expire == 0) {
$item->expire = time() + $lease_time;
$this->queue[$key] = $item;
return $item;
}
}
return FALSE;
}
/**
* {@inheritdoc}
*/
public function deleteItem($item) {
unset($this->queue[$item->item_id]);
}
/**
* {@inheritdoc}
*/
public function releaseItem($item) {
if (isset($this->queue[$item->item_id]) && $this->queue[$item->item_id]->expire != 0) {
$this->queue[$item->item_id]->expire = 0;
return TRUE;
}
return FALSE;
}
/**
* {@inheritdoc}
*/
public function createQueue() {
// Nothing needed here.
}
/**
* {@inheritdoc}
*/
public function deleteQueue() {
$this->queue = array();
$this->idSequence = 0;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Memory:: |
protected | property | Counter for item ids. | |
Memory:: |
protected | property | The queue data. | |
Memory:: |
public | function |
Claims an item in the queue for processing. Overrides QueueInterface:: |
1 |
Memory:: |
public | function |
Adds a queue item and store it directly to the queue. Overrides QueueInterface:: |
|
Memory:: |
public | function |
Creates a queue. Overrides QueueInterface:: |
|
Memory:: |
public | function |
Deletes a finished item from the queue. Overrides QueueInterface:: |
|
Memory:: |
public | function |
Deletes a queue and every item in the queue. Overrides QueueInterface:: |
|
Memory:: |
public | function |
Retrieves the number of items in the queue. Overrides QueueInterface:: |
|
Memory:: |
public | function |
Releases an item that the worker could not process. Overrides QueueInterface:: |
|
Memory:: |
public | function | Constructs a Memory object. |