| 1 | package POE::Component::Client::AMQP::Channel; | ||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||
| 3 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||
| 5 | POE::Component::Client::AMQP::Channel - AMQP Channel object | ||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||
| 7 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||
| 9 | Create using the L<POE::Component::Client::AMQP> objects' C<channel()> command. Calling C<channel()> also retrieves previously created Channel objects. Alternatively, you can use the C<create()> class method below to create it directly. | ||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||
| 11 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use POE; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use Params::Validate; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use POE::Component::Client::AMQP qw(:constants); | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 19 | 1 | ▶ | use base qw(Class::Accessor); | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | __PACKAGE__->mk_accessors(qw(id server Alias)); | |||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||
| 22 | 1 | our $VERSION = 0.03; | |||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||
| 24 | =head1 CLASS METHODS | ||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||
| 26 | =head2 create (...) | ||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||
| 28 | =over 4 | ||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||
| 30 | Creates a new L<POE::Session> that controls communications on a new AMQP channel. Pass a list of key/value pairs as follows: | ||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||
| 32 | =over 4 | ||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||
| 34 | =item I<id> (optional) | ||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||
| 36 | Provide an id or one will be generated for you. | ||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||
| 38 | =item I<server> (required) | ||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||
| 40 | Pass the L<POE::Component::Client::AMQP> parent object here. | ||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||
| 42 | =item I<Alias> (default: ${parent_alias}-channel-$id) | ||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||
| 44 | The L<POE::Session> alias so you can post to it's POE states. | ||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||
| 46 | =item I<Callbacks> (default: {}) | ||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||
| 48 | At the moment, only 'Created' is used. | ||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||
| 50 | =item I<CascadeFailure> (default: 1) | ||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||
| 52 | If this channel is closed, close also the server connection. | ||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||
| 54 | =back | ||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||
| 56 | Returns an object in this class. | ||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||
| 58 | =back | ||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||
| 60 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||
| 62 | 1 | my $_ids = 0; | |||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | sub create { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
create: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||
| 67 | my %args = validate(@_, { | ||||||||||||||||||||||||||||||||||||||||
| 68 | id => 0, | ||||||||||||||||||||||||||||||||||||||||
| 69 | server => 1, | ||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||
| 71 | # User definable | ||||||||||||||||||||||||||||||||||||||||
| 72 | Alias => 0, | ||||||||||||||||||||||||||||||||||||||||
| 73 | Callbacks => { default => {} }, | ||||||||||||||||||||||||||||||||||||||||
| 74 | CascadeFailure => { default => 1 }, | ||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | CloseCallback => { default => sub {} }, | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||
| 77 | # Private | ||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | consumers => { default => {} }, | |||||||||||||||||||||||||||||||||||||||
| 79 | is_created => { default => 0 }, | ||||||||||||||||||||||||||||||||||||||||
| 80 | }); | ||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||
| 82 | # Ensure we have a unique channel id | ||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | my $ids = $args{server}{channels}; | |||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | if ($args{id} && $ids->{ $args{id} }) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$args{"id"} and $$ids{$args{"id"}}
MC/DC0%0/2
$args{"id"} and $$ids{$args{"id"}}
$args{"id"}
$$ids{$args{"id"}}
Truth table0%0/3
A and B
A= $args{"id"}B= $$ids{$args{"id"}}
| |||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | croak "Channel id $args{id} is already in use"; | |||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||
| 89 | elsif (! $args{id}) { | ||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | foreach my $i (1 .. (2 ** 16 - 1)) { | |||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | if (! $ids->{$i}) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | $args{id} = $i; | |||||||||||||||||||||||||||||||||||||||
| 93 | 0 | last; | |||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | croak "Ran out of channel ids (!!)" unless $args{id}; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||
| 99 | # Ensure we have a unique alias name | ||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | $args{Alias} ||= $args{server}{Alias} . '-channel-' . $_ids++; | ||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$args{"Alias"} ||= $args{"server"}{"Alias"} . '-channel-' . $_ids++
MC/DC0%0/1
$args{"Alias"} ||= $args{"server"}{"Alias"} . '-channel-' . $_ids++
$args{"Alias"}
Truth table0%0/2
A
A= $args{"Alias"}
| |||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||
| 103 | # Create the object and session | ||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | my $self = bless \%args, $class; | |||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | POE::Session->create( | |||||||||||||||||||||||||||||||||||||||
| 108 | object_states => [ | ||||||||||||||||||||||||||||||||||||||||
| 109 | $self => [qw( | ||||||||||||||||||||||||||||||||||||||||
| 110 | _start | ||||||||||||||||||||||||||||||||||||||||
| 111 | server_input | ||||||||||||||||||||||||||||||||||||||||
| 112 | server_send | ||||||||||||||||||||||||||||||||||||||||
| 113 | channel_created | ||||||||||||||||||||||||||||||||||||||||
| 114 | )], | ||||||||||||||||||||||||||||||||||||||||
| 115 | ], | ||||||||||||||||||||||||||||||||||||||||
| 116 | ); | ||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||
| 118 | # Store and return | ||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | $ids->{ $self->{id} } = $self; | |||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||
| 125 | ## Public Object Methods ### | ||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||
| 127 | =head1 OBJECT METHODS | ||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||
| 129 | =head2 id | ||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||
| 131 | =over 4 | ||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||
| 133 | Returns the channel id. | ||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||
| 135 | =back | ||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||
| 137 | =head2 server | ||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||
| 139 | =over 4 | ||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||
| 141 | Returns the L<POE::Component::Client::AMQP> parent object. | ||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||
| 143 | =back | ||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||
| 145 | =head2 Alias | ||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||
| 147 | =over 4 | ||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||
| 149 | Returns the L<POE::Session> alias of the controlling session. | ||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||
| 151 | =back | ||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||
| 153 | =head2 do_when_created (...) | ||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||
| 155 | =over 4 | ||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||
| 157 | See L<POE::Component::Client::AMQP::do_when_startup()>; similar behavior. | ||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||
| 159 | =back | ||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||
| 161 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | ▶ | sub do_when_created { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
do_when_created: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | my ($self, $subref) = @_; | |||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | ▶ | if ($self->{is_created}) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | $subref->(); | |||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||
| 169 | else { | ||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | push @{ $self->{Callbacks}{Created} }, $subref; | |||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||
| 174 | =head2 send_frames (...) | ||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||
| 176 | =over 4 | ||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||
| 178 | Same as the POE state L<server_send>, but can be called on the object and before the channel is created. | ||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||
| 180 | =back | ||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||
| 182 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | ▶ | sub send_frames { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
send_frames: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | my ($self, @frames) = @_; | |||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | ▶ | $self->do_when_created(sub { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | $poe_kernel->post($self->{Alias}, server_send => @frames); | |||||||||||||||||||||||||||||||||||||||
| 189 | 0 | }); | |||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||
| 192 | ### Deferred methods ### | ||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||
| 194 | =head2 queue ($name, \%opts) | ||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||
| 196 | =over 4 | ||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||
| 198 | Creates a new queue named $name. If no name is given, the server will generate a name for you, which will be available in $queue_object->name after the queue is created. Returns a new L<POE::Component::Client::AMQP::Queue> object. This is a deferred call, similar to L<POE::Component::Client::AMQP::channel()>, so it can be used immediately. | ||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||
| 200 | If you pass %opts, the values you pass will override defaults in the L<Net::AMQP::Protocol::Queue::Declare::new()> call. These are arguments like 'ticket', 'passive', 'durable', 'exclusive', 'auto_delete', 'nowait' and 'arguments' (for version 0-8 of the protocol). See L<Net::AMQP::Protocol::Queue::Declare> for the details of these arguments. | ||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||
| 202 | =back | ||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||
| 204 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | ▶ | sub queue { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
queue: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | my ($self, $name, $user_opts) = @_; | |||||||||||||||||||||||||||||||||||||||
| 208 | 0 | ▶ | $user_opts ||= {}; | ||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$user_opts ||= {}
MC/DC0%0/1
$user_opts ||= {}
$user_opts
Truth table0%0/2
A
A= $user_opts
| |||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | ▶ | if (defined $name && $self->{queues}{$name}) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $name and $self->{"queues"}{$name}
MC/DC0%0/2
defined $name and $self->{"queues"}{$name}
defined $name
$self->{"queues"}{$name}
Truth table0%0/3
A and B
A= defined $nameB= $self->{"queues"}{$name}
| |||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | return $self->{queues}{$name}; | |||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||
| 214 | # Queue doesn't exist; create the object and setup deferred creation triggers | ||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | ▶ | my %opts = ( | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 217 | ticket => 0, | ||||||||||||||||||||||||||||||||||||||||
| 218 | queue => (defined $name ? $name : ''), | ||||||||||||||||||||||||||||||||||||||||
| 219 | #passive => 0, # if set, server will not create the queue; checks for existance | ||||||||||||||||||||||||||||||||||||||||
| 220 | #durable => 0, # will remain active after restart | ||||||||||||||||||||||||||||||||||||||||
| 221 | exclusive => 1, # may only be consumed from the current connection | ||||||||||||||||||||||||||||||||||||||||
| 222 | auto_delete => 1, # queue is deleted after the last consumer | ||||||||||||||||||||||||||||||||||||||||
| 223 | #nowait => 0, # do not send a DeclareOk response | ||||||||||||||||||||||||||||||||||||||||
| 224 | #arguments => {}, | ||||||||||||||||||||||||||||||||||||||||
| 225 | %$user_opts, | ||||||||||||||||||||||||||||||||||||||||
| 226 | ); | ||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||
| 228 | # TODO: if user sets $opts{nowait}, we can't do the synchronous_callback below | ||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | my $queue = POE::Component::Client::AMQP::Queue->create( | |||||||||||||||||||||||||||||||||||||||
| 231 | name => $name, | ||||||||||||||||||||||||||||||||||||||||
| 232 | channel => $self, | ||||||||||||||||||||||||||||||||||||||||
| 233 | %opts, | ||||||||||||||||||||||||||||||||||||||||
| 234 | ); | ||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||
| 236 | # Remember it here if we have a name; otherwise wait for the callback | ||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | ▶ | $self->{queues}{$name} = $queue if defined $name; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | ▶ | $self->do_when_created(sub { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||
| 240 | $poe_kernel->post($self->{Alias}, server_send => | ||||||||||||||||||||||||||||||||||||||||
| 241 | Net::AMQP::Frame::Method->new( | ||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | ▶ | synchronous_callback => sub { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | ▶ | if (! defined $name) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 244 | # I didn't know the name of the queue at the time of Queue.Declare | ||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | my $response_frame = $_[0]->method_frame; | |||||||||||||||||||||||||||||||||||||||
| 246 | 0 | $self->{queues}{ $response_frame->queue } = $queue; | |||||||||||||||||||||||||||||||||||||||
| 247 | 0 | $queue->name( $response_frame->queue ); | |||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||
| 249 | $queue->created() | ||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | }, | |||||||||||||||||||||||||||||||||||||||
| 251 | 0 | method_frame => Net::AMQP::Protocol::Queue::Declare->new(%opts), | |||||||||||||||||||||||||||||||||||||||
| 252 | ), | ||||||||||||||||||||||||||||||||||||||||
| 253 | ); | ||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | }); | |||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | return $queue; | |||||||||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||
| 259 | =head2 qos (\%opts, $on_complete) | ||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||
| 261 | =over 4 | ||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||
| 263 | Requests a specific quality of service from the server. The %opts are 'prefetch_size' and 'prefetch_count'. | ||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||
| 265 | $on_complete is an option callback that will be passed a boolean value indicating whether the QoS was set. | ||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||
| 267 | This is a deferred call, similar to L<POE::Component::Client::AMQP::channel()>, so it can be used immediately. | ||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||
| 269 | =back | ||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||
| 271 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | ▶ | sub qos { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
qos: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | my ($self, $opts, $on_complete) = @_; | |||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | ▶ | $on_complete ||= sub {}; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Condition0%0/3
$on_complete ||= sub {
}
MC/DC0%0/2
$on_complete ||= sub {
}
$on_complete
sub {
}
Truth table0%0/3
A ||= B
A= $on_completeB= sub {
}
| |||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | ▶ | $self->do_when_created(sub { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||
| 279 | $poe_kernel->post($self->{Alias}, server_send => | ||||||||||||||||||||||||||||||||||||||||
| 280 | Net::AMQP::Frame::Method->new( | ||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | ▶ | synchronous_callback => sub { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | my $response_frame = $_[0]->method_frame; | |||||||||||||||||||||||||||||||||||||||
| 283 | 0 | my $success = $response_frame->isa('Net::AMQP::Protocol::Basic::QosOk'); | |||||||||||||||||||||||||||||||||||||||
| 284 | 0 | $on_complete->($success); | |||||||||||||||||||||||||||||||||||||||
| 285 | }, | ||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | method_frame => Net::AMQP::Protocol::Basic::Qos->new(%$opts), | |||||||||||||||||||||||||||||||||||||||
| 287 | ), | ||||||||||||||||||||||||||||||||||||||||
| 288 | ); | ||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | }); | |||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | ▶ | sub close { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
close: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | ▶ | $self->do_when_created(sub { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | $poe_kernel->post($self->{Alias}, server_send => | |||||||||||||||||||||||||||||||||||||||
| 299 | Net::AMQP::Protocol::Channel::Close->new() | ||||||||||||||||||||||||||||||||||||||||
| 300 | ); | ||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | }); | |||||||||||||||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||
| 304 | =head1 POE STATES | ||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||
| 306 | The following are states you can post to to interact with the client. Use the alias defined in the C<create()> call above. | ||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||
| 308 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | ▶ | sub _start { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
_start: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||
| 311 | 0 | my ($self, $kernel) = @_[OBJECT, KERNEL]; | |||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | $kernel->alias_set($self->{Alias}); | |||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||
| 315 | # Request the AMQP creation of the channel | ||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | ▶ | $self->{server}->do_when_startup(sub { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||
| 318 | $kernel->post($self->{Alias}, server_send => | ||||||||||||||||||||||||||||||||||||||||
| 319 | Net::AMQP::Frame::Method->new( | ||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | ▶ | synchronous_callback => sub { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | $kernel->post($self->{Alias}, 'channel_created'); | |||||||||||||||||||||||||||||||||||||||
| 322 | }, | ||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | method_frame => Net::AMQP::Protocol::Channel::Open->new(), | |||||||||||||||||||||||||||||||||||||||
| 324 | ), | ||||||||||||||||||||||||||||||||||||||||
| 325 | ); | ||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | }); | |||||||||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | ▶ | sub channel_created { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
channel_created: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | my ($self, $kernel) = @_[OBJECT, KERNEL]; | |||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||
| 332 | # Call the callbacks if present | ||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | ▶ | if ($self->{Callbacks}{Created}) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | foreach my $subref (@{ $self->{Callbacks}{Created} }) { | |||||||||||||||||||||||||||||||||||||||
| 335 | 0 | $subref->(); | |||||||||||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | $self->{is_created} = 1; | |||||||||||||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | ▶ | sub server_input { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
server_input: not called CC=27 SCAR=66.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | my ($self, $kernel, $frame) = @_[OBJECT, KERNEL, ARG0]; | |||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||
| 345 | 0 | ▶ | if ($self->{should_be_dead}) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | $self->server->{Logger}->error("!! I should be dead !!"); | |||||||||||||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | ▶ | if ($frame->isa('Net::AMQP::Frame::Method')) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | my $method_frame = $frame->method_frame; | |||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||
| 352 | # TODO: There are probably other methods that have content following them | ||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | ▶ | if ($method_frame->isa('Net::AMQP::Protocol::Basic::Deliver') | ||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition0%0/3
$method_frame->isa("Net::AMQP::Protocol::Basic::Deliver") or $method_frame->isa("Net::AMQP::Protocol::Basic::Return")
MC/DC0%0/2
$method_frame->isa("Net::AMQP::Protocol::Basic::Deliver") or $method_frame->isa("Net::AMQP::Protocol::Basic::Return")
$method_frame->isa("Net::AMQP::Protocol::Basic::Deliver")
$method_frame->isa("Net::AMQP::Protocol::Basic::Return")
Truth table0%0/3
A or B
A= $method_frame->isa("Net::AMQP::Protocol::Basic::Deliver")B= $method_frame->isa("Net::AMQP::Protocol::Basic::Return")
| |||||||||||||||||||||||||||||||||||||||||
| 354 | || $method_frame->isa('Net::AMQP::Protocol::Basic::Return')) { | ||||||||||||||||||||||||||||||||||||||||
| 355 | # Start collecting content | ||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | $self->{collecting_content} = { method_frame => $method_frame }; | |||||||||||||||||||||||||||||||||||||||
| 357 | 0 | return; | |||||||||||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||||||||||
| 359 | elsif ($self->{collecting_content}) { | ||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | $self->server->{Logger}->error("Channel ".$self->id." got method call $method_frame when content (header or body) was expected"); | |||||||||||||||||||||||||||||||||||||||
| 361 | 0 | return; | |||||||||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||||||||||
| 363 | elsif ($method_frame->isa('Net::AMQP::Protocol::Channel::Close')) { | ||||||||||||||||||||||||||||||||||||||||
| 364 | # Come up with a descriptive reason why the channel closed | ||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | my $close_reason; | |||||||||||||||||||||||||||||||||||||||
| 367 | # If the Channel.Close event gives class and method id indicating what event cause the closure, find a | ||||||||||||||||||||||||||||||||||||||||
| 368 | # friendly name from this and use it in the close reason | ||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | ▶ | if ($method_frame->class_id && $method_frame->method_id) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$method_frame->class_id and $method_frame->method_id
MC/DC0%0/2
$method_frame->class_id and $method_frame->method_id
$method_frame->class_id
$method_frame->method_id
Truth table0%0/3
A and B
A= $method_frame->class_idB= $method_frame->method_id
| |||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | my $method_class = Net::AMQP::Frame::Method->registered_method_class($method_frame->class_id, $method_frame->method_id); | |||||||||||||||||||||||||||||||||||||||
| 371 | 0 | my ($class_name, $method_name) = $method_class =~ m{^Net::AMQP::Protocol::(.+)::(.+)$}; | |||||||||||||||||||||||||||||||||||||||
| 372 | 0 | $close_reason = "The method $class_name.$method_name caused channel " . $self->id . ' to be'; | |||||||||||||||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||||||||||||||
| 374 | else { | ||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | $close_reason = "The channel has been"; | |||||||||||||||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | $close_reason .= ' closed by the server: ' . $method_frame->reply_code . ': ' . $method_frame->reply_text; | |||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | $self->server->{Logger}->error($close_reason); | |||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | ▶ | if ($self->{CloseCallback}) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 382 | 0 | $self->{CloseCallback}->($close_reason); | |||||||||||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | ▶ | if ($self->{CascadeFailure}) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 386 | 0 | $self->server->stop() | |||||||||||||||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||||||||||||||
| 388 | else { | ||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | $kernel->call($self->{Alias}, 'server_send', | |||||||||||||||||||||||||||||||||||||||
| 390 | Net::AMQP::Protocol::Channel::CloseOk->new() | ||||||||||||||||||||||||||||||||||||||||
| 391 | ); | ||||||||||||||||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||
| 394 | # Delete references to myself in the server | ||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | delete $self->server->{channels}{ $self->id }; | |||||||||||||||||||||||||||||||||||||||
| 396 | 0 | delete $self->server->{wait_synchronous}{ $self->id }; | |||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||
| 398 | # Delete the reference to the server to reduce circular references | ||||||||||||||||||||||||||||||||||||||||
| 399 | #$self->{server} = undef;; | ||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | $self->{should_be_dead} = 1; | |||||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | $kernel->alias_remove( $self->{Alias} ); | |||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||
| 404 | 0 | return; | |||||||||||||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||||||||||||||
| 406 | elsif ($method_frame->isa('Net::AMQP::Protocol::Channel::CloseOk')) { | ||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | ▶ | if ($self->{CloseOkCallback}) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | $self->{CloseOkCallback}->(); | |||||||||||||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||
| 411 | # Delete references to myself in the server | ||||||||||||||||||||||||||||||||||||||||
| 412 | 0 | delete $self->server->{channels}{ $self->id }; | |||||||||||||||||||||||||||||||||||||||
| 413 | 0 | delete $self->server->{wait_synchronous}{ $self->id }; | |||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | $self->server->{Logger}->info("Closing channel ".$self->id."; now have channels " . join(', ', sort { $a <=> $b } keys %{ $self->server->{channels} }) . " open"); | |||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||
| 417 | # Delete the reference to the server to reduce circular references | ||||||||||||||||||||||||||||||||||||||||
| 418 | #$self->{server} = undef;; | ||||||||||||||||||||||||||||||||||||||||
| 419 | 0 | $self->{should_be_dead} = 1; | |||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||
| 421 | 0 | $kernel->alias_remove( $self->{Alias} ); | |||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||
| 423 | 0 | return; | |||||||||||||||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||||||||||||||
| 427 | elsif ($frame->isa('Net::AMQP::Frame::Header')) { | ||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | my $header_frame = $frame->header_frame; | |||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||
| 430 | 0 | my $content_meta = $self->{collecting_content}; | |||||||||||||||||||||||||||||||||||||||
| 431 | 0 | ▶ | if (! $content_meta) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 432 | 0 | $self->server->{Logger}->error("Channel ".$self->id." got header frame $header_frame when not expecting it"); | |||||||||||||||||||||||||||||||||||||||
| 433 | 0 | return; | |||||||||||||||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||
| 436 | 0 | $content_meta->{header_frame} = $header_frame; | |||||||||||||||||||||||||||||||||||||||
| 437 | 0 | $content_meta->{$_} = $frame->$_ foreach qw(weight body_size); | |||||||||||||||||||||||||||||||||||||||
| 438 | } | ||||||||||||||||||||||||||||||||||||||||
| 439 | elsif ($frame->isa('Net::AMQP::Frame::Body')) { | ||||||||||||||||||||||||||||||||||||||||
| 440 | 0 | my $content_meta = $self->{collecting_content}; | |||||||||||||||||||||||||||||||||||||||
| 441 | 0 | ▶ | if (! $content_meta) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 442 | 0 | $self->server->{Logger}->error("Channel ".$self->id." got body frame when not expecting it"); | |||||||||||||||||||||||||||||||||||||||
| 443 | 0 | return; | |||||||||||||||||||||||||||||||||||||||
| 444 | } | ||||||||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||||||||
| 446 | 0 | push @{ $content_meta->{body_frames} }, $frame; | |||||||||||||||||||||||||||||||||||||||
| 447 | 0 | $content_meta->{payload} .= $frame->payload; | |||||||||||||||||||||||||||||||||||||||
| 448 | 0 | $content_meta->{body_size_received} += length $frame->payload; | |||||||||||||||||||||||||||||||||||||||
| 449 | 0 | ▶ | if ($content_meta->{body_size_received} == $content_meta->{body_size}) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 450 | # Done collecting content | ||||||||||||||||||||||||||||||||||||||||
| 451 | 0 | delete $self->{collecting_content}; | |||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||
| 453 | 0 | ▶ | if ($content_meta->{method_frame}->isa('Net::AMQP::Protocol::Basic::Return')) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 454 | # FIXME | ||||||||||||||||||||||||||||||||||||||||
| 455 | 0 | $self->server->{Logger}->error("Channel ".$self->id." received a returned payload (".$content_meta->{method_frame}->reply_code . ': ' . $content_meta->{method_frame}->reply_text ."); no way yet to handle this"); | |||||||||||||||||||||||||||||||||||||||
| 456 | 0 | return; | |||||||||||||||||||||||||||||||||||||||
| 457 | } | ||||||||||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||||||||||
| 459 | 0 | my $consumer_tag = $content_meta->{method_frame}->consumer_tag; | |||||||||||||||||||||||||||||||||||||||
| 460 | 0 | my $consumer_data = $self->{consumers}{$consumer_tag}; | |||||||||||||||||||||||||||||||||||||||
| 461 | 0 | ▶ | if (! $consumer_data) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 462 | 0 | $self->server->{Logger}->error("Channel ".$self->id." received content with consumer tag $consumer_tag" | |||||||||||||||||||||||||||||||||||||||
| 463 | . " when no record of this Consume subscription exists"); | ||||||||||||||||||||||||||||||||||||||||
| 464 | 0 | return; | |||||||||||||||||||||||||||||||||||||||
| 465 | } | ||||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||||
| 467 | 0 | $content_meta->{$_} = $consumer_data->{$_} foreach qw(queue opts); | |||||||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||||||
| 469 | # Let the consumer know via the recorded callback | ||||||||||||||||||||||||||||||||||||||||
| 470 | 0 | my $callback_return = $consumer_data->{callback}($content_meta->{payload}, $content_meta); | |||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||
| 472 | # The return value is normally ignored unless the Consume call had 'no_ack => 0', | ||||||||||||||||||||||||||||||||||||||||
| 473 | # in which case a 'true' response from the callback will automatically ack | ||||||||||||||||||||||||||||||||||||||||
| 474 | 0 | ▶ | if (defined $callback_return && ! $consumer_data->{opts}{no_ack}) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $callback_return and not $consumer_data->{"opts"}{"no_ack"}
MC/DC0%0/2
defined $callback_return and not $consumer_data->{"opts"}{"no_ack"}
defined $callback_return
not $consumer_data->{"opts"}{"no_ack"}
Truth table0%0/3
A and not(B)
A= defined $callback_returnB= not $consumer_data->{"opts"}{"no_ack"}
| |||||||||||||||||||||||||||||||||||||||||
| 475 | 0 | my @message; | |||||||||||||||||||||||||||||||||||||||
| 476 | 0 | ▶ | if ($callback_return eq AMQP_ACK) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||
| 477 | push @message, Net::AMQP::Protocol::Basic::Ack->new( | ||||||||||||||||||||||||||||||||||||||||
| 478 | delivery_tag => $content_meta->{method_frame}->delivery_tag | ||||||||||||||||||||||||||||||||||||||||
| 479 | 0 | ); | |||||||||||||||||||||||||||||||||||||||
| 480 | } | ||||||||||||||||||||||||||||||||||||||||
| 481 | elsif ($callback_return eq AMQP_REJECT) { | ||||||||||||||||||||||||||||||||||||||||
| 482 | push @message, Net::AMQP::Protocol::Basic::Reject->new( | ||||||||||||||||||||||||||||||||||||||||
| 483 | delivery_tag => $content_meta->{method_frame}->delivery_tag, | ||||||||||||||||||||||||||||||||||||||||
| 484 | 0 | requeue => 1, | |||||||||||||||||||||||||||||||||||||||
| 485 | ); | ||||||||||||||||||||||||||||||||||||||||
| 486 | } | ||||||||||||||||||||||||||||||||||||||||
| 487 | 0 | ▶ | $kernel->call($self->{Alias}, server_send => @message) if @message; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 488 | } | ||||||||||||||||||||||||||||||||||||||||
| 489 | } | ||||||||||||||||||||||||||||||||||||||||
| 490 | } | ||||||||||||||||||||||||||||||||||||||||
| 491 | } | ||||||||||||||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||||||||||||
| 493 | =head2 server_send (@frames) | ||||||||||||||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||||||||||||||
| 495 | =over 4 | ||||||||||||||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||||||||||||||
| 497 | Wraps the parent L<POE::Component::Client::AMQP::server_send()> method, setting the channel id of all the frames sent to my channel id. | ||||||||||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||||||||||
| 499 | =back | ||||||||||||||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||||||||||||||
| 501 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||||||
| 503 | 0 | ▶ | sub server_send { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
server_send: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 504 | 0 | my ($self, $kernel, @output) = @_[OBJECT, KERNEL, ARG0 .. $#_]; | |||||||||||||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||||||||||||
| 506 | # Override the channel on each frame with my own channel id | ||||||||||||||||||||||||||||||||||||||||
| 507 | 0 | my @frames; | |||||||||||||||||||||||||||||||||||||||
| 508 | 0 | foreach my $output (@output) { | |||||||||||||||||||||||||||||||||||||||
| 509 | 0 | ▶ | if (! ref $output) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 510 | 0 | print STDERR "Invalid output value '$output' to channel server_send\n"; | |||||||||||||||||||||||||||||||||||||||
| 511 | 0 | next; | |||||||||||||||||||||||||||||||||||||||
| 512 | } | ||||||||||||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||||||||||
| 514 | 0 | ▶ | my $frame = $output->isa("Net::AMQP::Protocol::Base") ? $output->frame_wrap : $output; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 515 | 0 | $frame->channel($self->id); | |||||||||||||||||||||||||||||||||||||||
| 516 | 0 | push @frames, $frame; | |||||||||||||||||||||||||||||||||||||||
| 517 | } | ||||||||||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||||||||||
| 519 | # Pass through to the server session | ||||||||||||||||||||||||||||||||||||||||
| 520 | 0 | $kernel->post($self->{server}{Alias}, server_send => @frames); | |||||||||||||||||||||||||||||||||||||||
| 521 | } | ||||||||||||||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||||||||||||||
| 523 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||||||||||||||
| 525 | L<POE::Component::Client::AMQP> | ||||||||||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||||||||||
| 527 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||||||||
| 529 | Copyright (c) 2009 Eric Waters and XMission LLC (http://www.xmission.com/). All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||||||||||
| 531 | The full text of the license can be found in the LICENSE file included with this module. | ||||||||||||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||||||||||
| 533 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||||||||
| 535 | Eric Waters <ewaters@gmail.com> | ||||||||||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||||||||||
| 537 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||||||||||||||
| 539 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||