1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Async sockets |
4
|
|
|
* |
5
|
|
|
* @copyright Copyright (c) 2015-2017, Efimov Evgenij <[email protected]> |
6
|
|
|
* |
7
|
|
|
* This source file is subject to the MIT license that is bundled |
8
|
|
|
* with this source code in the file LICENSE. |
9
|
|
|
*/ |
10
|
|
|
namespace AsyncSockets\RequestExecutor\Pipeline; |
11
|
|
|
|
12
|
|
|
use AsyncSockets\RequestExecutor\ExecutionContext; |
13
|
|
|
use AsyncSockets\RequestExecutor\LimitationSolverInterface; |
14
|
|
|
use AsyncSockets\RequestExecutor\RequestExecutorInterface; |
15
|
|
|
use AsyncSockets\Socket\AsyncSelector; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class PipelineFactory |
19
|
|
|
*/ |
20
|
|
|
class PipelineFactory |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* Stage factory |
24
|
|
|
* |
25
|
|
|
* @var StageFactoryInterface |
26
|
|
|
*/ |
27
|
|
|
private $stageFactory; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* PipelineFactory constructor. |
31
|
|
|
* |
32
|
|
|
* @param StageFactoryInterface $stageFactory Stage factory |
33
|
|
|
*/ |
34
|
69 |
|
public function __construct(StageFactoryInterface $stageFactory) |
35
|
|
|
{ |
36
|
69 |
|
$this->stageFactory = $stageFactory; |
37
|
69 |
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Create Pipeline |
41
|
|
|
* |
42
|
|
|
* @param RequestExecutorInterface $executor Request executor |
43
|
|
|
* @param ExecutionContext $executionContext Execution context |
44
|
|
|
* @param EventCaller $eventCaller Event caller |
45
|
|
|
* @param LimitationSolverInterface $limitationDecider Limitation solver |
46
|
|
|
* |
47
|
|
|
* @return Pipeline |
48
|
|
|
*/ |
49
|
67 |
|
public function createPipeline( |
50
|
|
|
RequestExecutorInterface $executor, |
51
|
|
|
ExecutionContext $executionContext, |
52
|
|
|
EventCaller $eventCaller, |
53
|
|
|
LimitationSolverInterface $limitationDecider |
54
|
|
|
) { |
55
|
67 |
|
$selector = $this->createSelector(); |
56
|
67 |
|
$disconnectStage = $this->stageFactory->createDisconnectStage($executor, $executionContext, $eventCaller, $selector); |
57
|
|
|
|
58
|
67 |
|
return new Pipeline( |
59
|
67 |
|
$this->stageFactory->createConnectStage($executor, $executionContext, $eventCaller, $limitationDecider), |
60
|
|
|
[ |
61
|
67 |
|
new ExcludedOperationsStage( |
62
|
67 |
|
$executor, |
63
|
67 |
|
$eventCaller, |
64
|
67 |
|
$executionContext, |
65
|
|
|
[ |
66
|
67 |
|
$this->stageFactory->createDelayStage($executor, $executionContext, $eventCaller), |
67
|
67 |
|
new SelectStage($executor, $eventCaller, $executionContext, $selector), |
68
|
67 |
|
$this->stageFactory->createIoStage($executor, $executionContext, $eventCaller), |
69
|
|
|
$disconnectStage |
70
|
67 |
|
] |
71
|
67 |
|
), |
72
|
67 |
|
new TimeoutStage($executor, $eventCaller, $executionContext), |
73
|
|
|
$disconnectStage |
74
|
67 |
|
], |
75
|
|
|
$disconnectStage |
76
|
67 |
|
); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Create AsyncSelector |
81
|
|
|
* |
82
|
|
|
* @return AsyncSelector |
83
|
|
|
*/ |
84
|
67 |
|
protected function createSelector() |
85
|
|
|
{ |
86
|
67 |
|
return new AsyncSelector(); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|