Class: Qpid::Proton::Receiver

Inherits:
Link show all
Defined in:
lib/core/receiver.rb

Overview

The receiving endpoint.

See Also:

Constant Summary

Constants inherited from Link

Link::RCV_FIRST, Link::RCV_SECOND, Link::SND_MIXED, Link::SND_SETTLED, Link::SND_UNSETTLED

Constants inherited from Endpoint

Endpoint::LOCAL_ACTIVE, Endpoint::LOCAL_CLOSED, Endpoint::LOCAL_MASK, Endpoint::LOCAL_UNINIT, Endpoint::REMOTE_ACTIVE, Endpoint::REMOTE_CLOSED, Endpoint::REMOTE_MASK, Endpoint::REMOTE_UNINIT

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Link

#==, #advance, #close, #connection, #current, #delivery, #drained, #error, #next, #rcv_settle_mode, #rcv_settle_mode=, #remote_source, #remote_target, #session, #snd_settle_mode, #snd_settle_mode=, #source, #target

Methods inherited from Endpoint

#closed?, #local_closed?, #local_open?, #local_uninit?, #open?, #remote_closed?, #remote_open?, #remote_uninit?, #transport, #work_queue

Instance Attribute Details

#auto_acceptBoolean (readonly)

Returns auto_accept flag, see #open.

Returns:

  • (Boolean)

    auto_accept flag, see #open



62
63
64
# File 'lib/core/receiver.rb', line 62

def auto_accept
  @auto_accept
end

#credit_windowInteger (readonly)

Returns credit window, see #open.

Returns:

  • (Integer)

    credit window, see #open



59
60
61
# File 'lib/core/receiver.rb', line 59

def credit_window
  @credit_window
end

Instance Method Details

#flow(n)

Grants credit for incoming deliveries.

Parameters:

  • n (Integer)

    The amount to increment the link credit.



93
94
95
# File 'lib/core/receiver.rb', line 93

def flow(n)
  Cproton.pn_link_flow(@impl, n)
end

#open_receiver(address) #open_receiver(opts)

Overloads:

  • #open_receiver(address)

    Parameters:

    • address (String)

      address of the source to receive from

  • #open_receiver(opts)

    Parameters:

    • opts (Hash)

      Receiver options, see #open

    Options Hash (opts):

    • :credit_window (Integer)

      automatically maintain this much credit for messages to be pre-fetched while the current message is processed.

    • :auto_accept (Boolean)

      if true, deliveries that are not settled by the application in MessagingHandler#on_message are automatically accepted.

    • :dynamic (Boolean) — default: false

      dynamic property for source Terminus#dynamic

    • :source (String, Hash)

      source address or source options, see Terminus#apply

    • :target (String, Hash)

      target address or target options, see Terminus#apply

    • :name (String) — default: generated

      unique name for the link.



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/core/receiver.rb', line 46

def open(opts=nil)
  opts ||= {}
  opts = { :source => opts } if opts.is_a? String
  @credit_window =  opts.fetch(:credit_window, 10)
  @auto_accept = opts.fetch(:auto_accept, true)
  source.apply(opts[:source])
  target.apply(opts[:target])
  source.dynamic = !!opts[:dynamic]
  super()
  self
end

#receive(limit) ⇒ Integer?

Allows receiving up to the specified limit of data from the remote endpoint.

Note that large messages can be streamed across the network, so just because there is no data to read does not imply the message is complete.

To ensure the entirety of the message data has been read, either call #receive until nil is returned, or verify that #partial? is false and Delivery#pending is 0.

the stream was reached.

Parameters:

  • limit (Integer)

    The maximum bytes to receive.

Returns:

  • (Integer, nil)

    The number of bytes received, or nil if the end of

Raises:

See Also:

  • To see how much buffer space is needed.


116
117
118
119
120
121
# File 'lib/core/receiver.rb', line 116

def receive(limit)
  (n, bytes) = Cproton.pn_link_recv(@impl, limit)
  return nil if n == Qpid::Proton::Error::EOS
  raise LinkError.new("[#{n}]: #{Cproton.pn_link_error(@impl)}") if n < 0
  return bytes
end