|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Enqueue\Consumption\Context; |
| 4 | + |
| 5 | +use Enqueue\Consumption\BoundProcessor; |
| 6 | +use Interop\Queue\Context; |
| 7 | +use Psr\Log\LoggerInterface; |
| 8 | + |
| 9 | +final class Start |
| 10 | +{ |
| 11 | + /** |
| 12 | + * @var Context |
| 13 | + */ |
| 14 | + private $context; |
| 15 | + |
| 16 | + /** |
| 17 | + * @var LoggerInterface |
| 18 | + */ |
| 19 | + private $logger; |
| 20 | + |
| 21 | + /** |
| 22 | + * @var BoundProcessor[] |
| 23 | + */ |
| 24 | + private $processors; |
| 25 | + |
| 26 | + /** |
| 27 | + * @var int |
| 28 | + */ |
| 29 | + private $receiveTimeout; |
| 30 | + |
| 31 | + /** |
| 32 | + * @var int |
| 33 | + */ |
| 34 | + private $idleTime; |
| 35 | + |
| 36 | + /** |
| 37 | + * @var int |
| 38 | + */ |
| 39 | + private $startTime; |
| 40 | + |
| 41 | + /** |
| 42 | + * @var bool |
| 43 | + */ |
| 44 | + private $executionInterrupted; |
| 45 | + |
| 46 | + /** |
| 47 | + * @param BoundProcessor[] $processors |
| 48 | + */ |
| 49 | + public function __construct(Context $context, LoggerInterface $logger, array $processors, int $receiveTimeout, int $idleTime, int $startTime) |
| 50 | + { |
| 51 | + $this->context = $context; |
| 52 | + $this->logger = $logger; |
| 53 | + $this->processors = $processors; |
| 54 | + $this->receiveTimeout = $receiveTimeout; |
| 55 | + $this->idleTime = $idleTime; |
| 56 | + $this->startTime = $startTime; |
| 57 | + |
| 58 | + $this->executionInterrupted = false; |
| 59 | + } |
| 60 | + |
| 61 | + public function getInteropContext(): Context |
| 62 | + { |
| 63 | + return $this->context; |
| 64 | + } |
| 65 | + |
| 66 | + public function getLogger(): LoggerInterface |
| 67 | + { |
| 68 | + return $this->logger; |
| 69 | + } |
| 70 | + |
| 71 | + public function changeLogger(LoggerInterface $logger): void |
| 72 | + { |
| 73 | + $this->logger = $logger; |
| 74 | + } |
| 75 | + |
| 76 | + /** |
| 77 | + * In milliseconds. |
| 78 | + */ |
| 79 | + public function getReceiveTimeout(): int |
| 80 | + { |
| 81 | + return $this->receiveTimeout; |
| 82 | + } |
| 83 | + |
| 84 | + /** |
| 85 | + * In milliseconds. |
| 86 | + */ |
| 87 | + public function changeReceiveTimeout(int $timeout): void |
| 88 | + { |
| 89 | + $this->receiveTimeout = $timeout; |
| 90 | + } |
| 91 | + |
| 92 | + /** |
| 93 | + * In milliseconds. |
| 94 | + */ |
| 95 | + public function getIdleTime(): int |
| 96 | + { |
| 97 | + return $this->idleTime; |
| 98 | + } |
| 99 | + |
| 100 | + /** |
| 101 | + * In milliseconds. |
| 102 | + */ |
| 103 | + public function changeIdleTime(int $time): void |
| 104 | + { |
| 105 | + $this->idleTime = $time; |
| 106 | + } |
| 107 | + |
| 108 | + /** |
| 109 | + * In milliseconds. |
| 110 | + */ |
| 111 | + public function getStartTime(): int |
| 112 | + { |
| 113 | + return $this->startTime; |
| 114 | + } |
| 115 | + |
| 116 | + /** |
| 117 | + * @return BoundProcessor[] |
| 118 | + */ |
| 119 | + public function getBoundProcessors(): array |
| 120 | + { |
| 121 | + return $this->processors; |
| 122 | + } |
| 123 | + |
| 124 | + /** |
| 125 | + * @param BoundProcessor[] $processors |
| 126 | + */ |
| 127 | + public function changeBoundProcessors(array $processors): void |
| 128 | + { |
| 129 | + $this->processors = []; |
| 130 | + array_walk($processors, function (BoundProcessor $processor) { |
| 131 | + $this->processors[] = $processor; |
| 132 | + }); |
| 133 | + } |
| 134 | + |
| 135 | + public function isExecutionInterrupted(): bool |
| 136 | + { |
| 137 | + return $this->executionInterrupted; |
| 138 | + } |
| 139 | + |
| 140 | + public function interruptExecution(): void |
| 141 | + { |
| 142 | + $this->executionInterrupted = true; |
| 143 | + } |
| 144 | +} |
0 commit comments