|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Wonderland\Thread\Event; |
|
4
|
|
|
|
|
5
|
|
|
use Wonderland\Thread\Mediator\Event\EventInterface; |
|
6
|
|
|
use Wonderland\Thread\Thread; |
|
7
|
|
|
|
|
8
|
|
|
class Event 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 Thread $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
|
1 |
|
public function getEventName(): string |
|
63
|
|
|
{ |
|
64
|
1 |
|
return $this->eventName; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @param string $eventName |
|
69
|
|
|
* @return Event |
|
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
|
1 |
|
public function getThreadNb(): int |
|
82
|
|
|
{ |
|
83
|
1 |
|
return $this->threadNb; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @param int $threadNb |
|
88
|
|
|
* @return Event |
|
89
|
|
|
*/ |
|
90
|
2 |
|
public function setThreadNb(int $threadNb): self |
|
91
|
|
|
{ |
|
92
|
2 |
|
$this->threadNb = $threadNb; |
|
93
|
|
|
|
|
94
|
2 |
|
return $this; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @return int |
|
99
|
|
|
*/ |
|
100
|
1 |
|
public function getThreadDoneNb(): int |
|
101
|
|
|
{ |
|
102
|
1 |
|
return $this->threadDoneNb; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* @param int $threadDoneNb |
|
107
|
|
|
* @return Event |
|
108
|
|
|
*/ |
|
109
|
2 |
|
public function setThreadDoneNb(int $threadDoneNb): self |
|
110
|
|
|
{ |
|
111
|
2 |
|
$this->threadDoneNb = $threadDoneNb; |
|
112
|
|
|
|
|
113
|
2 |
|
return $this; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* @return int |
|
118
|
|
|
*/ |
|
119
|
1 |
|
public function getThreadLeftNb(): int |
|
120
|
|
|
{ |
|
121
|
1 |
|
return $this->threadLeftNb; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* @param int $threadLeftNb |
|
126
|
|
|
* @return Event |
|
127
|
|
|
*/ |
|
128
|
2 |
|
public function setThreadLeftNb(int $threadLeftNb): self |
|
129
|
|
|
{ |
|
130
|
2 |
|
$this->threadLeftNb = $threadLeftNb; |
|
131
|
|
|
|
|
132
|
2 |
|
return $this; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* @return int |
|
137
|
|
|
*/ |
|
138
|
1 |
|
public function getMaxRunningThreadNb(): int |
|
139
|
|
|
{ |
|
140
|
1 |
|
return $this->maxRunningThreadNb; |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
/** |
|
144
|
|
|
* @param int $maxRunningThreadNb |
|
145
|
|
|
* @return Event |
|
146
|
|
|
*/ |
|
147
|
2 |
|
public function setMaxRunningThreadNb(int $maxRunningThreadNb): self |
|
148
|
|
|
{ |
|
149
|
2 |
|
$this->maxRunningThreadNb = $maxRunningThreadNb; |
|
150
|
|
|
|
|
151
|
2 |
|
return $this; |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
/** |
|
155
|
|
|
* @return int |
|
156
|
|
|
*/ |
|
157
|
1 |
|
public function getRunningThreadNb(): int |
|
158
|
|
|
{ |
|
159
|
1 |
|
return $this->runningThreadNb; |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
/** |
|
163
|
|
|
* @param int $runningThreadNb |
|
164
|
|
|
* @return Event |
|
165
|
|
|
*/ |
|
166
|
2 |
|
public function setRunningThreadNb(int $runningThreadNb): self |
|
167
|
|
|
{ |
|
168
|
2 |
|
$this->runningThreadNb = $runningThreadNb; |
|
169
|
|
|
|
|
170
|
2 |
|
return $this; |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
/** |
|
174
|
|
|
* @return Thread |
|
175
|
|
|
*/ |
|
176
|
1 |
|
public function getThread(): ?Thread |
|
177
|
|
|
{ |
|
178
|
1 |
|
return $this->thread; |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
/** |
|
182
|
|
|
* @param Thread|null $thread |
|
183
|
|
|
* @return $this |
|
184
|
|
|
*/ |
|
185
|
2 |
|
public function setThread(Thread $thread = null): self |
|
186
|
|
|
{ |
|
187
|
2 |
|
$this->thread = $thread; |
|
188
|
|
|
|
|
189
|
2 |
|
return $this; |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
} |
|
193
|
|
|
|