1 | <?php |
||
45 | class ProtocolHandler implements ProtocolHandlerInterface |
||
46 | { |
||
47 | |||
48 | /** |
||
49 | * Holds the Separator for protocol versions. |
||
50 | * |
||
51 | * @var string |
||
52 | */ |
||
53 | const SEPARATOR = ","; |
||
54 | |||
55 | /** |
||
56 | * The supported protocol versions. |
||
57 | * |
||
58 | * @var array |
||
59 | */ |
||
60 | protected $supportedProtocolVersions; |
||
61 | |||
62 | /** |
||
63 | * Holds the stomp authenticator. |
||
64 | * |
||
65 | * @var \AppserverIo\Stomp\Interfaces\AuthenticatorInterface |
||
66 | */ |
||
67 | protected $authenticator; |
||
68 | |||
69 | /** |
||
70 | * Holds the response as stomp frame. |
||
71 | * |
||
72 | * @var \AppserverIo\Stomp\Frame |
||
73 | */ |
||
74 | protected $response; |
||
75 | |||
76 | /** |
||
77 | * Holds the state to close parent connection. |
||
78 | * |
||
79 | * @var bool |
||
80 | */ |
||
81 | protected $mustConnectionClose; |
||
82 | |||
83 | /** |
||
84 | * Holds the queue session. |
||
85 | * |
||
86 | * @var \AppserverIo\Messaging\QueueSession |
||
87 | */ |
||
88 | protected $session; |
||
89 | |||
90 | /** |
||
91 | * Init new stomp protocol handler. |
||
92 | */ |
||
93 | public function __construct() |
||
103 | |||
104 | /** |
||
105 | * Init the StompProtocolHandler |
||
106 | * |
||
107 | * @return void |
||
108 | */ |
||
109 | public function init() |
||
114 | |||
115 | /** |
||
116 | * Injects the supported protocol versions for the handler. |
||
117 | * |
||
118 | * @param array $supportedProtocolVersion Array with supported protocol versions |
||
119 | * |
||
120 | * @return void |
||
121 | */ |
||
122 | public function injectSupportedProtocolVersions(array $supportedProtocolVersion) |
||
126 | |||
127 | /** |
||
128 | * Injects the authenticator for the handler. |
||
129 | * |
||
130 | * @param \AppserverIo\Stomp\Interfaces\AuthenticatorInterface $authenticator The $authenticator |
||
131 | * |
||
132 | * @return void |
||
133 | */ |
||
134 | public function injectAuthenticator(AuthenticatorInterface $authenticator) |
||
138 | |||
139 | /** |
||
140 | * Returns must the parent handler the connection close |
||
141 | * |
||
142 | * @return bool |
||
143 | */ |
||
144 | public function getMustConnectionClose() |
||
148 | |||
149 | /** |
||
150 | * Handle the connect request. |
||
151 | * |
||
152 | * @param \AppserverIo\Stomp\Frame $stompFrame The Stomp frame to handle the connect. |
||
153 | * |
||
154 | * @return void |
||
155 | * |
||
156 | * throws \AppserverIo\Stomp\Exception\ProtocolException |
||
157 | */ |
||
158 | public function handle(Frame $stompFrame) |
||
176 | |||
177 | /** |
||
178 | * Detects the protocol version by given string |
||
179 | * |
||
180 | * @param string $protocolVersion The version string to detect the version |
||
181 | * |
||
182 | * @return string |
||
183 | * |
||
184 | * @throws \AppserverIo\Stomp\Exception\ProtocolException |
||
185 | */ |
||
186 | public function detectProtocolVersion($protocolVersion) |
||
204 | |||
205 | /** |
||
206 | * Handle the connect request. |
||
207 | * |
||
208 | * @param \AppserverIo\Stomp\Frame $stompFrame The Stomp frame to handle the connect. |
||
209 | * |
||
210 | * @return \AppserverIo\Stomp\Frame The stomp frame Response |
||
211 | * |
||
212 | * @throws \AppserverIo\Stomp\Exception\ProtocolException |
||
213 | */ |
||
214 | protected function handleConnect(Frame $stompFrame) |
||
241 | |||
242 | /** |
||
243 | * Returns the authenticator, |
||
244 | * |
||
245 | * @return \AppserverIo\Stomp\Interfaces\AuthenticatorInterface |
||
246 | */ |
||
247 | public function getAuthenticator() |
||
251 | |||
252 | /** |
||
253 | * Returns the message queue session. |
||
254 | * |
||
255 | * @return \AppserverIo\Messaging\QueueSession |
||
256 | */ |
||
257 | public function getSession() |
||
261 | |||
262 | /** |
||
263 | * Set the message queue session. |
||
264 | * |
||
265 | * @param \AppserverIo\Messaging\QueueSession $session The message queue session to set. |
||
266 | * |
||
267 | * @return void |
||
268 | */ |
||
269 | public function setSession($session) |
||
273 | |||
274 | /** |
||
275 | * Handle the send request. |
||
276 | * |
||
277 | * @param \AppserverIo\Stomp\Frame $stompFrame The Stomp frame to handle the connect. |
||
278 | * |
||
279 | * @return void |
||
280 | * |
||
281 | * @throws \AppserverIo\Stomp\Exception\ProtocolException |
||
282 | */ |
||
283 | protected function handleSend(Frame $stompFrame) |
||
302 | |||
303 | /** |
||
304 | * Handle the disconnect request. |
||
305 | * |
||
306 | * @param \AppserverIo\Stomp\Frame $stompFrame The Stomp frame to handle the connect. |
||
307 | * |
||
308 | * @return \AppserverIo\Stomp\Frame The stomp frame Response |
||
309 | */ |
||
310 | protected function handleDisConnect($stompFrame) |
||
326 | |||
327 | /** |
||
328 | * Returns the response stomp frame. |
||
329 | * |
||
330 | * @return \AppserverIo\Stomp\Frame |
||
331 | */ |
||
332 | public function getResponseStompFrame() |
||
336 | |||
337 | /** |
||
338 | * Sets the state from handler to error |
||
339 | * |
||
340 | * @param string $message The message to set in the error frame. |
||
341 | * @param array $headers The header to set in the error frame. |
||
342 | * |
||
343 | * @return mixed |
||
344 | */ |
||
345 | public function setErrorState($message = "", $headers = array()) |
||
349 | |||
350 | /** |
||
351 | * Returns error stomp frame. |
||
352 | * |
||
353 | * @param string $message The message to set |
||
354 | * @param array $headers The headers to set |
||
355 | * |
||
356 | * @return \AppserverIo\Stomp\Frame |
||
357 | */ |
||
358 | protected function handleError($message, array $headers = array()) |
||
371 | } |
||
372 |