summaryrefslogtreecommitdiff
path: root/cpp/bindings/qpid/perl/lib/qpid/messaging/Session.pm
blob: af8573168532ac6bebb4929e3e88315e7e39fd7b (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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
#
# 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::Session

=head1 DESCRIPTION

A B<qpid::messaging::Session> represents a distinct conversation between end
points. They are created from an active (i.e, not closed) B<Connection>.

A session is used to acknowledge individual or all messages that have
passed through it, as well as for creating senders and receivers for conversing.
=cut
package qpid::messaging::Session;

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

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

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

=pod

=head1 ACTIONS

=cut


=pod

=head2 CLOSING THE SESSION

=over

=item $session->close

=back

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

    $impl->close;
}

=pod

=head2 TRANSACTIONS

Transactions can be rolled back or committed.

=over

=item $session->commit

=item $session->rollback

=back

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

    $impl->commit;
}

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

    $impl->rollback;
}

=pod

=head2 MESSAGE DISPOSITIONS

=cut


=pod

=over

=item $session->acknowledge( msg )

Acknowledges that a specific message that has been received.

=back

=begin _private

TODO: How to handle acknowledging a specific message?

=end _private

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

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

    $impl->acknowledge($sync);
}

=pod

=over

=item $session->reject( msg )

Rejects the specified message. A reject message will not be redelivered.

=back

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

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

=pod

=over

=item $session->release( msg )

Releases the specified message, which allows the broker to attempt to
redeliver it.

=back

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

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

=pod

=over

=item $session->sync

=item $session->sync( block )

Requests synchronization with the broker.

=back

=head3 ARGUMENTS

=over

=item * block

If true, then the call blocks until the process completes.

=back

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

    if(defined($_[1])) {
        $impl->sync($_[1]);
    } else {
        $impl->sync;
    }
}

=pod

=head2 SENDERS AND RECEIVERS

=cut


=pod

=over

=item $sender = $session->create_sender( address )

Creates a new sender.

=back

=head3 ARGUMENTS

=over

=item * address

The sender address. See B<qpid::messaging::Address> for more details

=back

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

    my $address = $_[1];

    if (ref($address) eq "qpid::messaging::Address") {
        my $temp = $address->get_implementation();
        $address = $temp;
    }
    my $send_impl = $impl->createSender($address);

    return new qpid::messaging::Sender($send_impl, $self);
}

=pod

=over

=item $sender = $session->get_session( name )

=back

=head3 ARGUMENTS

=over

=item * name

The name of the sender.

Raises an exception when no sender with that name exists.

=back

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

    my $send_impl = $impl->getSender($_[1]);
    my $sender = undef;

    if (defined($send_impl)) {
        $sender = new qpid::messaging::Sender($send_impl, $self);
    }

    return $sender;
}

=pod

=over

=item $receiver = $session->create_receiver( address )

=back

=head3 ARGUMENTS

=over

=item * address

The receiver address. see B<qpid::messaging::Address> for more details.

=back

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

    my $address = $_[1];

    if (ref($address) eq "qpid::messaging::Address") {
        $address = $address->get_implementation();
    }
    my $recv_impl = $impl->createReceiver($address);

    return new qpid::messaging::Receiver($recv_impl, $self);
}

=pod

=over

=item $receiver = $session->get_receiver( name )

=back

=head3 ARGUMENTS

=over

=item * name

The name of the receiver.

=back

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

    my $recv_impl = $impl->getReceiver($_[1]);
    my $receiver = undef;

    if (defined($recv_impl)) {
        $receiver = new qpid::messaging::Receiver($recv_impl, $self);
    }

    return $receiver;
}

=pod

=head1 ATTRIBUTES

=cut


=pod

=head2 RECEIVABLE

The total number of receivable messages, and messages already received,
by receivers associated with this session.

=over

=item $session->get_receivable

=back

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

    return $impl->getReceivable;
}

=pod

=head2 UNSETTLED ACKNOWLEDGEMENTS

The number of messages that have been acknowledged by this session whose
acknowledgements have not been confirmed as processed by the broker.

=over

=item $session->get_unsettled_acks

=back

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

    return $impl->getUnsettledAcks;
}

=pod

=head2 NEXT RECEIVER

The next receiver is the one, created by this session, that has any pending
local messages.

If no receivers are found within the timeout then a B<MessagingException> is
raised.

=over

=item $session->get_next_receiver

=item $session->get_next_receiver( timeout )

=back

=head3 ARGUMENTS

=over

=item * timeout

The period of time to wait for a receiver to be found. If no period of time is
specified then the default is to wait B<forever>.

=back

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

    my $timeout = $_[1] || qpid::messaging::Duration::FOREVER;

    return $impl->getNextReceiver($timeout);
}

=pod

=head2 CONNECTION

=over

=item $conn = $session->get_connection

Returns the owning connection for the session.

=back

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

    return $self->{_conn};
}

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

    return $impl->hasError;
}

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

    $impl->checkForError;
}

1;