1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Wonderland\Thread\Event; |
4
|
|
|
|
5
|
|
|
use Wonderland\Thread\Mediator\Event\EventInterface; |
6
|
|
|
use Wonderland\Thread\AbstractThread; |
7
|
|
|
|
8
|
|
|
class PoolEvent implements EventInterface |
9
|
|
|
{ |
10
|
|
|
const POOL_RUN_START = 'run_start'; |
11
|
|
|
const POOL_RUN_STOP = 'run_stop'; |
12
|
|
|
const POOL_NEW_THREAD = 'new_thread'; |
13
|
|
|
const POOL_PRE_WAIT_TICK = 'pre_wait_tick'; |
14
|
|
|
const POOL_POST_WAIT_TICK = 'post_wait_tick'; |
15
|
|
|
const POOL_WAIT_TICK_PID = 'wait_tick_pid'; |
16
|
|
|
const POOL_WAIT_TICK_PID_REMOVED = 'wait_tick_pid_removed'; |
17
|
|
|
|
18
|
|
|
const THREAD_PRE_PROCESS = 'pre_process'; |
19
|
|
|
const THREAD_POST_PROCESS = 'post_process'; |
20
|
|
|
const THREAD_EXIT_SUCCESS = 'exist_success'; |
21
|
|
|
const THREAD_EXIT_ERROR = 'exit_error'; |
22
|
|
|
const THREAD_EXIT_UNKNOWN = 'exit_unknown'; |
23
|
|
|
|
24
|
|
|
/** @var string $eventName */ |
25
|
|
|
private $eventName; |
26
|
|
|
|
27
|
|
|
/** @var int $threadNb */ |
28
|
|
|
private $threadNb; |
29
|
|
|
|
30
|
|
|
/** @var int $runningThreadNb */ |
31
|
|
|
private $runningThreadNb; |
32
|
|
|
|
33
|
|
|
/** @var int $threadDoneNb */ |
34
|
|
|
private $threadDoneNb; |
35
|
|
|
|
36
|
|
|
/** @var int $threadLeftNb */ |
37
|
|
|
private $threadLeftNb; |
38
|
|
|
|
39
|
|
|
/** @var int $maxRunningThreadNb */ |
40
|
|
|
private $maxRunningThreadNb; |
41
|
|
|
|
42
|
|
|
/** @var AbstractThread $thread */ |
43
|
|
|
private $thread; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* ThreadPoolEvent constructor. |
47
|
|
|
* @param string $eventName |
48
|
|
|
*/ |
49
|
4 |
|
public function __construct($eventName) |
50
|
|
|
{ |
51
|
4 |
|
$this->eventName = $eventName; |
52
|
4 |
|
$this->threadNb = 0; |
53
|
4 |
|
$this->runningThreadNb = 0; |
54
|
4 |
|
$this->threadDoneNb = 0; |
55
|
4 |
|
$this->threadLeftNb = 0; |
56
|
4 |
|
$this->maxRunningThreadNb = 0; |
57
|
4 |
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @return string |
61
|
|
|
*/ |
62
|
4 |
|
public function getEventName(): string |
63
|
|
|
{ |
64
|
4 |
|
return $this->eventName; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param string $eventName |
69
|
|
|
* @return PoolEvent |
70
|
|
|
*/ |
71
|
1 |
|
public function setEventName(string $eventName): self |
72
|
|
|
{ |
73
|
1 |
|
$this->eventName = $eventName; |
74
|
|
|
|
75
|
1 |
|
return $this; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @return int |
80
|
|
|
*/ |
81
|
2 |
|
public function getThreadNb(): int |
82
|
|
|
{ |
83
|
2 |
|
return $this->threadNb; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @param int $threadNb |
88
|
|
|
* @return PoolEvent |
89
|
|
|
*/ |
90
|
3 |
|
public function setThreadNb(int $threadNb): self |
91
|
|
|
{ |
92
|
3 |
|
$this->threadNb = $threadNb; |
93
|
|
|
|
94
|
3 |
|
return $this; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @return int |
99
|
|
|
*/ |
100
|
2 |
|
public function getThreadDoneNb(): int |
101
|
|
|
{ |
102
|
2 |
|
return $this->threadDoneNb; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @param int $threadDoneNb |
107
|
|
|
* @return PoolEvent |
108
|
|
|
*/ |
109
|
3 |
|
public function setThreadDoneNb(int $threadDoneNb): self |
110
|
|
|
{ |
111
|
3 |
|
$this->threadDoneNb = $threadDoneNb; |
112
|
|
|
|
113
|
3 |
|
return $this; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @return int |
118
|
|
|
*/ |
119
|
2 |
|
public function getThreadLeftNb(): int |
120
|
|
|
{ |
121
|
2 |
|
return $this->threadLeftNb; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @param int $threadLeftNb |
126
|
|
|
* @return PoolEvent |
127
|
|
|
*/ |
128
|
3 |
|
public function setThreadLeftNb(int $threadLeftNb): self |
129
|
|
|
{ |
130
|
3 |
|
$this->threadLeftNb = $threadLeftNb; |
131
|
|
|
|
132
|
3 |
|
return $this; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @return int |
137
|
|
|
*/ |
138
|
2 |
|
public function getMaxRunningThreadNb(): int |
139
|
|
|
{ |
140
|
2 |
|
return $this->maxRunningThreadNb; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @param int $maxRunningThreadNb |
145
|
|
|
* @return PoolEvent |
146
|
|
|
*/ |
147
|
3 |
|
public function setMaxRunningThreadNb(int $maxRunningThreadNb): self |
148
|
|
|
{ |
149
|
3 |
|
$this->maxRunningThreadNb = $maxRunningThreadNb; |
150
|
|
|
|
151
|
3 |
|
return $this; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* @return int |
156
|
|
|
*/ |
157
|
2 |
|
public function getRunningThreadNb(): int |
158
|
|
|
{ |
159
|
2 |
|
return $this->runningThreadNb; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* @param int $runningThreadNb |
164
|
|
|
* @return PoolEvent |
165
|
|
|
*/ |
166
|
3 |
|
public function setRunningThreadNb(int $runningThreadNb): self |
167
|
|
|
{ |
168
|
3 |
|
$this->runningThreadNb = $runningThreadNb; |
169
|
|
|
|
170
|
3 |
|
return $this; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* @return AbstractThread |
175
|
|
|
*/ |
176
|
1 |
|
public function getThread(): ?AbstractThread |
177
|
|
|
{ |
178
|
1 |
|
return $this->thread; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* @param AbstractThread|null $thread |
183
|
|
|
* @return $this |
184
|
|
|
*/ |
185
|
3 |
|
public function setThread(AbstractThread $thread = null): self |
186
|
|
|
{ |
187
|
3 |
|
$this->thread = $thread; |
188
|
|
|
|
189
|
3 |
|
return $this; |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
} |
193
|
|
|
|