| 1 |
# Licensed to the Apache Software Foundation (ASF) under one |
| 2 |
# or more contributor license agreements. See the NOTICE file |
| 3 |
# distributed with this work for additional information |
| 4 |
# regarding copyright ownership. The ASF licenses this file |
| 5 |
# to you under the Apache License, Version 2.0 (the |
| 6 |
# "License"); you may not use this file except in compliance |
| 7 |
# with the License. You may obtain a copy of the License at |
| 8 |
# |
| 9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 |
# |
| 11 |
# Unless required by applicable law or agreed to in writing, |
| 12 |
# software distributed under the License is distributed on an |
| 13 |
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 |
# KIND, either express or implied. See the License for the |
| 15 |
# specific language governing permissions and limitations |
| 16 |
# under the License. |
| 17 |
|
| 18 |
|
| 19 |
module Qpid::Proton |
| 20 |
|
| 21 |
# The sending endpoint. |
| 22 |
# |
| 23 |
# @see Receiver |
| 24 |
# |
| 25 |
class Sender < Link |
| 26 |
|
| 27 |
# @private |
| 28 |
include Util::ErrorHandler |
| 29 |
|
| 30 |
# Open the {Sender} link |
| 31 |
# |
| 32 |
# @overload open_sender(address) |
| 33 |
# @param address [String] address of the target to send to |
| 34 |
# @overload open_sender(opts) |
| 35 |
# @option opts [Boolean] :auto_settle (true) If true (default), automatically settle |
| 36 |
# messages upon receiving a settled disposition for that delivery. Otherwise messages |
| 37 |
# must be explicitly settled. |
| 38 |
# @option opts [Boolean] :dynamic (false) dynamic property for source {Terminus#dynamic} |
| 39 |
# @option opts [String,Hash] :source source address or source options, see {Terminus#apply} |
| 40 |
# @option opts [String,Hash] :target target address or target options, see {Terminus#apply} |
| 41 |
# @option opts [String] :name (generated) unique name for the link. |
| 42 |
def open(opts=nil) |
| 43 |
opts = { :target => opts } if opts.is_a? String |
| 44 |
opts ||= {} |
| 45 |
target.apply opts[:target] |
| 46 |
source.apply opts[:source] |
| 47 |
target.dynamic = !!opts[:dynamic] |
| 48 |
@auto_settle = opts.fetch(:auto_settle, true) |
| 49 |
super() |
| 50 |
self |
| 51 |
end |
| 52 |
|
| 53 |
# @return [Boolean] auto_settle flag, see {#open} |
| 54 |
attr_reader :auto_settle |
| 55 |
|
| 56 |
# Hint to the remote receiver about the number of messages available. |
| 57 |
# The receiver may use this to optimize credit flow, or may ignore it. |
| 58 |
# @param n [Integer] The number of deliveries potentially available. |
| 59 |
def offered(n) |
| 60 |
Cproton.pn_link_offered(@impl, n) |
| 61 |
end |
| 62 |
|
| 63 |
# TODO aconway 2017-12-05: incompatible, used to return bytes sent. |
| 64 |
|
| 65 |
# @!method send(message) |
| 66 |
# Send a message. |
| 67 |
# @param message [Message] The message to send. |
| 68 |
# @return [Tracker] Tracks the outcome of the message. |
| 69 |
def send(message, *args) |
| 70 |
tag = nil |
| 71 |
if args.size > 0 |
| 72 |
# deprecated: allow tag in args[0] for backwards compat |
| 73 |
raise ArgumentError("too many arguments") if args.size > 1 |
| 74 |
tag = args[0] |
| 75 |
end |
| 76 |
tag ||= next_tag |
| 77 |
t = Tracker.new(Cproton.pn_delivery(@impl, tag)) |
| 78 |
Cproton.pn_link_send(@impl, message.encode) |
| 79 |
Cproton.pn_link_advance(@impl) |
| 80 |
t.settle if snd_settle_mode == SND_SETTLED |
| 81 |
return t |
| 82 |
end |
| 83 |
|
| 84 |
# @deprecated use {#send} |
| 85 |
def stream(bytes) |
| 86 |
deprecated __method__, "send" |
| 87 |
Cproton.pn_link_send(@impl, bytes) |
| 88 |
end |
| 89 |
|
| 90 |
# @deprecated internal use only |
| 91 |
def delivery_tag() deprecated(__method__); next_tag; end |
| 92 |
|
| 93 |
private |
| 94 |
|
| 95 |
def initialize(*arg) super; @tag_count = 0; end |
| 96 |
def next_tag() (@tag_count += 1).to_s(32); end |
| 97 |
can_raise_error :stream, :error_class => Qpid::Proton::LinkError |
| 98 |
end |
| 99 |
end |