3 namespace Drupal\Core\Queue;
6 * Static queue implementation.
8 * This allows "undelayed" variants of processes relying on the Queue
9 * interface. The queue data resides in memory. It should only be used for
10 * items that will be queued and dequeued within a given page request.
14 class Memory implements QueueInterface {
23 * Counter for item ids.
27 protected $idSequence;
30 * Constructs a Memory object.
33 * An arbitrary string. The name of the queue to work with.
35 public function __construct($name) {
37 $this->idSequence = 0;
43 public function createItem($data) {
44 $item = new \stdClass();
45 $item->item_id = $this->idSequence++;
47 $item->created = time();
49 $this->queue[$item->item_id] = $item;
50 return $item->item_id;
56 public function numberOfItems() {
57 return count($this->queue);
63 public function claimItem($lease_time = 30) {
64 foreach ($this->queue as $key => $item) {
65 if ($item->expire == 0) {
66 $item->expire = time() + $lease_time;
67 $this->queue[$key] = $item;
77 public function deleteItem($item) {
78 unset($this->queue[$item->item_id]);
84 public function releaseItem($item) {
85 if (isset($this->queue[$item->item_id]) && $this->queue[$item->item_id]->expire != 0) {
86 $this->queue[$item->item_id]->expire = 0;
95 public function createQueue() {
96 // Nothing needed here.
102 public function deleteQueue() {
104 $this->idSequence = 0;