Class: Mqlight::ProtonContainer
- Inherits:
-
Object
- Object
- Mqlight::ProtonContainer
- Includes:
- Logging, Qpid::Proton::Util::ErrorHandler
- Defined in:
- lib/mqlight/proton_container.rb
Overview
This class handles the interaction with the qpid_proton and protecting access via multible thread. Must methods are wrapped in a ‘synchronize’ block to ensure only one thread has access to the qpid proton at any one time.
Defined Under Namespace
Classes: DeliveryMessage
Class Method Summary collapse
-
.finalize!(impl) ⇒ Object
No synchronize as dead lock can occur.
Instance Method Summary collapse
-
#accept(_link) ⇒ Object
Performs a accept of the given message/track with error handling.
- #check_for_out_of_sequence_messages ⇒ Object
-
#check_sasl_outcome ⇒ Object
Check to see if SASL status has changed.
-
#check_started ⇒ boolean
Check to see of the connection has started and then if there were any errors.
- #close_link(destination, ttl) ⇒ Object
- #collect_message ⇒ Object
-
#connect(service) ⇒ Object
Attempts to connect to the given service.
- #create_delivery_message(service) ⇒ Object
- #create_subscription(destination) ⇒ Object
- #drain_message(link) ⇒ Object
-
#error ⇒ Object
No synchronize as dead lock can occur.
- #free_messenger ⇒ Object
-
#initialize(thread_vars, id) ⇒ ProtonContainer
constructor
A new instance of ProtonContainer.
- #interpret_message ⇒ Object
-
#link_up?(link) ⇒ Boolean
Check to see if the subscription link is up?.
- #message? ⇒ Boolean
- #open_for_message(destination) ⇒ Object
- #outbound_pending? ⇒ Boolean
- #proton_push(msg) ⇒ Object
- #put_message(msg, qos) ⇒ Object
-
#reinstate_links ⇒ Object
This method reinstates all the active subscriptions that were present when the connect to the server was lost.
- #remote_idle_timeout(service) ⇒ Object
-
#settle(_link) ⇒ Object
Performs a settle of the given message/track with error handling.
-
#settle_mode=(qos) ⇒ Object
Configures the settle mode based on the given QoS.
- #sockets_open=(state) ⇒ Object
- #sockets_open? ⇒ Boolean
- #started? ⇒ Boolean
- #starting? ⇒ Boolean
- #stop ⇒ Object
- #tracker ⇒ Object
-
#tracker_condition_description(default_value) ⇒ Object
returns the associated error condition/description store in the selected tracker for the messenger_impl parameter.
- #tracker_status ⇒ Object
-
#wait_messenger_started(service) ⇒ Object
Monitor the lower level waiting for the connection to be confirmed as started.
Methods included from Logging
Methods included from Qpid::Proton::Util::ErrorHandler
#can_raise_error, #check_for_error, #create_exception_handler_wrapper, included
Constructor Details
#initialize(thread_vars, id) ⇒ ProtonContainer
Returns a new instance of ProtonContainer.
33 34 35 36 37 38 39 |
# File 'lib/mqlight/proton_container.rb', line 33 def initialize(thread_vars, id) @thread_vars = thread_vars @container = Mutex.new @container_resource = ConditionVariable.new @id = id @sockets_open = false end |
Class Method Details
.finalize!(impl) ⇒ Object
No synchronize as dead lock can occur
261 262 263 264 265 |
# File 'lib/mqlight/proton_container.rb', line 261 def self.finalize!(impl) proc do # Cproton.pn_messenger_free(impl) unless @messenger_impl.nil? end end |
Instance Method Details
#accept(_link) ⇒ Object
Performs a accept of the given message/track with error handling
593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 |
# File 'lib/mqlight/proton_container.rb', line 593 def accept(_link) logger.entry(@id) { self.class.to_s + '#' + __method__.to_s } parms = Hash[method(__method__).parameters.map do |parm| [parm[1], eval(parm[1].to_s)] end] logger.parms { parms } @container.synchronize do tracker = Cproton.pn_messenger_incoming_tracker(@messenger_impl) Cproton.pn_messenger_accept(@messenger_impl, tracker, 0) fail Mqlight::NetworkError, Cproton.pn_error_text( Cproton.pn_messenger_error(@messenger_impl)) \ unless Cproton.pn_messenger_errno(@messenger_impl) == 0 end logger.exit(@id) { self.class.to_s + '#' + __method__.to_s } rescue => e logger.throw(@id, e) { self.class.to_s + '#' + __method__.to_s } raise e end |
#check_for_out_of_sequence_messages ⇒ Object
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
# File 'lib/mqlight/proton_container.rb', line 236 def logger.entry_often(@id) { self.class.to_s + '#' + __method__.to_s } @container.synchronize do break if @messenger_impl.nil? Cproton.pn_messenger_work(@messenger_impl, 1000) if Cproton.pn_messenger_errno(@messenger_impl) != 0 && started? unless sockets_open? # Braces of the belt and braces logger.data(@id, 'Detected lower level socket closed') do self.class.to_s + '#' + __method__.to_s end @thread_vars.change_state(:retrying, Mqlight::NetworkError.new( 'Connection terminated')) \ if @thread_vars.state == :started end end logger.exit_often(@id) { self.class.to_s + '#' + __method__.to_s } end |
#check_sasl_outcome ⇒ Object
Check to see if SASL status has changed. If change check for connection closed and report error. there were any errors.
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/mqlight/proton_container.rb', line 163 def check_sasl_outcome logger.entry(@id) { self.class.to_s + '#' + __method__.to_s } transport = Cproton.pn_connection_transport(@connection); outcome = Cproton.pn_sasl_outcome(transport) if outcome >= 1 Cproton.pn_connection_was_closed(@messenger_impl, @connection) if (Cproton.pn_messenger_errno(@messenger_impl) != 0) text = Cproton.pn_error_text( Cproton.pn_messenger_error(@messenger_impl)) logger.data(@id, 'Throwing : ' + text) \ { self.class.to_s + '#' + __method__.to_s } fail Qpid::Proton::ProtonError, text end logger.exit(@id) { self.class.to_s + '#' + __method__.to_s } end end |
#check_started ⇒ boolean
Check to see of the connection has started and then if there were any errors.
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/mqlight/proton_container.rb', line 141 def check_started logger.entry(@id) { self.class.to_s + '#' + __method__.to_s } Cproton.pn_messenger_work(@messenger_impl, 1000) rc = Cproton::pn_messenger_started(@messenger_impl) if (Cproton.pn_messenger_errno(@messenger_impl) != 0) text = Cproton.pn_error_text( Cproton.pn_messenger_error(@messenger_impl)) logger.data(@id, 'Throwing : ' + text) \ { self.class.to_s + '#' + __method__.to_s } puts "Thrown 001" fail Qpid::Proton::ProtonError, text end logger.exit(@id,rc) { self.class.to_s + '#' + __method__.to_s } rc end |
#close_link(destination, ttl) ⇒ Object
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 |
# File 'lib/mqlight/proton_container.rb', line 401 def close_link(destination, ttl) logger.entry(@id) { self.class.to_s + '#' + __method__.to_s } parms = Hash[method(__method__).parameters.map do |parm| [parm[1], eval(parm[1].to_s)] end] Logging.logger.parms(@id, parms) do self.class.to_s + '#' + __method__.to_s end link = nil @container.synchronize do # find and close the link link = Cproton.pn_messenger_get_link(@messenger_impl, destination.address, false) fail Mqlight::InternalError, "Missing link for close_link(#{destination}, #{ttl})" if link.nil? if ttl == 0 Cproton.pn_terminus_set_expiry_policy(Cproton.pn_link_target(link), Cproton::PN_EXPIRE_WITH_LINK) Cproton.pn_terminus_set_expiry_policy(Cproton.pn_link_source(link), Cproton::PN_EXPIRE_WITH_LINK) Cproton.pn_terminus_set_timeout(Cproton.pn_link_target(link), ttl) Cproton.pn_terminus_set_timeout(Cproton.pn_link_source(link), ttl) end expiry_policy = Cproton.pn_terminus_get_expiry_policy(Cproton.pn_link_target(link)) timeout = Cproton.pn_terminus_get_timeout(Cproton.pn_link_target(link)) # if we're not expiring the link, we won't get an ACK from the server # so all we can do is wait until our request has gone over the network if timeout > 0 || expiry_policy == Cproton::PN_EXPIRE_NEVER Cproton.pn_link_detach(link) until Cproton.pn_link_remote_detached(link) Cproton.pn_messenger_work(@messenger_impl, 1000) # TODO: long wait here .. could lower level signal to release earlier? @container_resource.wait(@container, 1) end Cproton.pn_messenger_reclaim_link(@messenger_impl, link) Cproton.pn_link_free(link) else # otherwise we can wait for server-side confirmation of the close # Cproton.pn_link_close(link) while (Cproton.pn_link_state(link) & Cproton::PN_REMOTE_CLOSED) == 0 Cproton.pn_messenger_work(@messenger_impl, 1000) @container_resource.wait(@container, 1) end end end logger.exit(@id, link) { self.class.to_s + '#' + __method__.to_s } end |
#collect_message ⇒ Object
535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 |
# File 'lib/mqlight/proton_container.rb', line 535 def logger.entry(@id) { self.class.to_s + '#' + __method__.to_s } msg = nil @container.synchronize do msg = Qpid::Proton::Message.new begin Cproton.pn_messenger_work(@messenger_impl, 1000) check_for_error(Cproton.pn_messenger_get(@messenger_impl, msg.impl)) msg.post_decode rescue => error logger.throw(@id, error) { self.class.to_s + '#' + __method__.to_s } raise error end end logger.exit(@id) { self.class.to_s + '#' + __method__.to_s } msg # return the message end |
#connect(service) ⇒ Object
Attempts to connect to the given service. If it fails it will throw an exception indicating the failure type.
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 |
# File 'lib/mqlight/proton_container.rb', line 46 def connect(service) logger.entry(@id) { self.class.to_s + '#' + __method__.to_s } parms = Hash[method(__method__).parameters.map do |parm| [parm[1], eval(parm[1].to_s)] end] logger.parms(@id, parms) { self.class.to_s + '#' + __method__.to_s } @container.synchronize do @messenger_impl = Cproton.pn_messenger(@id) Cproton.pn_messenger_set_flags(@messenger_impl, Cproton::PN_FLAGS_CHECK_ROUTES | Cproton::PN_FLAGS_EXTERNAL_SOCKET) Cproton.pn_messenger_set_passive(@messenger_impl, true) Cproton.pn_messenger_set_incoming_window(@messenger_impl, 1024) Cproton.pn_messenger_set_outgoing_window(@messenger_impl, 1024) Cproton.pn_messenger_set_external_socket(@messenger_impl) Cproton.pn_messenger_route(@messenger_impl, service.pattern + '/*', service.address + '/$1') check_for_error(Cproton.pn_messenger_start(@messenger_impl)) @connection = Cproton.pn_messenger_resolve(@messenger_impl, service.address) fail(Mqlight::InternalError, "Could not resolve #{service.pattern} to a connection") \ if @connection.nil? end logger.exit(@id) { self.class.to_s + '#' + __method__.to_s } rescue => e Logging.logger.throw(nil, e) { self.class.to_s + '#' + __method__.to_s } raise e end |
#create_delivery_message(service) ⇒ Object
731 732 733 734 735 736 737 738 739 740 |
# File 'lib/mqlight/proton_container.rb', line 731 def (service) logger.entry(@id) { self.class.to_s + '#' + __method__.to_s } parms = Hash[method(__method__).parameters.map do |parm| [parm[1], eval(parm[1].to_s)] end] logger.parms(@id, parms) { self.class.to_s + '#' + __method__.to_s } rc = DeliveryMessage.new(@messenger_impl, service, @container) logger.exit(@id) { self.class.to_s + '#' + __method__.to_s } rc end |
#create_subscription(destination) ⇒ Object
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 |
# File 'lib/mqlight/proton_container.rb', line 354 def create_subscription(destination) logger.entry(@id) { self.class.to_s + '#' + __method__.to_s } parms = Hash[method(__method__).parameters.map do |parm| [parm[1], eval(parm[1].to_s)] end] Logging.logger.parms(@id, parms) do self.class.to_s + '#' + __method__.to_s end rc = 0 @container.synchronize do Cproton.pn_messenger_subscribe_ttl(@messenger_impl, destination.address, destination.ttl) rc = Cproton.pn_messenger_get_link(@messenger_impl, destination.address, false) end logger.exit(@id, rc) { self.class.to_s + '#' + __method__.to_s } rc end |
#drain_message(link) ⇒ Object
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 |
# File 'lib/mqlight/proton_container.rb', line 511 def (link) logger.entry(@id) { self.class.to_s + '#' + __method__.to_s } rc = 0 @container.synchronize do # if no message was received, we set the drain flag and wait for the # server to advance the delivery-count, consuming our credit Cproton.pn_link_drain(link, 0) while Cproton.pn_link_draining(link) && started? logger.data(@id, 'Waiting for drain to complete') do self.class.to_s + '#' + __method__.to_s end Cproton.pn_messenger_work(@messenger_impl, 1000) @container_resource.wait(@container, 1) end rc = Cproton.pn_messenger_incoming(@messenger_impl) > 0 end logger.exit(@id, rc) { self.class.to_s + '#' + __method__.to_s } rc end |
#error ⇒ Object
No synchronize as dead lock can occur
270 271 272 |
# File 'lib/mqlight/proton_container.rb', line 270 def error Cproton.pn_error_text(Cproton.pn_messenger_error(@messenger_impl)) end |
#free_messenger ⇒ Object
183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/mqlight/proton_container.rb', line 183 def free_messenger logger.entry(@id) { self.class.to_s + '#' + __method__.to_s } @container.synchronize do unless @messenger_impl.nil? # XXX: this segfaults #Cproton.pn_messenger_work(@messenger_impl, 1000) #Cproton.pn_messenger_free(@messenger_impl) @messenger_impl = nil end end logger.exit(@id) { self.class.to_s + '#' + __method__.to_s } end |
#interpret_message ⇒ Object
766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 |
# File 'lib/mqlight/proton_container.rb', line 766 def text = Cproton.pn_error_text( Cproton.pn_messenger_error(@messenger_impl)) error = Cproton.pn_messenger_error(@messenger_impl) Cproton.pn_error_clear(error) logger.data(@id, "interpreting message: #{text}") do self.class.to_s + '#' + __method__.to_s end unless text.nil? if text.include? '_Takeover' @thread_vars.change_state(:stopped, Mqlight::ReplacedError.new(text)) elsif text.include? 'connection aborted' @thread_vars.change_state(:retrying, Mqlight::NetworkError.new(text)) else @thread_vars.change_state(:retrying, Mqlight::NetworkError.new(text)) end end end |
#link_up?(link) ⇒ Boolean
Check to see if the subscription link is up?
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 |
# File 'lib/mqlight/proton_container.rb', line 378 def link_up?(link) logger.entry(@id) { self.class.to_s + '#' + __method__.to_s } rc = true @container.synchronize do Cproton.pn_messenger_work(@messenger_impl, 1000) if ((Cproton.pn_link_state(link) & Cproton::PN_REMOTE_ACTIVE) == 0) # Still down, was there an error? fail Mqlight::SubscribedError, Cproton.pn_error_text( Cproton.pn_messenger_error(@messenger_impl)) unless \ Cproton.pn_messenger_errno(@messenger_impl) == 0 rc = false end end logger.exit(@id, rc.to_s) { self.class.to_s + '#' + __method__.to_s } rc end |
#message? ⇒ Boolean
496 497 498 499 500 501 502 503 504 505 506 |
# File 'lib/mqlight/proton_container.rb', line 496 def logger.entry_often(@id) { self.class.to_s + '#' + __method__.to_s } rc = false @container.synchronize do rc = Cproton.pn_messenger_incoming(@messenger_impl) > 0 end logger.exit_often(@id, rc) { self.class.to_s + '#' + __method__.to_s } rc end |
#open_for_message(destination) ⇒ Object
460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 |
# File 'lib/mqlight/proton_container.rb', line 460 def (destination) logger.entry(@id) { self.class.to_s + '#' + __method__.to_s } link = nil @container.synchronize do link = Cproton.pn_messenger_get_link(@messenger_impl, destination.address, false) unless link.nil? Cproton.pn_link_flow(link, 1) if Cproton.pn_link_credit(link) == 0 begin Cproton.pn_messenger_set_timeout(@messenger_impl, 250) check_for_error(Cproton.pn_messenger_recv(@messenger_impl, -2)) rescue Qpid::Proton::TimeoutError logger.debug(@id, 'TimeoutError. This is fine.') do self.class.to_s + '#' + __method__.to_s end rescue Qpid::Proton::StateError => e # Assuming this means there is a network error, so exit logger.data(@id, 'StateError ... lost of connection.') do self.class.to_s + '#' + __method__.to_s end raise e ensure Cproton.pn_messenger_set_timeout(@messenger_impl, -1) end end end # Return the link logger.exit(@id, link) { self.class.to_s + '#' + __method__.to_s } link end |
#outbound_pending? ⇒ Boolean
308 309 310 311 312 313 314 315 316 317 |
# File 'lib/mqlight/proton_container.rb', line 308 def outbound_pending? logger.entry_often(@id) { self.class.to_s + '#' + __method__.to_s } rc = false @container.synchronize do tracker = Cproton.pn_messenger_outgoing_tracker(@messenger_impl) rc = Cproton.pn_messenger_buffered(@messenger_impl, tracker) end logger.exit_often(@id, rc) { self.class.to_s + '#' + __method__.to_s } rc end |
#proton_push(msg) ⇒ Object
708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 |
# File 'lib/mqlight/proton_container.rb', line 708 def proton_push(msg) logger.entry_often(@id) { self.class.to_s + '#' + __method__.to_s } parms = Hash[method(__method__).parameters.map do |parm| [parm[1], eval(parm[1].to_s)] end] logger.often(@id, parms) { self.class.to_s + '#' + __method__.to_s } size = 0 @container.synchronize do unless @messenger_impl.nil? size = Cproton.pn_connection_push(@connection, msg, msg.length) Cproton.pn_connection_pop(@connection, 0) if started? end end logger.exit_often(@id, size) \ { self.class.to_s + '#' + __method__.to_s } size end |
#put_message(msg, qos) ⇒ Object
277 278 279 280 281 282 283 284 285 286 287 288 289 |
# File 'lib/mqlight/proton_container.rb', line 277 def (msg, qos) logger.entry(@id) { self.class.to_s + '#' + __method__.to_s } @container.synchronize do check_for_error(Cproton.pn_messenger_put(@messenger_impl, msg)) if qos == 0 tracker = Cproton.pn_messenger_outgoing_tracker(@messenger_impl) check_for_error( Cproton.pn_messenger_settle(@messenger_impl, tracker, 0)) end check_for_error(Cproton.pn_messenger_send(@messenger_impl, 1)) end logger.exit(@id) { self.class.to_s + '#' + __method__.to_s } end |
#reinstate_links ⇒ Object
This method reinstates all the active subscriptions that were present when the connect to the server was lost.
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 |
# File 'lib/mqlight/proton_container.rb', line 200 def reinstate_links logger.entry(@id) { self.class.to_s + '#' + __method__.to_s } @container.synchronize do # for all destinations @thread_vars.destinations.each do |destination| Cproton.pn_messenger_subscribe_ttl(@messenger_impl, destination.address, destination.ttl) link = Cproton.pn_messenger_get_link(@messenger_impl, destination.address, false) while (Cproton.pn_link_state(link) & Cproton::PN_REMOTE_ACTIVE) == 0 # TODO: Let low level process I/O @container_resource.wait(@container, 1) # Perform work Cproton.pn_messenger_work(@messenger_impl, 1000) # Check for errors from last work action unless Cproton.pn_messenger_errno(@messenger_impl) == 0 # Stop on 1st failed to reinstate a subscription fail Mqlight::SubscribedError, Cproton.pn_error_text( Cproton.pn_messenger_error(@messenger_impl)) end # Short pause - ok to hold on to the lock here as # nothing else can be done until this completes. sleep 0.1 end end end logger.exit(@id) { self.class.to_s + '#' + __method__.to_s } end |
#remote_idle_timeout(service) ⇒ Object
618 619 620 621 622 623 624 625 626 627 628 629 |
# File 'lib/mqlight/proton_container.rb', line 618 def remote_idle_timeout(service) logger.entry(@id) { self.class.to_s + '#' + __method__.to_s } rc = 0 @container.synchronize do rc = Cproton.pn_messenger_get_remote_idle_timeout( @messenger_impl, service.to_s) end logger.exit(@id, rc) { self.class.to_s + '#' + __method__.to_s } rc end |
#settle(_link) ⇒ Object
Performs a settle of the given message/track with error handling.
571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 |
# File 'lib/mqlight/proton_container.rb', line 571 def settle(_link) logger.entry(@id) { self.class.to_s + '#' + __method__.to_s } parms = Hash[method(__method__).parameters.map do |parm| [parm[1], eval(parm[1].to_s)] end] logger.parms(@id, parms) { self.class.to_s + '#' + __method__.to_s } @container.synchronize do tracker = Cproton.pn_messenger_incoming_tracker(@messenger_impl) Cproton.pn_messenger_settle(@messenger_impl, tracker, 0); if Cproton.pn_messenger_errno(@messenger_impl) != 0 end logger.exit(@id) { self.class.to_s + '#' + __method__.to_s } rescue => e logger.throw(@id, e) { self.class.to_s + '#' + __method__.to_s } raise e end |
#settle_mode=(qos) ⇒ Object
Configures the settle mode based on the given QoS
655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 |
# File 'lib/mqlight/proton_container.rb', line 655 def settle_mode=(qos) logger.entry(@id) { self.class.to_s + '#' + __method__.to_s } parms = Hash[method(__method__).parameters.map do |parm| [parm[1], eval(parm[1].to_s)] end] logger.parms(@id, parms) { self.class.to_s + '#' + __method__.to_s } @container.synchronize do if qos == 0 logger.debug(@id, 'Setting snd mode to ' + \ Cproton::PN_SND_SETTLED.to_s) do self.class.to_s + '#' + __method__.to_s end Cproton.pn_messenger_set_snd_settle_mode( @messenger_impl, Cproton::PN_SND_SETTLED) logger.debug(@id, 'Setting rcv mode to ' + \ Cproton::PN_RCV_FIRST.to_s) do self.class.to_s + '#' + __method__.to_s end Cproton.pn_messenger_set_rcv_settle_mode( @messenger_impl, Cproton::PN_RCV_FIRST) elsif qos == 1 logger.debug(@id, 'Setting snd mode to ' + \ Cproton::PN_SND_UNSETTLED.to_s) do self.class.to_s + '#' + __method__.to_s end Cproton.pn_messenger_set_snd_settle_mode( @messenger_impl, Cproton::PN_SND_UNSETTLED) logger.debug(@id, 'Setting snd mode to ' + \ Cproton::PN_RCV_FIRST.to_s) do self.class.to_s + '#' + __method__.to_s end Cproton.pn_messenger_set_rcv_settle_mode( @messenger_impl, Cproton::PN_RCV_FIRST) else fail ArgumentError, "Argument qos=#{qos} is an invalid value. " \ 'Must be either QOS_AT_LEAST_ONCE(0) or QOS_AT_MOST_ONCE(1)' end end logger.exit(@id) { self.class.to_s + '#' + __method__.to_s } rescue => e logger.throw(@id, e) { self.class.to_s + '#' + __method__.to_s } raise e end |
#sockets_open=(state) ⇒ Object
128 129 130 131 132 133 |
# File 'lib/mqlight/proton_container.rb', line 128 def sockets_open=(state) logger.entry_often(@id) { self.class.to_s + '#' + __method__.to_s } @container_resource.broadcast @sockets_open = state logger.exit_often(@id) { self.class.to_s + '#' + __method__.to_s } end |
#sockets_open? ⇒ Boolean
745 746 747 |
# File 'lib/mqlight/proton_container.rb', line 745 def sockets_open? @sockets_open end |
#started? ⇒ Boolean
759 760 761 |
# File 'lib/mqlight/proton_container.rb', line 759 def started? @thread_vars.state == :started end |
#starting? ⇒ Boolean
752 753 754 |
# File 'lib/mqlight/proton_container.rb', line 752 def starting? @thread_vars.state == :starting end |
#stop ⇒ Object
634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 |
# File 'lib/mqlight/proton_container.rb', line 634 def stop logger.entry(@id) { self.class.to_s + '#' + __method__.to_s } @container.synchronize do rc = Cproton.pn_messenger_stop(@messenger_impl) if rc == Cproton::PN_INPROGRESS until Cproton.pn_messenger_stopped(@messenger_impl) Cproton.pn_connection_pop(@connection, 0) # Push the stop through @container_resource.wait(@container, 0.1) end end Cproton.pn_messenger_free(@messenger_impl) @messenger_impl = nil end logger.exit(@id) { self.class.to_s + '#' + __method__.to_s } end |
#tracker ⇒ Object
558 559 560 561 562 563 564 565 566 |
# File 'lib/mqlight/proton_container.rb', line 558 def tracker logger.entry(@id) { self.class.to_s + '#' + __method__.to_s } @container.synchronize do Cproton.pn_messenger_incoming_tracker(@messenger_impl) end logger.exit(@id) { self.class.to_s + '#' + __method__.to_s } end |
#tracker_condition_description(default_value) ⇒ Object
returns the associated error condition/description store in the selected tracker for the messenger_impl parameter.
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 |
# File 'lib/mqlight/proton_container.rb', line 322 def tracker_condition_description(default_value) Logging.logger.entry(@id) { self.class.to_s + '#' + __method__.to_s } parms = Hash[method(__method__).parameters.map do |parm| [parm[1], eval(parm[1].to_s)] end] Logging.logger.parms(@id, parms) do self.class.to_s + '#' + __method__.to_s end @container.synchronize do tracker = Cproton.pn_messenger_outgoing_tracker(@messenger_impl) return default_value if tracker.nil? delivery = Cproton.pn_messenger_delivery(@messenger_impl, tracker) return default_value if delivery.nil? disposition = Cproton.pn_delivery_remote(delivery) return default_value if disposition.nil? condition = Cproton.pn_disposition_condition(disposition) return default_value if condition.nil? description = Cproton.pn_condition_get_description(condition) return default_value if description.nil? # logger.exit(@id) { self.class.to_s + '#' + __method__.to_s } description end rescue => e Logging.logger.throw(nil, e) { self.class.to_s + '#' + __method__.to_s } raise e end |
#tracker_status ⇒ Object
294 295 296 297 298 299 300 301 302 303 |
# File 'lib/mqlight/proton_container.rb', line 294 def tracker_status logger.entry(@id) { self.class.to_s + '#' + __method__.to_s } rc = 0 @container.synchronize do tracker = Cproton.pn_messenger_outgoing_tracker(@messenger_impl) rc = Cproton.pn_messenger_status(@messenger_impl, tracker) end logger.exit(@id, rc) { self.class.to_s + '#' + __method__.to_s } rc end |
#wait_messenger_started(service) ⇒ Object
Monitor the lower level waiting for the connection to be confirmed as started.
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 |
# File 'lib/mqlight/proton_container.rb', line 85 def wait_messenger_started(service) logger.entry(@id) { self.class.to_s + '#' + __method__.to_s } finished = false Timeout.timeout(8.0) do while !finished do @container.synchronize do finished = check_started() next if finished check_sasl_outcome() end sleep(0.1) end end raise Mqlight::NetworkError, 'Connection remotely terminated' unless sockets_open? logger.exit(@id) { self.class.to_s + '#' + __method__.to_s } # Success - return rescue Timeout::Error logger.data(@id, 'Timeout exception waiting for ' + service.to_s) do self.class.to_s + '#' + __method__.to_s end free_messenger raise Mqlight::NetworkError, 'Mqlight server did not respond within timeout' rescue Qpid::Proton::ProtonError => e free_messenger error_msg = e.to_s logger.data(@id, 'Exception for ' + service.to_s + ' of ' + error_msg) do self.class.to_s + '#' + __method__.to_s end if /sasl /.match(error_msg) || /SSL /.match(error_msg) || /2035/.match(error_msg) new_msg = "AMQXR9001E:Security Error (amqp:unauthorized-access) #{error_msg}" raise Mqlight::SecurityError, new_msg else raise Mqlight::NetworkError, error_msg end end |