summaryrefslogtreecommitdiff
path: root/cpp/bindings/qpid/perl/lib/qpid/messaging/Sender.pm
blob: 5d0896ff7971c8a3e1f137717b6f958ecef5234a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
#

=pod

=head1 NAME

qpid::messaging::Sender

=head1 DESCRIPTION

A B<qpid::messaging::Sender> is the entity through which messages are sent.

An instance can only be created using an active (i.e., not previously closed)
B<qpid::messaging::Session>.

=head1 EXAMPLE

   # create a connection and a session
   my $conn = new qpid::messaging::Connection("mybroker:5672");
   conn->open;
   my $session = $conn->create_session;
   
   # create a sender that posts messages to the "updates" queue
   my $sender = $session->create_sender "updates;{create:always}"
   
   # begin sending updates
   while( 1 ) {
     my $content = wait_for_event;
     $sender->send(new qpid::messaging::Message($content));
   }

=cut

package qpid::messaging::Sender;

sub new {
    my ($class) = @_;
    my ($self) = {
        _impl => $_[1],
        _session => $_[2],
    };

    die "Must provide an implementation." unless defined($self->{_impl});
    die "Must provide a Session." unless defined($self->{_session});

    bless $self, $class;
    return $self;
}

=pod

=head1 ACTIONS

=cut


=pod

=head2 SENDING MESSAGES

=over

=item $sender->send( message )

=item $sender->send( message, block)

Sends a message, optionally blocking until the message is received by
the broker.

=back

=head3 ARGUMENTS

=over

=item * message

The message to be sent.

=item * block

If true then blocks until the message is received.

=back

=cut
sub send {
    my ($self) = @_;
    my $message = $_[1];
    my $sync = $_[2] || 0;

    die "No message to send." unless defined($message);

    my $impl = $self->{_impl};

    $impl->send($message->get_implementation, $sync);
}

=pod

=head2 CLOSING THE SENDER

=item sender->close

Closes the sender.

This does not affect the ownering B<Session> or B<Connection>

=back

=cut
sub close {
    my ($self) = @_;
    my $impl = $self->{_impl};

    $impl->close;
}

=pod

=head1 ATTRIBUTES

=cut

=pod

=head2 CAPACITY

The capacity is the number of outoing messages that can be held pending
confirmation of receipt by the broker.

=over

=item sender->set_capacity( size )

=item $size = sender->get_capacity

=back

=back

=cut
sub set_capacity {
    my ($self) = @_;
    my $impl = $self->{_impl};

    $impl->setCapacity($_[1]);
}

sub get_capacity {
    my ($self) = @_;
    my $impl = $self->{_impl};

    return $impl->getCapacity;
}

=pod

=head2 UNSETTLED

The number of messages sent that are pending receipt confirmation by the broker.

=over

=item $count = sender->get_unsettled

=back

=cut
sub get_unsettled {
    my ($self) = @_;
    my $impl = $self->{_impl};

    return $impl->getUnsettled;
}

=pod

=head2 AVAILABLE

The available slots for sending messages.

This differences form B<capacity> in that it is the available slots in the
senders capacity for holding outgoing messages. The difference between
capacity and available is the number of messages that have no been delivered
yet.

=over

=item $slots = sender->get_available

=back

=cut
sub get_available {
    my ($self) = @_;
    my $impl = $self->{_impl};

    return $impl->getAvailable();
}

=pod

=head2 NAME

The human-readable name for this sender.

=over

=item $name = sender-get_name

=back

=cut
sub get_name {
    my ($self) = @_;
    my $impl = $self->{_impl};

    return $impl->getName;
}

=pod

=head2 SESSION

The owning session from which the sender was created.

=over

=item $session = $sender->get_session

=back

=cut
sub get_session {
    my ($self) = @_;

    return $self->{_session};
}

1;