Code Coverage  | 
      ||||||||||
Lines  | 
       Functions and Methods  | 
       Classes and Traits  | 
      ||||||||
| Total |         | 
       0.00%  | 
       0 / 16  | 
               | 
       0.00%  | 
       0 / 8  | 
       CRAP |         | 
       0.00%  | 
       0 / 1  | 
      
| InMemoryQueueBroker |         | 
       0.00%  | 
       0 / 16  | 
               | 
       0.00%  | 
       0 / 8  | 
       110 |         | 
       0.00%  | 
       0 / 1  | 
      
| getQueue |         | 
       0.00%  | 
       0 / 3  | 
               | 
       0.00%  | 
       0 / 1  | 
       6 | |||
| createQueue |         | 
       0.00%  | 
       0 / 2  | 
               | 
       0.00%  | 
       0 / 1  | 
       2 | |||
| count |         | 
       0.00%  | 
       0 / 1  | 
               | 
       0.00%  | 
       0 / 1  | 
       2 | |||
| push |         | 
       0.00%  | 
       0 / 2  | 
               | 
       0.00%  | 
       0 / 1  | 
       2 | |||
| pop |         | 
       0.00%  | 
       0 / 4  | 
               | 
       0.00%  | 
       0 / 1  | 
       6 | |||
| doPop |         | 
       0.00%  | 
       0 / 1  | 
               | 
       0.00%  | 
       0 / 1  | 
       2 | |||
| delete |         | 
       0.00%  | 
       0 / 1  | 
               | 
       0.00%  | 
       0 / 1  | 
       2 | |||
| doDelete |         | 
       0.00%  | 
       0 / 2  | 
               | 
       0.00%  | 
       0 / 1  | 
       2 | |||
| 1 | <?php | 
| 2 | |
| 3 | /** | 
| 4 | * This program is free software; you can redistribute it and/or | 
| 5 | * modify it under the terms of the GNU General Public License | 
| 6 | * as published by the Free Software Foundation; under version 2 | 
| 7 | * of the License (non-upgradable). | 
| 8 | * | 
| 9 | * This program is distributed in the hope that it will be useful, | 
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 
| 12 | * GNU General Public License for more details. | 
| 13 | * | 
| 14 | * You should have received a copy of the GNU General Public License | 
| 15 | * along with this program; if not, write to the Free Software | 
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 
| 17 | * | 
| 18 | * Copyright (c) 2017 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); | 
| 19 | * | 
| 20 | */ | 
| 21 | |
| 22 | namespace oat\taoTaskQueue\model\QueueBroker; | 
| 23 | |
| 24 | use oat\tao\model\taskQueue\Queue\Broker\AbstractQueueBroker; | 
| 25 | use oat\tao\model\taskQueue\Task\TaskInterface; | 
| 26 | |
| 27 | /** | 
| 28 | * Stores tasks in memory. It accomplishes Sync Queue mechanism. | 
| 29 | * | 
| 30 | * @deprecated Use \oat\tao\model\taskQueue\Queue\Broker\InMemoryQueueBroker | 
| 31 | * | 
| 32 | * @author Gyula Szucs <gyula@taotesting.com> | 
| 33 | */ | 
| 34 | class InMemoryQueueBroker extends AbstractQueueBroker implements SyncQueueBrokerInterface | 
| 35 | { | 
| 36 | /** | 
| 37 | * @var \SplQueue | 
| 38 | */ | 
| 39 | private $queue; | 
| 40 | |
| 41 | /** | 
| 42 | * @return \SplQueue | 
| 43 | */ | 
| 44 | private function getQueue() | 
| 45 | { | 
| 46 | if (is_null($this->queue)) { | 
| 47 | $this->createQueue(); | 
| 48 | } | 
| 49 | return $this->queue; | 
| 50 | } | 
| 51 | |
| 52 | /** | 
| 53 | * Initiates the SplQueue | 
| 54 | */ | 
| 55 | public function createQueue() | 
| 56 | { | 
| 57 | $this->queue = new \SplQueue(); | 
| 58 | $this->logDebug('Memory Queue created'); | 
| 59 | } | 
| 60 | |
| 61 | /** | 
| 62 | * @return int | 
| 63 | */ | 
| 64 | public function count() | 
| 65 | { | 
| 66 | return $this->getQueue()->count(); | 
| 67 | } | 
| 68 | |
| 69 | /** | 
| 70 | * @param TaskInterface $task | 
| 71 | * @return bool | 
| 72 | */ | 
| 73 | public function push(TaskInterface $task) | 
| 74 | { | 
| 75 | $this->getQueue()->enqueue($this->serializeTask($task)); | 
| 76 | |
| 77 | return true; | 
| 78 | } | 
| 79 | |
| 80 | /** | 
| 81 | * Overwriting the parent totally because in this case we need a much simpler logic for popping messages. | 
| 82 | * | 
| 83 | * @return mixed|null | 
| 84 | */ | 
| 85 | public function pop() | 
| 86 | { | 
| 87 | if (!$this->count()) { | 
| 88 | return null; | 
| 89 | } | 
| 90 | |
| 91 | $task = $this->getQueue()->dequeue(); | 
| 92 | |
| 93 | return $this->unserializeTask($task, ''); | 
| 94 | } | 
| 95 | |
| 96 | /** | 
| 97 | * Do nothing. | 
| 98 | */ | 
| 99 | protected function doPop() | 
| 100 | { | 
| 101 | } | 
| 102 | |
| 103 | /** | 
| 104 | * Do nothing, because dequeue automatically deletes the message from the queue | 
| 105 | * | 
| 106 | * @param TaskInterface $task | 
| 107 | */ | 
| 108 | public function delete(TaskInterface $task) | 
| 109 | { | 
| 110 | } | 
| 111 | |
| 112 | /** | 
| 113 | * Do nothing. | 
| 114 | * | 
| 115 | * @param string $receipt | 
| 116 | * @param array $logContext | 
| 117 | */ | 
| 118 | protected function doDelete($receipt, array $logContext = []) | 
| 119 | { | 
| 120 | } | 
| 121 | } |