|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* AppserverIo\Psr\Pms\MessageWrapper |
|
5
|
|
|
* |
|
6
|
|
|
* NOTICE OF LICENSE |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
|
9
|
|
|
* that is available through the world-wide-web at this URL: |
|
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
|
11
|
|
|
* |
|
12
|
|
|
* PHP version 5 |
|
13
|
|
|
* |
|
14
|
|
|
* @author Tim Wagner <[email protected]> |
|
15
|
|
|
* @copyright 2015 TechDivision GmbH <[email protected]> |
|
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
17
|
|
|
* @link https://github.com/appserver-io-psr/pms |
|
18
|
|
|
* @link http://www.appserver.io |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace AppserverIo\Psr\Pms; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* A simple message wrapper instance. |
|
25
|
|
|
* |
|
26
|
|
|
* @author Tim Wagner <[email protected]> |
|
27
|
|
|
* @copyright 2015 TechDivision GmbH <[email protected]> |
|
28
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
29
|
|
|
* @link https://github.com/appserver-io-psr/pms |
|
30
|
|
|
* @link http://www.appserver.io |
|
31
|
|
|
*/ |
|
32
|
|
|
class MessageWrapper implements MessageInterface |
|
33
|
|
|
{ |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* The message we want to wrap. |
|
37
|
|
|
* |
|
38
|
|
|
* @var \AppserverIo\Psr\Pms\MessageInterface |
|
39
|
|
|
*/ |
|
40
|
|
|
protected $message; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Injects the message we want to wrap. |
|
44
|
|
|
* |
|
45
|
|
|
* @param \AppserverIo\Psr\Pms\MessageInterface $message The message instance |
|
46
|
|
|
* |
|
47
|
|
|
* @return void |
|
48
|
|
|
*/ |
|
49
|
1 |
|
public function injectMessage(MessageInterface $message) |
|
50
|
|
|
{ |
|
51
|
1 |
|
$this->message = $message; |
|
52
|
1 |
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Returns the injected message instance. |
|
56
|
|
|
* |
|
57
|
|
|
* @return \AppserverIo\Psr\Pms\MessageInterface The injected message instance |
|
58
|
|
|
*/ |
|
59
|
1 |
|
public function getInjectedMessage() |
|
60
|
|
|
{ |
|
61
|
1 |
|
return $this->message; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Returns the destination queue. |
|
66
|
|
|
* |
|
67
|
|
|
* @return \AppserverIo\Psr\Pms\QueueInterface The destination queue |
|
68
|
|
|
*/ |
|
69
|
|
|
public function getDestination() |
|
70
|
|
|
{ |
|
71
|
|
|
return $this->getInjectedMessage()->getDestination(); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Returns the message id as an |
|
76
|
|
|
* hash value.. |
|
77
|
|
|
* |
|
78
|
|
|
* @return string The message id as hash value |
|
79
|
|
|
*/ |
|
80
|
|
|
public function getMessageId() |
|
81
|
|
|
{ |
|
82
|
|
|
return $this->getInjectedMessage()->getMessageId(); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Returns the message itself. |
|
87
|
|
|
* |
|
88
|
|
|
* @return Object The message depending on the type of the Message object |
|
89
|
|
|
*/ |
|
90
|
1 |
|
public function getMessage() |
|
91
|
|
|
{ |
|
92
|
1 |
|
return $this->getInjectedMessage()->getMessage(); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Sets the unique session id. |
|
97
|
|
|
* |
|
98
|
|
|
* @param string $sessionId The uniquid id |
|
99
|
|
|
* |
|
100
|
|
|
* @return void |
|
101
|
|
|
*/ |
|
102
|
|
|
public function setSessionId($sessionId) |
|
103
|
|
|
{ |
|
104
|
|
|
$this->getInjectedMessage()->setSessionId($sessionId); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* Returns the unique session id. |
|
109
|
|
|
* |
|
110
|
|
|
* @return string The uniquid id |
|
111
|
|
|
*/ |
|
112
|
|
|
public function getSessionId() |
|
113
|
|
|
{ |
|
114
|
|
|
return $this->getInjectedMessage()->getSessionId(); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* Returns the parent message. |
|
119
|
|
|
* |
|
120
|
|
|
* @return \AppserverIo\Psr\Pms\MessageInterface The parent message |
|
121
|
|
|
*/ |
|
122
|
|
|
public function getParentMessage() |
|
123
|
|
|
{ |
|
124
|
|
|
return $this->getInjectedMessage()->getParentMessage(); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* Returns the message monitor. |
|
129
|
|
|
* |
|
130
|
|
|
* @return \AppserverIo\Psr\Pms\MonitorInterface The monitor |
|
131
|
|
|
*/ |
|
132
|
|
|
public function getMessageMonitor() |
|
133
|
|
|
{ |
|
134
|
|
|
return $this->getInjectedMessage()->getMessageMonitor(); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* Returns the priority of the message. |
|
139
|
|
|
* |
|
140
|
|
|
* @return \AppserverIo\Psr\Pms\PriorityKeyInterface The priority of the message |
|
141
|
|
|
*/ |
|
142
|
|
|
public function getPriority() |
|
143
|
|
|
{ |
|
144
|
|
|
return $this->getInjectedMessage()->getPriority(); |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* Returns the state of the message. |
|
149
|
|
|
* |
|
150
|
|
|
* @return \AppserverIo\Psr\Pms\StateKeyInterface The message state |
|
151
|
|
|
*/ |
|
152
|
|
|
public function getState() |
|
153
|
|
|
{ |
|
154
|
|
|
return $this->getInjectedMessage()->getState(); |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* Sets the monitor for monitoring the message itself. |
|
159
|
|
|
* |
|
160
|
|
|
* @param \AppserverIo\Psr\Pms\MonitorInterface $messageMonitor The monitor |
|
161
|
|
|
* |
|
162
|
|
|
* @return void |
|
163
|
|
|
*/ |
|
164
|
|
|
public function setMessageMonitor(MonitorInterface $messageMonitor) |
|
165
|
|
|
{ |
|
166
|
|
|
$this->getInjectedMessage()->setMessageMonitor($messageMonitor); |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
/** |
|
170
|
|
|
* Unlocks the message. |
|
171
|
|
|
* |
|
172
|
|
|
* @return void |
|
173
|
|
|
*/ |
|
174
|
|
|
public function unlock() |
|
175
|
|
|
{ |
|
176
|
|
|
$this->getInjectedMessage()->unlock(); |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
/** |
|
180
|
|
|
* Sets the parent message. |
|
181
|
|
|
* |
|
182
|
|
|
* @param \AppserverIo\Psr\Pms\MessageInterface $parentMessage The parent message |
|
183
|
|
|
* |
|
184
|
|
|
* @return void |
|
185
|
|
|
*/ |
|
186
|
|
|
public function setParentMessage(MessageInterface $parentMessage) |
|
187
|
|
|
{ |
|
188
|
|
|
$this->getInjectedMessage()->setParentMessage($parentMessage); |
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
|
|
/** |
|
192
|
|
|
* Sets the destination queue. |
|
193
|
|
|
* |
|
194
|
|
|
* @param \AppserverIo\Psr\Pms\QueueInterface $destination The destination queue |
|
195
|
|
|
* |
|
196
|
|
|
* @return void |
|
197
|
|
|
*/ |
|
198
|
|
|
public function setDestination(QueueInterface $destination) |
|
199
|
|
|
{ |
|
200
|
|
|
$this->getInjectedMessage()->setDestination($destination); |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
/** |
|
204
|
|
|
* Return's the number of retries for this message. |
|
205
|
|
|
* |
|
206
|
|
|
* @return integer The number of retries |
|
207
|
|
|
*/ |
|
208
|
|
|
public function getRetryCounter() |
|
209
|
|
|
{ |
|
210
|
|
|
return $this->getInjectedMessage()->getRetryCounter(); |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
|
|
/** |
|
214
|
|
|
* Return's the callback information for the given state. |
|
215
|
|
|
* |
|
216
|
|
|
* @param \AppserverIo\Psr\Pms\StateKeyInterface $state The state to register the callback for |
|
217
|
|
|
* |
|
218
|
|
|
* @return array The array with the callback information |
|
219
|
|
|
*/ |
|
220
|
|
|
public function getCallbacks(StateKeyInterface $state) |
|
221
|
|
|
{ |
|
222
|
|
|
return $this->getInjectedMessage()->getCallbacks($state); |
|
223
|
|
|
} |
|
224
|
|
|
|
|
225
|
|
|
/** |
|
226
|
|
|
* Add's the callback for the given state. |
|
227
|
|
|
* |
|
228
|
|
|
* @param \AppserverIo\Psr\Pms\StateKeyInterface $state The state to register the callback for |
|
229
|
|
|
* @param array $callback The array with the bean's lookup and method name that has to be invoked |
|
230
|
|
|
* |
|
231
|
|
|
* @return void |
|
232
|
|
|
* @throws \Exception Is thrown if the passed state doesn't support callbacks |
|
233
|
|
|
*/ |
|
234
|
|
|
public function addCallback(StateKeyInterface $state, array $callback) |
|
235
|
|
|
{ |
|
236
|
|
|
$this->getInjectedMessage()->addCallback($state, $callback); |
|
237
|
|
|
} |
|
238
|
|
|
|
|
239
|
|
|
/** |
|
240
|
|
|
* Return's the timeout for the given retry. |
|
241
|
|
|
* |
|
242
|
|
|
* @param integer $retry The retry to return the timeout for |
|
243
|
|
|
* |
|
244
|
|
|
* @return integer The timeout in seconds for the passed retry |
|
245
|
|
|
* @throws \InvalidArgumentException Is thrown if the timeout for the passed retry is NOT available |
|
246
|
|
|
*/ |
|
247
|
|
|
public function getRetryTimeout($retry) |
|
248
|
|
|
{ |
|
249
|
|
|
return $this->getInjectedMessage()->getRetryTimeout($retry); |
|
250
|
|
|
} |
|
251
|
|
|
|
|
252
|
|
|
/** |
|
253
|
|
|
* Return's the array with the retry timeouts. |
|
254
|
|
|
* |
|
255
|
|
|
* @return array The retry timeouts |
|
256
|
|
|
*/ |
|
257
|
|
|
public function getRetryTimeouts() |
|
258
|
|
|
{ |
|
259
|
|
|
return $this->getInjectedMessage()->getRetryTimeouts(); |
|
260
|
|
|
} |
|
261
|
|
|
|
|
262
|
|
|
/** |
|
263
|
|
|
* Returns the message lock flag. |
|
264
|
|
|
* |
|
265
|
|
|
* @return boolean TRUE if the message is locked, else FALSE |
|
266
|
|
|
*/ |
|
267
|
|
|
public function isLocked() |
|
268
|
|
|
{ |
|
269
|
|
|
return $this->getInjectedMessage()->isLocked(); |
|
270
|
|
|
} |
|
271
|
|
|
|
|
272
|
|
|
/** |
|
273
|
|
|
* Sets the state of the message. |
|
274
|
|
|
* |
|
275
|
|
|
* @param \AppserverIo\Psr\Pms\StateKeyInterface $state The new state |
|
276
|
|
|
* |
|
277
|
|
|
* @return void |
|
278
|
|
|
*/ |
|
279
|
|
|
public function setState(StateKeyInterface $state) |
|
280
|
|
|
{ |
|
281
|
|
|
$this->getInjectedMessage()->setState($state); |
|
282
|
|
|
} |
|
283
|
|
|
|
|
284
|
|
|
/** |
|
285
|
|
|
* Locks the message. |
|
286
|
|
|
* |
|
287
|
|
|
* @return void |
|
288
|
|
|
*/ |
|
289
|
|
|
public function lock() |
|
290
|
|
|
{ |
|
291
|
|
|
$this->getInjectedMessage()->lock(); |
|
292
|
|
|
} |
|
293
|
|
|
|
|
294
|
|
|
/** |
|
295
|
|
|
* Sets the priority of the message. |
|
296
|
|
|
* |
|
297
|
|
|
* @param \AppserverIo\Psr\Pms\PriorityKeyInterface $priority The priority to set the message to |
|
298
|
|
|
* |
|
299
|
|
|
* @return void |
|
300
|
|
|
*/ |
|
301
|
|
|
public function setPriority(PriorityKeyInterface $priority) |
|
302
|
|
|
{ |
|
303
|
|
|
$this->getInjectedMessage()->setPriority($priority); |
|
304
|
|
|
} |
|
305
|
|
|
|
|
306
|
|
|
/** |
|
307
|
|
|
* Return's whether or not callbacks for the passed state has been registered. |
|
308
|
|
|
* |
|
309
|
|
|
* @param \AppserverIo\Psr\Pms\StateKeyInterface $state The state to register the callback for |
|
310
|
|
|
* |
|
311
|
|
|
* @return boolean TRUE if callbacks has been registered, else FALSE |
|
312
|
|
|
*/ |
|
313
|
|
|
public function hasCallbacks(StateKeyInterface $state) |
|
314
|
|
|
{ |
|
315
|
|
|
return $this->getInjectedMessage()->hasCallbacks($state); |
|
316
|
|
|
} |
|
317
|
|
|
|
|
318
|
|
|
/** |
|
319
|
|
|
* Set's the array with the retry timeouts which is also responsible |
|
320
|
|
|
* for the the number of retries. |
|
321
|
|
|
* |
|
322
|
|
|
* @param array $retryTimeouts The number of retries with their timeouts |
|
323
|
|
|
* |
|
324
|
|
|
* @return void |
|
325
|
|
|
*/ |
|
326
|
|
|
public function setRetryTimeouts(array $retryTimeouts) |
|
327
|
|
|
{ |
|
328
|
|
|
$this->getInjectedMessage()->setRetryTimeouts($retryTimeouts); |
|
329
|
|
|
} |
|
330
|
|
|
} |
|
331
|
|
|
|