QueueSender   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 3
dl 0
loc 50
ccs 0
cts 12
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A send() 0 11 1
1
<?php
2
3
/**
4
 * AppserverIo\Messaging\QueueSender
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/messaging
18
 * @link      http://www.appserver.io
19
 */
20
21
namespace AppserverIo\Messaging;
22
23
use AppserverIo\Psr\Pms\QueueInterface;
24
use AppserverIo\Psr\Pms\MessageInterface;
25
26
/**
27
 * A queue sender implementation.
28
 *
29
 * @author    Tim Wagner <[email protected]>
30
 * @copyright 2015 TechDivision GmbH <[email protected]>
31
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
32
 * @link      https://github.com/appserver-io/messaging
33
 * @link      http://www.appserver.io
34
 */
35
class QueueSender
36
{
37
38
    /**
39
     * Holds the queue instance used for sending the message.
40
     *
41
     * @var \AppserverIo\Psr\Pms\QueueInterface
42
     */
43
    protected $queue = null;
44
45
    /**
46
     * Holds the queue session instance for sending the message.
47
     *
48
     * @var \AppserverIo\Messaging\QueueSession
49
     */
50
    protected $session = null;
51
52
    /**
53
     * Initializes the queue sender with the queue session and queue instance
54
     * to use for sending the message to the server.
55
     *
56
     * @param \AppserverIo\Messaging\QueueSession $session The queue session instance for sending the message
57
     * @param \AppserverIo\Psr\Pms\QueueInterface $queue   The queue instance used for sending the message
58
     */
59
    public function __construct(QueueSession $session, QueueInterface $queue)
60
    {
61
        $this->session = $session;
62
        $this->queue = $queue;
63
    }
64
65
    /**
66
     * Sends the passed Message to the server.
67
     *
68
     * @param \AppserverIo\Psr\Pms\MessageInterface $message          The message to send
69
     * @param boolean                               $validateResponse If this flag is TRUE, the queue connection waits for the message queue response and validates it
70
     *
71
     * @return \AppserverIo\Messaging\QueueResponse The response of the message queue, or null
72
     */
73
    public function send(MessageInterface $message, $validateResponse = false)
74
    {
75
76
        // create a new queue proxy instance, because we want to send it over a network)
77
        $queueProxy = QueueProxy::createFromQueue($this->queue);
78
79
        // prepare and send the message
80
        $message->setDestination($queueProxy);
81
        $message->setSessionId($this->session->getId());
82
        return $this->session->send($message, $validateResponse);
83
    }
84
}
85