http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/ruby/lib/messenger/messenger.rb ---------------------------------------------------------------------- diff --git a/proton-c/bindings/ruby/lib/messenger/messenger.rb b/proton-c/bindings/ruby/lib/messenger/messenger.rb deleted file mode 100644 index 70a01de..0000000 --- a/proton-c/bindings/ruby/lib/messenger/messenger.rb +++ /dev/null @@ -1,702 +0,0 @@ -# -# 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. -# - -module Qpid::Proton::Messenger - - # The +Messenger+ class defines a high level interface for - # sending and receiving Messages. Every Messenger contains - # a single logical queue of incoming messages and a single - # logical queue of outgoing messages. These messages in these - # queues may be destined for, or originate from, a variety of - # addresses. - # - # The messenger interface is single-threaded. All methods - # except one ( #interrupt ) are intended to be used from within - # the messenger thread. - # - # === Sending & Receiving Messages - # - # The Messenger class works in conjuction with the Message class. The - # Message class is a mutable holder of message content. - # - # The put method copies its Message to the outgoing queue, and may - # send queued messages if it can do so without blocking. The send - # method blocks until it has sent the requested number of messages, - # or until a timeout interrupts the attempt. - # - # Similarly, the recv method receives messages into the incoming - # queue, and may block as it attempts to receive the requested number - # of messages, or until timeout is reached. It may receive fewer - # than the requested number. The get method pops the - # eldest Message off the incoming queue and copies it into the Message - # object that you supply. It will not block. - # - # The blocking attribute allows you to turn off blocking behavior entirely, - # in which case send and recv will do whatever they can without - # blocking, and then return. You can then look at the number - # of incoming and outgoing messages to see how much outstanding work - # still remains. - # - class Messenger - - include Qpid::Proton::Util::ErrorHandler - - can_raise_error [:send, :receive, :password=, :start, :stop, - :perform_put, :perform_get, :interrupt, - :route, :rewrite, :accept, :reject, - :incoming_window=, :outgoing_window=] - - # Creates a new +Messenger+. - # - # The +name+ parameter is optional. If one is not provided then - # a unique name is generated. - # - # ==== Options - # - # * name - the name (def. nil) - # - def initialize(name = nil) - @impl = Cproton.pn_messenger(name) - @selectables = {} - ObjectSpace.define_finalizer(self, self.class.finalize!(@impl)) - end - - def self.finalize!(impl) # :nodoc: - proc { - Cproton.pn_messenger_free(impl) - } - end - - # Returns the name. - # - def name - Cproton.pn_messenger_name(@impl) - end - - # This property contains the password for the Messenger.private_key - # file, or +nil+ if the file is not encrypted. - # - # ==== Arguments - # - # * password - the password - # - def password=(password) - Cproton.pn_messenger_set_password(@impl, password) - end - - # Returns the password property for the Messenger.private_key file. - # - def password - Cproton.pn_messenger_get_password(@impl) - end - - # Sets the timeout period, in milliseconds. - # - # A negative timeout period implies an infinite timeout. - # - # ==== Options - # - # * timeout - the timeout period - # - def timeout=(timeout) - raise TypeError.new("invalid timeout: #{timeout}") if timeout.nil? - Cproton.pn_messenger_set_timeout(@impl, timeout) - end - - # Returns the timeout period - # - def timeout - Cproton.pn_messenger_get_timeout(@impl) - end - - # Returns true if blocking mode is enabled. - # - # Enable or disable blocking behavior during message sending - # and receiving. This affects every blocking call, with the - # exception of work(). Currently, the affected calls are - # send, recv, and stop. - def blocking? - Cproton.pn_messenger_is_blocking(@impl) - end - - # Sets the blocking mode. - def blocking=(blocking) - Cproton.pn_messenger_set_blocking(@impl, blocking) - end - - # Returns true if passive mode is enabled. - # - def passive? - Cproton.pn_messenger_is_passive(@impl) - end - - # Turns passive mode on or off. - # - # When set to passive mode, Messenger will not attempt to perform I/O - # operations internally. In this mode it is necesssary to use the - # Selectable type to drive any I/O needed to perform requestioned - # actions. - # - # In this mode Messenger will never block. - # - def passive=(mode) - Cproton.pn_messenger_set_passive(@impl, mode) - end - - def deadline - tstamp = Cproton.pn_messenger_deadline(@impl) - return tstamp / 1000.0 unless tstamp.nil? - end - - # Reports whether an error occurred. - # - def error? - !Cproton.pn_messenger_errno(@impl).zero? - end - - # Returns the most recent error number. - # - def errno - Cproton.pn_messenger_errno(@impl) - end - - # Returns the most recent error message. - # - def error - Cproton.pn_error_text(Cproton.pn_messenger_error(@impl)) - end - - # Clears the current error state. - # - def clear_error - error = Cproton.pn_messenger_error(@impl) - unless error.nil? - Cproton.pn_error_clear(error) - end - end - - # For future compatibility, do not send or recv messages - # before starting the +Messenger+. - # - def start - at_exit { stop } - Cproton.pn_messenger_start(@impl) - end - - # Stops the +Messenger+, preventing it from sending or receiving - # any more messages. - # - def stop - Cproton.pn_messenger_stop(@impl) - end - - # Returns true if a Messenger is in the stopped state. - # This function does not block. - # - def stopped? - Cproton.pn_messenger_stopped(@impl) - end - - # Subscribes the Messenger to messages originating from the - # specified source. The source is an address as specified in the - # Messenger introduction with the following addition. If the - # domain portion of the address begins with the '~' character, the - # Messenger will interpret the domain as host/port, bind to it, - # and listen for incoming messages. For example "~0.0.0.0", - # "amqp://~0.0.0.0" will all bind to any local interface and - # listen for incoming messages. An address of "amqps://~0.0.0.0" - # will only permit incoming SSL connections. - # - # ==== Options - # - # * address - the source address to be subscribe - # * timeout - an optional time-to-live value, in seconds, for the - # subscription - # - def subscribe(address, timeout=0) - raise TypeError.new("invalid address: #{address}") if address.nil? - subscription = Cproton.pn_messenger_subscribe_ttl(@impl, address, timeout) - raise Qpid::Proton::ProtonError.new("Subscribe failed") if subscription.nil? - Subscription.new(subscription) - end - - # Path to a certificate file for the +Messenger+. - # - # This certificate is used when the +Messenger+ accepts or establishes - # SSL/TLS connections. This property must be specified for the - # Messenger to accept incoming SSL/TLS connections and to establish - # client authenticated outgoing SSL/TLS connection. Non client authenticated - # outgoing SSL/TLS connections do not require this property. - # - # ==== Options - # - # * certificate - the certificate - # - def certificate=(certificate) - Cproton.pn_messenger_set_certificate(@impl, certificate) - end - - # Returns the path to a certificate file. - # - def certificate - Cproton.pn_messenger_get_certificate(@impl) - end - - # Path to a private key file for the +Messenger+. - # - # The property must be specified for the +Messenger+ to accept incoming - # SSL/TLS connections and to establish client authenticated outgoing - # SSL/TLS connections. Non client authenticated SSL/TLS connections - # do not require this property. - # - # ==== Options - # - # * key - the key file - # - def private_key=(key) - Cproton.pn_messenger_set_private_key(@impl, key) - end - - # Returns the path to a private key file. - # - def private_key - Cproton.pn_messenger_get_private_key(@impl) - end - - # A path to a database of trusted certificates for use in verifying the - # peer on an SSL/TLS connection. If this property is +nil+, then the - # peer will not be verified. - # - # ==== Options - # - # * certificates - the certificates path - # - def trusted_certificates=(certificates) - Cproton.pn_messenger_set_trusted_certificates(@impl,certificates) - end - - # The path to the databse of trusted certificates. - # - def trusted_certificates - Cproton.pn_messenger_get_trusted_certificates(@impl) - end - - # Places the content contained in the message onto the outgoing - # queue of the Messenger. - # - # This method will never block, however it will send any unblocked - # Messages in the outgoing queue immediately and leave any blocked - # Messages remaining in the outgoing queue. - # The send call may then be used to block until the outgoing queue - # is empty. The outgoing attribute may be used to check the depth - # of the outgoing queue. - # - # ==== Options - # - # * message - the message - # - def put(message) - if message.nil? - raise TypeError.new("invalid message: #{message}") - end - unless message.kind_of?(Qpid::Proton::Message) - raise ::ArgumentError.new("invalid message type: #{message.class}") - end - # encode the message first - message.pre_encode - perform_put(message) - return outgoing_tracker - end - - private - - def perform_put(message) # :nodoc: - Cproton.pn_messenger_put(@impl, message.impl) - end - - public - - - # This call will block until the indicated number of messages - # have been sent, or until the operation times out. - # If n is -1 this call will block until all outgoing messages - # have been sent. If n is 0 then this call will send whatever - # it can without blocking. - # - def send(n = -1) - Cproton.pn_messenger_send(@impl, n) - end - - # Moves the message from the head of the incoming message queue into - # the supplied message object. Any content in the supplied message - # will be overwritten. - # A tracker for the incoming Message is returned. The tracker can - # later be used to communicate your acceptance or rejection of the - # Message. - # - # If no message is provided in the argument, then one is created. In - # either case, the one returned will be the fetched message. - # - # ==== Options - # - # * msg - the (optional) +Message+ instance to be used - # - def get(msg = nil) - msg_impl = nil - if msg.nil? then - msg_impl = nil - else - msg_impl = msg.impl - end - perform_get(msg_impl) - msg.post_decode unless msg.nil? - return incoming_tracker - end - - private - - def perform_get(msg) # :nodoc: - Cproton.pn_messenger_get(@impl, msg) - end - - public - - # Receives up to limit messages into the incoming queue. If no value - # for limit is supplied, this call will receive as many messages as it - # can buffer internally. If the Messenger is in blocking mode, this - # call will block until at least one Message is available in the - # incoming queue. - # - # Options ==== - # - # * limit - the maximum number of messages to receive - # - def receive(limit = -1) - Cproton.pn_messenger_recv(@impl, limit) - end - - # Returns true if the messenger is currently receiving data. - def receiving? - Cproton.pn_messenger_receiving(@impl) - end - - # Attempts interrupting of the messenger thread. - # - # The Messenger interface is single-threaded, and this is the only - # function intended to be called from outside of is thread. - # - # Call this from a non-Messenger thread to interrupt it while it - # is blocking. This will cause a ::InterruptError to be raised. - # - # If there is no currently blocking call, then the next blocking - # call will be affected, even if it is within the same thread that - # originated the interrupt. - # - def interrupt - Cproton.pn_messenger_interrupt(@impl) - end - - # Sends or receives any outstanding messages queued for a Messenger. - # - # This will block for the indicated timeout. This method may also do I/O - # other than sending and receiving messages. For example, closing - # connections after stop() has been called. - # - def work(timeout=-1) - err = Cproton.pn_messenger_work(@impl, timeout) - if (err == Cproton::PN_TIMEOUT) then - return false - else - check_for_error(err) - return true - end - end - - # Returns the number messages in the outgoing queue that have not been - # transmitted. - # - def outgoing - Cproton.pn_messenger_outgoing(@impl) - end - - # Returns the number of messages in the incoming queue that have not - # been retrieved. - # - def incoming - Cproton.pn_messenger_incoming(@impl) - end - - # Adds a routing rule to the Messenger's internal routing table. - # - # The route procedure may be used to influence how a Messenger will - # internally treat a given address or class of addresses. Every call - # to the route procedure will result in Messenger appending a routing - # rule to its internal routing table. - # - # Whenever a Message is presented to a Messenger for delivery, it - # will match the address of this message against the set of routing - # rules in order. The first rule to match will be triggered, and - # instead of routing based on the address presented in the message, - # the Messenger will route based on the address supplied in the rule. - # - # The pattern matching syntax supports two types of matches, a '%' - # will match any character except a '/', and a '*' will match any - # character including a '/'. - # - # A routing address is specified as a normal AMQP address, however it - # may additionally use substitution variables from the pattern match - # that triggered the rule. - # - # ==== Arguments - # - # * pattern - the address pattern - # * address - the target address - # - # ==== Examples - # - # # route messages sent to foo to the destionaty amqp://foo.com - # messenger.route("foo", "amqp://foo.com") - # - # # any message to foobar will be routed to amqp://foo.com/bar - # messenger.route("foobar", "amqp://foo.com/bar") - # - # # any message to bar/<path> will be routed to the same path within - # # the amqp://bar.com domain - # messenger.route("bar/*", "amqp://bar.com/$1") - # - # # route all Message objects over TLS - # messenger.route("amqp:*", "amqps:$1") - # - # # supply credentials for foo - # messenger.route("amqp://foo.com/*", "amqp://user:passw...@foo.com/$1") - # - # # supply credentials for all domains - # messenger.route("amqp://*", "amqp://user:password@$1") - # - # # route all addresses through a single proxy while preserving the - # # original destination - # messenger.route("amqp://%$/*", "amqp://user:password@proxy/$1/$2") - # - # # route any address through a single broker - # messenger.route("*", "amqp://user:password@broker/$1") - # - def route(pattern, address) - Cproton.pn_messenger_route(@impl, pattern, address) - end - - # Similar to #route, except that the destination of - # the Message is determined before the message address is rewritten. - # - # The outgoing address is only rewritten after routing has been - # finalized. If a message has an outgoing address of - # "amqp://0.0.0.0:5678", and a rewriting rule that changes its - # outgoing address to "foo", it will still arrive at the peer that - # is listening on "amqp://0.0.0.0:5678", but when it arrives there, - # the receiver will see its outgoing address as "foo". - # - # The default rewrite rule removes username and password from addresses - # before they are transmitted. - # - # ==== Arguments - # - # * pattern - the outgoing address - # * address - the target address - # - def rewrite(pattern, address) - Cproton.pn_messenger_rewrite(@impl, pattern, address) - end - - def selectable - impl = Cproton.pn_messenger_selectable(@impl) - - # if we don't have any selectables, then return - return nil if impl.nil? - - fd = Cproton.pn_selectable_get_fd(impl) - - selectable = @selectables[fd] - if selectable.nil? - selectable = Selectable.new(self, impl) - @selectables[fd] = selectable - end - return selectable - end - - # Returns a +Tracker+ for the message most recently sent via the put - # method. - # - def outgoing_tracker - impl = Cproton.pn_messenger_outgoing_tracker(@impl) - return nil if impl == -1 - Tracker.new(impl) - end - - # Returns a +Tracker+ for the most recently received message. - # - def incoming_tracker - impl = Cproton.pn_messenger_incoming_tracker(@impl) - return nil if impl == -1 - Tracker.new(impl) - end - - # Signal the sender that you have acted on the Message - # pointed to by the tracker. If no tracker is supplied, - # then all messages that have been returned by the get - # method are accepted, except those that have already been - # auto-settled by passing beyond your incoming window size. - # - # ==== Options - # - # * tracker - the tracker - # - def accept(tracker = nil) - raise TypeError.new("invalid tracker: #{tracker}") unless tracker.nil? or valid_tracker?(tracker) - if tracker.nil? then - tracker = self.incoming_tracker - flag = Cproton::PN_CUMULATIVE - else - flag = 0 - end - Cproton.pn_messenger_accept(@impl, tracker.impl, flag) - end - - # Rejects the incoming message identified by the tracker. - # If no tracker is supplied, all messages that have been returned - # by the get method are rejected, except those that have already - # been auto-settled by passing beyond your outgoing window size. - # - # ==== Options - # - # * tracker - the tracker - # - def reject(tracker) - raise TypeError.new("invalid tracker: #{tracker}") unless tracker.nil? or valid_tracker?(tracker) - if tracker.nil? then - tracker = self.incoming_tracker - flag = Cproton::PN_CUMULATIVE - else - flag = 0 - end - Cproton.pn_messenger_reject(@impl, tracker.impl, flag) - end - - # Gets the last known remote state of the delivery associated with - # the given tracker, as long as the Message is still within your - # outgoing window. (Also works on incoming messages that are still - # within your incoming queue. See TrackerStatus for details on the - # values returned. - # - # ==== Options - # - # * tracker - the tracker - # - def status(tracker) - raise TypeError.new("invalid tracker: #{tracker}") unless valid_tracker?(tracker) - TrackerStatus.by_value(Cproton.pn_messenger_status(@impl, tracker.impl)) - end - - # Frees a Messenger from tracking the status associated - # with a given tracker. If you don't supply a tracker, all - # outgoing messages up to the most recent will be settled. - # - # ==== Options - # - # * tracker - the tracker - # - # ==== Examples - # - def settle(tracker) - raise TypeError.new("invalid tracker: #{tracker}") unless valid_tracker?(tracker) - if tracker.nil? then - tracker = self.incoming_tracker - flag = Cproton::PN_CUMULATIVE - else - flag = 0 - end - Cproton.pn_messenger_settle(@impl, tracker.impl, flag) - end - - # Sets the incoming window. - # - # The Messenger will track the remote status of this many incoming - # deliveries after they have been accepted or rejected. - # - # Messages enter this window only when you take them into your application - # using get(). If your incoming window size is n, and you get n+1 messages - # without explicitly accepting or rejecting the oldest message, then the - # message that passes beyond the edge of the incoming window will be - # assigned the default disposition of its link. - # - # ==== Options - # - # * window - the window size - # - def incoming_window=(window) - raise TypeError.new("invalid window: #{window}") unless valid_window?(window) - Cproton.pn_messenger_set_incoming_window(@impl, window) - end - - # Returns the incoming window. - # - def incoming_window - Cproton.pn_messenger_get_incoming_window(@impl) - end - - # Sets the outgoing window. - # - # The Messenger will track the remote status of this many outgoing - # deliveries after calling send. - # A Message enters this window when you call the put() method with the - # message. If your outgoing window size is n, and you call put n+1 - # times, status information will no longer be available for the - # first message. - # - # ==== Options - # - # * window - the window size - # - def outgoing_window=(window) - raise TypeError.new("invalid window: #{window}") unless valid_window?(window) - Cproton.pn_messenger_set_outgoing_window(@impl, window) - end - - # Returns the outgoing window. - # - def outgoing_window - Cproton.pn_messenger_get_outgoing_window(@impl) - end - - # Unregisters a selectable object. - def unregister_selectable(fileno) # :nodoc: - @selectables.delete(fileno) - end - - private - - def valid_tracker?(tracker) - !tracker.nil? && tracker.is_a?(Tracker) - end - - def valid_window?(window) - !window.nil? && [Float, Fixnum].include?(window.class) - end - - end - -end
http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/ruby/lib/messenger/subscription.rb ---------------------------------------------------------------------- diff --git a/proton-c/bindings/ruby/lib/messenger/subscription.rb b/proton-c/bindings/ruby/lib/messenger/subscription.rb deleted file mode 100644 index 6d4973e..0000000 --- a/proton-c/bindings/ruby/lib/messenger/subscription.rb +++ /dev/null @@ -1,37 +0,0 @@ -#-- -# 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. -#++ - -module Qpid::Proton::Messenger - - # A +Subscription+ is an opaque object for working with a +Messenger+'s - # subscriptions. - # - class Subscription - - def initialize(impl) # :nodoc: - @impl = impl - end - - def impl # :nodoc: - @impl - end - - end - -end http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/ruby/lib/messenger/tracker.rb ---------------------------------------------------------------------- diff --git a/proton-c/bindings/ruby/lib/messenger/tracker.rb b/proton-c/bindings/ruby/lib/messenger/tracker.rb deleted file mode 100644 index 55507e5..0000000 --- a/proton-c/bindings/ruby/lib/messenger/tracker.rb +++ /dev/null @@ -1,38 +0,0 @@ -#-- -# 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. -#++ - -module Qpid::Proton::Messenger - - # A +Tracker+ is used to track the disposition of a +Message+. - # - class Tracker - - CUMULATIVE = Cproton::PN_CUMULATIVE - - def initialize(impl) # :nodoc: - @impl = impl - end - - def impl # :nodoc: - @impl - end - - end - -end http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/ruby/lib/messenger/tracker_status.rb ---------------------------------------------------------------------- diff --git a/proton-c/bindings/ruby/lib/messenger/tracker_status.rb b/proton-c/bindings/ruby/lib/messenger/tracker_status.rb deleted file mode 100644 index 6eea9ce..0000000 --- a/proton-c/bindings/ruby/lib/messenger/tracker_status.rb +++ /dev/null @@ -1,69 +0,0 @@ -#-- -# 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. -#++ - -module Qpid::Proton::Messenger - - # TrackerStatus contains symbols that represent the status value for a - # Tracker. - # - class TrackerStatus - - def initialize value, name # :nodoc: - @value = value - @name = name - end - - def value # :nodoc: - @value - end - - def to_s # :nodoc: - @name.to_s - end - - def self.by_name(name) # :nodoc: - @by_name[name.to_sym] unless name.nil? - end - - def self.by_value(value) # :nodoc: - @by_value[value] unless value.nil? - end - - private - - def self.add_item(key, value) # :nodoc: - @by_name ||= {} - @by_name[key] = TrackerStatus.new value, key - @by_value ||= {} - @by_value[value] = @by_name[key] - end - - def self.const_missing(key) # :nodoc: - @by_name[key] - end - - self.add_item :UNKNOWN, Cproton::PN_STATUS_UNKNOWN - self.add_item :PENDING, Cproton::PN_STATUS_PENDING - self.add_item :ACCEPTED, Cproton::PN_STATUS_ACCEPTED - self.add_item :REJECTED, Cproton::PN_STATUS_REJECTED - self.add_item :SETTLED, Cproton::PN_STATUS_SETTLED - - end - -end http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/ruby/lib/qpid_proton.rb ---------------------------------------------------------------------- diff --git a/proton-c/bindings/ruby/lib/qpid_proton.rb b/proton-c/bindings/ruby/lib/qpid_proton.rb deleted file mode 100644 index 1d614a4..0000000 --- a/proton-c/bindings/ruby/lib/qpid_proton.rb +++ /dev/null @@ -1,132 +0,0 @@ -#-- -# 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. -#++ - -require "cproton" -require "date" -require "weakref" - -if RUBY_VERSION < "1.9" -require "kconv" -else - require "securerandom" -end - -# Exception classes -require "core/exceptions" - -# Utility classes -require "util/version" -require "util/error_handler" -require "util/constants" -require "util/swig_helper" -require "util/condition" -require "util/wrapper" -require "util/class_wrapper" -require "util/engine" -require "util/uuid" -require "util/timeout" -require "util/handler" -require "util/reactor" - -# Types -require "types/strings" -require "types/hash" -require "types/array" -require "types/described" - -# Codec classes -require "codec/mapping" -require "codec/data" - -# Event API classes -require "event/event_type" -require "event/event_base" -require "event/event" -require "event/collector" - -# Main Proton classes -require "core/selectable" -require "core/message" -require "core/endpoint" -require "core/session" -require "core/terminus" -require "core/disposition" -require "core/delivery" -require "core/link" -require "core/sender" -require "core/receiver" -require "core/connection" -require "core/sasl" -require "core/ssl_domain" -require "core/ssl_details" -require "core/ssl" -require "core/transport" -require "core/base_handler" -require "core/url" - -# Messenger API classes -require "messenger/subscription" -require "messenger/tracker_status" -require "messenger/tracker" -require "messenger/messenger" - -# Handler classes -require "handler/c_adaptor" -require "handler/wrapped_handler" -require "handler/acking" -require "handler/endpoint_state_handler" -require "handler/incoming_message_handler" -require "handler/outgoing_message_handler" -require "handler/c_flow_controller" -require "handler/messaging_handler" - -# Reactor classes -require "reactor/task" -require "reactor/acceptor" -require "reactor/reactor" -require "reactor/ssl_config" -require "reactor/global_overrides" -require "reactor/urls" -require "reactor/connector" -require "reactor/backoff" -require "reactor/session_per_connection" -require "reactor/container" -require "reactor/link_option" - -module Qpid::Proton - # @private - def self.registry - @registry ||= {} - end - - # @private - def self.add_to_registry(key, value) - self.registry[key] = value - end - - # @private - def self.get_from_registry(key) - self.registry[key] - end - - # @private - def self.delete_from_registry(key) - self.registry.delete(key) - end -end http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/ruby/lib/reactor/acceptor.rb ---------------------------------------------------------------------- diff --git a/proton-c/bindings/ruby/lib/reactor/acceptor.rb b/proton-c/bindings/ruby/lib/reactor/acceptor.rb deleted file mode 100644 index 83e0596..0000000 --- a/proton-c/bindings/ruby/lib/reactor/acceptor.rb +++ /dev/null @@ -1,41 +0,0 @@ -#-- -# 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. -#++ - -module Qpid::Proton::Reactor - - class Acceptor - - include Qpid::Proton::Util::Wrapper - - def initialize(impl) - @impl = impl - self.class.store_instance(self) - end - - def set_ssl_domain(ssl_domain) - Cproton.pn_acceptor_set_ssl_domain(@impl, ssl_domain.impl) - end - - def close - Cproton.pn_acceptor_close(@impl) - end - - end - -end http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/ruby/lib/reactor/backoff.rb ---------------------------------------------------------------------- diff --git a/proton-c/bindings/ruby/lib/reactor/backoff.rb b/proton-c/bindings/ruby/lib/reactor/backoff.rb deleted file mode 100644 index 99682e5..0000000 --- a/proton-c/bindings/ruby/lib/reactor/backoff.rb +++ /dev/null @@ -1,41 +0,0 @@ -#-- -# 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. -#++ - -module Qpid::Proton::Reactor - - class Backoff - - def initialize - @delay = 0 - end - - def reset - @delay = 0 - end - - def next - current = @delay - current = 0.1 if current.zero? - @delay = [10, 2 * current].min - return current - end - - end - -end http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/ruby/lib/reactor/connector.rb ---------------------------------------------------------------------- diff --git a/proton-c/bindings/ruby/lib/reactor/connector.rb b/proton-c/bindings/ruby/lib/reactor/connector.rb deleted file mode 100644 index a6523db..0000000 --- a/proton-c/bindings/ruby/lib/reactor/connector.rb +++ /dev/null @@ -1,98 +0,0 @@ -#-- -# 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. -#++ - -module Qpid::Proton::Reactor - - class Connector < Qpid::Proton::BaseHandler - - attr_accessor :address - attr_accessor :reconnect - attr_accessor :ssl_domain - - def initialize(connection) - @connection = connection - @address = nil - @heartbeat = nil - @reconnect = nil - @ssl_domain = nil - end - - def on_connection_local_open(event) - self.connect(event.connection) - end - - def on_connection_remote_open(event) - if !@reconnect.nil? - @reconnect.reset - @transport = nil - end - end - - def on_transport_tail_closed(event) - self.on_transport_closed(event) - end - - def on_transport_closed(event) - if !@connection.nil? && !(@connection.state & Qpid::Proton::Endpoint::LOCAL_ACTIVE).zero? - if !@reconnect.nil? - event.transport.unbind - delay = @reconnect.next - if delay == 0 - self.connect(@connection) - else - event.reactor.schedule(delay, self) - end - else - @connection = nil - end - end - end - - def on_timer_task(event) - self.connect(@connection) - end - - def on_connection_remote_close(event) - @connection = nil - end - - def connect(connection) - url = @address.next - connection.hostname = "#{url.host}:#{url.port}" - - transport = Qpid::Proton::Transport.new - transport.bind(connection) - if !@heartbeat.nil? - transport.idle_timeout = @heartbeat - elsif (url.scheme == "amqps") && !@ssl_domain.nil? - @ssl = Qpid::Proton::SSL.new(transport, @ssl_domain) - @ss.peer_hostname = url.host - elsif !url.username.nil? - sasl = transport.sasl - if url.username == "anonymous" - sasl.mechanisms("ANONYMOUS") - else - sasl.plain(url.username, url.password) - end - end - end - - end - -end http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/ruby/lib/reactor/container.rb ---------------------------------------------------------------------- diff --git a/proton-c/bindings/ruby/lib/reactor/container.rb b/proton-c/bindings/ruby/lib/reactor/container.rb deleted file mode 100644 index 2a7a030..0000000 --- a/proton-c/bindings/ruby/lib/reactor/container.rb +++ /dev/null @@ -1,272 +0,0 @@ -#-- -# 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. -#++ - -module Qpid::Proton::Reactor - - # @private - class InternalTransactionHandler < Qpid::Proton::Handler::OutgoingMessageHandler - - def initialize - super - end - - def on_settled(event) - if event.delivery.respond_to? :transaction - event.transaction = event.delivery.transaction - event.delivery.transaction.handle_outcome(event) - end - end - - end - - - # A representation of the AMQP concept of a container which, loosely - # speaking, is something that establishes links to or from another - # container on which messages are transferred. - # - # This is an extension to the Reactor classthat adds convenience methods - # for creating instances of Qpid::Proton::Connection, Qpid::Proton::Sender - # and Qpid::Proton::Receiver. - # - # @example - # - class Container < Reactor - - include Qpid::Proton::Util::Reactor - - include Qpid::Proton::Util::UUID - - attr_accessor :container_id - attr_accessor :global_handler - - def initialize(handlers, options = {}) - super(handlers, options) - - # only do the following if we're creating a new instance - if !options.has_key?(:impl) - @ssl = SSLConfig.new - if options[:global_handler] - self.global_handler = GlobalOverrides.new(options[:global_handler]) - else - # very ugly, but using self.global_handler doesn't work in the constructor - ghandler = Reactor.instance_method(:global_handler).bind(self).call - ghandler = GlobalOverrides.new(ghandler) - Reactor.instance_method(:global_handler=).bind(self).call(ghandler) - end - @trigger = nil - @container_id = generate_uuid - end - end - - # Initiates the establishment of an AMQP connection. - # - # @param options [Hash] A hash of named arguments. - # - def connect(options = {}) - conn = self.connection(options[:handler]) - conn.container = self.container_id || generate_uuid - connector = Connector.new(conn) - conn.overrides = connector - if !options[:url].nil? - connector.address = URLs.new([options[:url]]) - elsif !options[:urls].nil? - connector.address = URLs.new(options[:urls]) - elsif !options[:address].nil? - connector.address = URLs.new([Qpid::Proton::URL.new(options[:address])]) - else - raise ::ArgumentError.new("either :url or :urls or :address required") - end - - connector.heartbeat = options[:heartbeat] if !options[:heartbeat].nil? - if !options[:reconnect].nil? - connector.reconnect = options[:reconnect] - else - connector.reconnect = Backoff.new() - end - - connector.ssl_domain = SessionPerConnection.new # TODO seems this should be configurable - - conn.open - - return conn - end - - def _session(context) - if context.is_a?(Qpid::Proton::URL) - return self._session(self.connect(:url => context)) - elsif context.is_a?(Qpid::Proton::Session) - return context - elsif context.is_a?(Qpid::Proton::Connection) - if context.session_policy? - return context.session_policy.session(context) - else - return self.create_session(context) - end - else - return context.session - end - end - - # Initiates the establishment of a link over which messages can be sent. - # - # @param context [String, URL] The context. - # @param opts [Hash] Additional options. - # @param opts [String, Qpid::Proton::URL] The target address. - # @param opts [String] :source The source address. - # @param opts [Boolean] :dynamic - # @param opts [Object] :handler - # @param opts [Object] :tag_generator The tag generator. - # @param opts [Hash] :options Addtional link options - # - # @return [Sender] The sender. - # - def create_sender(context, opts = {}) - if context.is_a?(::String) - context = Qpid::Proton::URL.new(context) - end - - target = opts[:target] - if context.is_a?(Qpid::Proton::URL) && target.nil? - target = context.path - end - - session = self._session(context) - - sender = session.sender(opts[:name] || - id(session.connection.container, - target, opts[:source])) - sender.source.address = opts[:source] if !opts[:source].nil? - sender.target.address = target if target - sender.handler = opts[:handler] if !opts[:handler].nil? - sender.tag_generator = opts[:tag_generator] if !opts[:tag_gnenerator].nil? - self._apply_link_options(opts[:options], sender) - sender.open - return sender - end - - # Initiates the establishment of a link over which messages can be received. - # - # There are two accepted arguments for the context - # 1. If a Connection is supplied then the link is established using that - # object. The source, and optionally the target, address can be supplied - # 2. If it is a String or a URL then a new Connection is created on which - # the link will be attached. If a path is specified, but not the source - # address, then the path of the URL is used as the target address. - # - # The name will be generated for the link if one is not specified. - # - # @param context [Connection, URL, String] The connection or the address. - # @param opts [Hash] Additional otpions. - # @option opts [String, Qpid::Proton::URL] The source address. - # @option opts [String] :target The target address - # @option opts [String] :name The link name. - # @option opts [Boolean] :dynamic - # @option opts [Object] :handler - # @option opts [Hash] :options Additional link options. - # - # @return [Receiver - # - def create_receiver(context, opts = {}) - if context.is_a?(::String) - context = Qpid::Proton::URL.new(context) - end - - source = opts[:source] - if context.is_a?(Qpid::Proton::URL) && source.nil? - source = context.path - end - - session = self._session(context) - - receiver = session.receiver(opts[:name] || - id(session.connection.container, - source, opts[:target])) - receiver.source.address = source if source - receiver.source.dynamic = true if opts.has_key?(:dynamic) && opts[:dynamic] - receiver.target.address = opts[:target] if !opts[:target].nil? - receiver.handler = opts[:handler] if !opts[:handler].nil? - self._apply_link_options(opts[:options], receiver) - receiver.open - return receiver - end - - def declare_transaction(context, handler = nil, settle_before_discharge = false) - if context.respond_to? :txn_ctl && !context.__send__(:txn_ctl).nil? - class << context - attr_accessor :txn_ctl - end - context.txn_ctl = self.create_sender(context, nil, "txn-ctl", - InternalTransactionHandler.new()) - end - return Transaction.new(context.txn_ctl, handler, settle_before_discharge) - end - - # Initiates a server socket, accepting incoming AMQP connections on the - # interface and port specified. - # - # @param url [] - # @param ssl_domain [] - # - def listen(url, ssl_domain = nil) - url = Qpid::Proton::URL.new(url) - acceptor = self.acceptor(url.host, url.port) - ssl_config = ssl_domain - if ssl_config.nil? && (url.scheme == 'amqps') && @ssl - ssl_config = @ssl.server - end - if !ssl_config.nil? - acceptor.ssl_domain(ssl_config) - end - return acceptor - end - - def do_work(timeout = nil) - self.timeout = timeout unless timeout.nil? - self.process - end - - def id(container, remote, local) - if !local.nil? && !remote.nil? - "#{container}-#{remote}-#{local}" - elsif !local.nil? - "#{container}-#{local}" - elsif !remote.nil? - "#{container}-#{remote}" - else - "#{container}-#{generate_uuid}" - end - end - - def _apply_link_options(options, link) - if !options.nil? && !options.empty? - if !options.is_a?(::List) - options = [Options].flatten - end - - options.each {|option| o.apply(link) if o.test(link)} - end - end - - def to_s - "#{self.class}<@impl=#{Cproton.pni_address_of(@impl)}>" - end - - end - -end http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/ruby/lib/reactor/global_overrides.rb ---------------------------------------------------------------------- diff --git a/proton-c/bindings/ruby/lib/reactor/global_overrides.rb b/proton-c/bindings/ruby/lib/reactor/global_overrides.rb deleted file mode 100644 index 11d05a5..0000000 --- a/proton-c/bindings/ruby/lib/reactor/global_overrides.rb +++ /dev/null @@ -1,44 +0,0 @@ -#-- -# 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. -#++ - -module Qpid::Proton::Reactor - - class GlobalOverrides - - def initialize(base) - @base = base - end - - def on_unhandled(name, event) - event.dispatch(@base) unless self.override?(event) - end - - def override?(event) - conn = event.connection - if !conn.nil? && conn.overrides? - overrides = conn.overrides - result = event.dispatch(overrides) - return result - end - false - end - - end - -end http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/ruby/lib/reactor/link_option.rb ---------------------------------------------------------------------- diff --git a/proton-c/bindings/ruby/lib/reactor/link_option.rb b/proton-c/bindings/ruby/lib/reactor/link_option.rb deleted file mode 100644 index 628a811..0000000 --- a/proton-c/bindings/ruby/lib/reactor/link_option.rb +++ /dev/null @@ -1,90 +0,0 @@ -#-- -# 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. -#++ - -module Qpid::Proton::Reactor - - class LinkOption - def apply(link) - end - - # Subclasses should override this to selectively apply an option. - def test(link) - true - end - end - - class AtMostOne < LinkOption - def apply(link) - link.snd_settle_mod = Link::SND_SETTLED - end - end - - class AtLeastOnce < LinkOption - def apply(link) - link.snd_settle_mode = Link::SND_UNSETTLED - link.rcv_settle_mode = Link::RCV_FIRST - end - end - - class SenderOption < LinkOption - def test(link) - link.sender? - end - end - - class ReceiverOption < LinkOption - def test(link) - link.receiver? - end - end - - class DynamicNodeProperties < LinkOption - def initialize(properties = {}) - @properties = [] - properties.each do |property| - @properties << property.to_sym - end - end - - def apply(link) - if link.receiver? - link.source.properties.dict = @properties - else - link.target.properties.dict = @properties - end - end - end - - class Filter < ReceiverOption - def initialize(filter_set = {}) - @filter_set = filter_set - end - - def apply(receiver) - receiver.source.filter.dict = @filter_set - end - end - - #class Selector < Filter - # def initialize(value, name = 'selector') - # - # end - #end - -end http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/ruby/lib/reactor/reactor.rb ---------------------------------------------------------------------- diff --git a/proton-c/bindings/ruby/lib/reactor/reactor.rb b/proton-c/bindings/ruby/lib/reactor/reactor.rb deleted file mode 100644 index a0ff7e0..0000000 --- a/proton-c/bindings/ruby/lib/reactor/reactor.rb +++ /dev/null @@ -1,196 +0,0 @@ -#-- -# 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. -#++ - -module Qpid::Proton::Reactor - - class Reactor - - include Qpid::Proton::Util::Handler - - # @private - include Qpid::Proton::Util::SwigHelper - - # @private - PROTON_METHOD_PREFIX = "pn_reactor" - - proton_caller :yield - - proton_caller :mark - - proton_caller :start - - proton_caller :stop - - # @private - include Qpid::Proton::Util::Timeout - - include Qpid::Proton::Util::Wrapper - - attr_reader :errors - - def self.wrap(impl) - return nil if impl.nil? - - self.fetch_instance(impl, :pn_reactor_attachments) || Reactor.new(nil, :impl => impl) - end - - def initialize(handlers, options = {}) - @impl = options[:impl] - if @impl.nil? - @impl = Cproton.pn_reactor - end - if !handlers.nil? - [handlers].flatten.each {|handler| self.handler.add(handler)} - end - @errors = [] - @handlers = [] - self.class.store_instance(self, :pn_reactor_attachments) - end - - # Returns whether the reactor has any unbuffered data. - # - # @return [Boolean] True if there is no unbuffered data. - # - def quiesced? - Cproton.pn_reactor_quiesced(@impl) - end - - def on_error(info) - self.errors << info - self.yield - end - - def global_handler - impl = Cproton.pn_reactor_get_global_handler(@impl) - Qpid::Proton::Handler::WrappedHandler.wrap(impl, self.method(:on_error)) - end - - def global_handler=(handler) - impl = chandler(handler, self.method(:on_error)) - Cproton.pn_reactor_set_global_handler(@impl, impl) - Cproton.pn_decref(impl) - end - - # Returns the timeout period. - # - # @return [Fixnum] The timeout period, in seconds. - # - def timeout - millis_to_timeout(Cproton.pn_reactor_get_timeout(@impl)) - end - - # Sets the timeout period. - # - # @param timeout [Fixnum] The timeout, in seconds. - # - def timeout=(timeout) - Cproton.pn_reactor_set_timeout(@impl, timeout_to_millis(timeout)) - end - - def handler - impl = Cproton.pn_reactor_get_handler(@impl) - Qpid::Proton::Handler::WrappedHandler.wrap(impl, self.method(:on_error)) - end - - def handler=(handler) - impl = chandler(handler, set.method(:on_error)) - Cproton.pn_reactor_set_handler(@impl, impl) - Cproton.pn_decref(impl) - end - - def run(&block) - self.timeout = 3.14159265359 - self.start - while self.process do - if block_given? - yield - end - end - self.stop - end - - def wakeup - n = Cproton.pn_reactor_wakeup(@impl) - unless n.zero? - raise IOError.new(Cproton.pn_reactor_error(@impl)) - end - end - - def process - result = Cproton.pn_reactor_process(@impl) - if !self.errors.nil? && !self.errors.empty? - (0...self.errors.size).each do |index| - error_set = self.errors[index] - print error.backtrace.join("\n") - end - raise self.errors.last - end - return result - end - - def schedule(delay, task) - impl = chandler(task, self.method(:on_error)) - task = Task.wrap(Cproton.pn_reactor_schedule(@impl, sec_to_millis(delay), impl)) - Cproton.pn_decref(impl) - return task - end - - def acceptor(host, port, handler = nil) - impl = chandler(handler, self.method(:on_error)) - aimpl = Cproton.pn_reactor_acceptor(@impl, host, "#{port}", impl) - Cproton.pn_decref(impl) - if !aimpl.nil? - return Acceptor.new(aimpl) - else - io_error = Cproton.pn_reactor_error(@impl) - error_text = Cproton.pn_error_text(io_error) - text = "(#{Cproton.pn_error_text(io_error)} (#{host}:#{port}))" - raise IOError.new(text) - end - end - - def connection(handler = nil) - impl = chandler(handler, self.method(:on_error)) - conn = Qpid::Proton::Connection.wrap(Cproton.pn_reactor_connection(@impl, impl)) - Cproton.pn_decref(impl) - return conn - end - - def selectable(handler = nil) - impl = chandler(handler, self.method(:on_error)) - result = Selectable.wrap(Cproton.pn_reactor_selectable(@impl)) - if !impl.nil? - record = Cproton.pn_selectable_attachments(result.impl) - Cproton.pn_record_set_handler(record, impl) - Cproton.pn_decref(impl) - end - return result - end - - def update(sel) - Cproton.pn_reactor_update(@impl, sel.impl) - end - - def push_event(obj, etype) - Cproton.pn_collector_put(Cproton.pn_reactor_collector(@impl), Qpid::Proton::Util::RBCTX, Cproton.pn_py2void(obj), etype.number) - end - - end - -end http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/ruby/lib/reactor/session_per_connection.rb ---------------------------------------------------------------------- diff --git a/proton-c/bindings/ruby/lib/reactor/session_per_connection.rb b/proton-c/bindings/ruby/lib/reactor/session_per_connection.rb deleted file mode 100644 index f8180c0..0000000 --- a/proton-c/bindings/ruby/lib/reactor/session_per_connection.rb +++ /dev/null @@ -1,45 +0,0 @@ -#-- -# 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. -#++ - -module Qpid::Proton::Reactor - - class SessionPerConnection - - include Qpid::Proton::Util::Reactor - - def initialize - @default_session = nil - end - - def session(connection) - if @default_session.nil? - @default_session = self.create_session - @default_session.context = self - end - return @default_session - end - - def on_session_remote_close(event) - event.connection.close - @default_session = nil - end - - end - -end http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/ruby/lib/reactor/ssl_config.rb ---------------------------------------------------------------------- diff --git a/proton-c/bindings/ruby/lib/reactor/ssl_config.rb b/proton-c/bindings/ruby/lib/reactor/ssl_config.rb deleted file mode 100644 index 56fec71..0000000 --- a/proton-c/bindings/ruby/lib/reactor/ssl_config.rb +++ /dev/null @@ -1,41 +0,0 @@ -#-- -# 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. -#++ - -module Qpid::Proton::Reactor - - class SSLConfig - - def initialize - @client = Qpid::Proton::SSLDomain.new(Qpid::Proton::SSLDomain::MODE_CLIENT) - @server = Qpid::Proton::SSLDomain.new(Qpid::Proton::SSLDomain::MODE_SERVER) - end - - def set_credentials(cert_file, key_file, password) - @client.set_credentials(cert_file, key_file, password) - @server.set_credentials(cert_file, key_file, password) - end - - def set_trusted_ca_db(certificate_db) - @client.set_trusted_ca_db(certificate_db) - @server.set_trusted_ca_db(certificate_db) - end - - end - -end http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/ruby/lib/reactor/task.rb ---------------------------------------------------------------------- diff --git a/proton-c/bindings/ruby/lib/reactor/task.rb b/proton-c/bindings/ruby/lib/reactor/task.rb deleted file mode 100644 index 6818ed2..0000000 --- a/proton-c/bindings/ruby/lib/reactor/task.rb +++ /dev/null @@ -1,39 +0,0 @@ -#-- -# 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. -#++ - -module Qpid::Proton::Reactor - - class Task - - # @private - include Qpid::Proton::Util::Wrapper - - def self.wrap(impl) - return nil if impl.nil? - self.fetch_instance(impl, :pn_task_attachments) || Task.new(impl) - end - - def initialize(impl) - @impl = impl - self.class.store_instance(self, :pn_task_attachments) - end - - end - -end http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/ruby/lib/reactor/urls.rb ---------------------------------------------------------------------- diff --git a/proton-c/bindings/ruby/lib/reactor/urls.rb b/proton-c/bindings/ruby/lib/reactor/urls.rb deleted file mode 100644 index 8cdb16c..0000000 --- a/proton-c/bindings/ruby/lib/reactor/urls.rb +++ /dev/null @@ -1,40 +0,0 @@ -#-- -# 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. -#++ - -module Qpid::Proton::Reactor - - class URLs - - def initialize(values) - @values = [values].flatten - @iter = @values.each - end - - def next - begin - return @iter.next - rescue StopIteration - @iter = @values.each - return @iter.next - end - end - - end - -end http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/ruby/lib/types/array.rb ---------------------------------------------------------------------- diff --git a/proton-c/bindings/ruby/lib/types/array.rb b/proton-c/bindings/ruby/lib/types/array.rb deleted file mode 100644 index f5c6b50..0000000 --- a/proton-c/bindings/ruby/lib/types/array.rb +++ /dev/null @@ -1,172 +0,0 @@ -#-- -# 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. -#++ - -#-- -# Patch the Array class to provide methods for adding its contents -# to a Qpid::Proton::Data instance. -#++ - -module Qpid::Proton::Types - - # Holds the information for an AMQP Array compound type. - # - # It holds the type for the array and the descriptor if the - # array is described. - # - # @private - # - class ArrayHeader - attr_reader :type - attr_reader :descriptor - - def initialize(type, descriptor = nil) - @type = type - @descriptor = descriptor - end - - # Returns true if the array is described. - def described? - !@descriptor.nil? - end - - def ==(that) - ((@type == that.type) && (@descriptor == that.descriptor)) - end - end - -end - -# @private -class Array # :nodoc: - - # Used to declare an array as an AMQP array. - # - # The value, if defined, is an instance of Qpid::Proton::Types::ArrayHeader - attr_accessor :proton_array_header - - # Returns true if the array is the a Proton described type. - def proton_described? - !@proton_array_header.nil? && @proton_array_header.described? - end - - # Puts the elements of the array into the specified Qpid::Proton::Data object. - def proton_put(data) - raise TypeError, "data object cannot be nil" if data.nil? - - if @proton_array_header.nil? - proton_put_list(data) - else - proton_put_array(data) - end - end - - private - - def proton_put_list(data) - # create a list, then enter it and add each element - data.put_list - data.enter - each do |element| - # get the proton type for the element - mapping = Qpid::Proton::Codec::Mapping.for_class(element.class) - # add the element - mapping.put(data, element) - end - # exit the list - data.exit - end - - def proton_put_array(data) - data.put_array(@proton_array_header.described?, @proton_array_header.type) - data.enter - if @proton_array_header.described? - data.symbol = @proton_array_header.descriptor - end - - each do |element| - @proton_array_header.type.put(data, element) - end - - data.exit - end - - class << self - - # Gets the elements of an array or list out of the specified - # Qpid::Proton::Data object. - def proton_get(data) - raise TypeError, "can't convert nil into Qpid::Proton::Data" if data.nil? - - type = data.type - - if type == Qpid::Proton::Codec::LIST - result = proton_get_list(data) - elsif type == Qpid::Proton::Codec::ARRAY - result = proton_get_array(data) - else - raise TypeError, "element is not a list and not an array" - end - end - - private - - def proton_get_list(data) - size = data.list - raise TypeError, "not a list" unless data.enter - elements = [] - (0...size).each do - data.next - type = data.type - raise TypeError, "missing next element in list" unless type - elements << type.get(data) - end - data.exit - return elements - end - - def proton_get_array(data) - count, described, type = data.array - - raise TypeError, "not an array" unless data.enter - elements = [] - - descriptor = nil - - if described - data.next - descriptor = data.symbol - end - - elements.proton_array_header = Qpid::Proton::Types::ArrayHeader.new(type, descriptor) - (0...count).each do |which| - if data.next - etype = data.type - raise TypeError, "missing next element in array" unless etype - raise TypeError, "invalid array element: #{etype}" unless etype == type - elements << type.get(data) - end - end - data.exit - return elements - end - - end - -end - http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/ruby/lib/types/described.rb ---------------------------------------------------------------------- diff --git a/proton-c/bindings/ruby/lib/types/described.rb b/proton-c/bindings/ruby/lib/types/described.rb deleted file mode 100644 index 7c09d3f..0000000 --- a/proton-c/bindings/ruby/lib/types/described.rb +++ /dev/null @@ -1,63 +0,0 @@ -#-- -# 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. -#++ - -module Qpid::Proton::Types - - # @private - class Described - - attr_reader :descriptor - attr_reader :value - - def initialize(descriptor, value) - @descriptor = descriptor - @value = value - end - - # Puts the description into the Data object. - # - # ==== Arguments - # - # * data - the Qpid::Proton::Data instance - # - # ==== Examples - # - # described = Qpid::Proton::Described.new("my-descriptor", "the value") - # data = Qpid::Proton::Data.new - # ... - # described.put(data) - # - def put(data) - data.symbol = @descriptor - data.string = @value - end - - def ==(that) # :nodoc: - (that.is_a?(Qpid::Proton::Types::Described) && - (self.descriptor == that.descriptor) && - (self.value == that.value)) - end - - def to_s # :nodoc: - "descriptor=#{descriptor} value=#{value}" - end - - end - -end http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/ruby/lib/types/hash.rb ---------------------------------------------------------------------- diff --git a/proton-c/bindings/ruby/lib/types/hash.rb b/proton-c/bindings/ruby/lib/types/hash.rb deleted file mode 100644 index e6836d5..0000000 --- a/proton-c/bindings/ruby/lib/types/hash.rb +++ /dev/null @@ -1,87 +0,0 @@ -#-- -# 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. -#++ - -#-- -# Patch the Hash class to provide methods for adding its contents -# to a Qpid::Proton::Data instance. -#++ - -# @private -class Hash # :nodoc: - - # Places the contents of the hash into the specified data object. - # - # ==== Arguments - # - # * data - the Qpid::Proton::Data instance - # - # ==== Examples - # - # data = Qpid::Proton::Data.new - # values = {:foo => :bar} - # values.proton_data_put(data) - # - def proton_data_put(data) - raise TypeError, "data object cannot be nil" if data.nil? - - data.put_map - data.enter - - each_pair do |key, value| - type = Qpid::Proton::Codec::Mapping.for_class(key.class) - type.put(data, key) - type = Qpid::Proton::Codec::Mapping.for_class(value.class) - type.put(data, value) - end - - data.exit - end - - class << self - - def proton_data_get(data) - raise TypeError, "data object cannot be nil" if data.nil? - - type = data.type - - raise TypeError, "element is not a map" unless type == Qpid::Proton::Codec::MAP - - count = data.map - result = {} - - data.enter - - (0...(count/2)).each do - data.next - type = data.type - key = type.get(data) - data.next - type = data.type - value = type.get(data) - result[key] = value - end - - data.exit - - return result - end - - end - -end http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/ruby/lib/types/strings.rb ---------------------------------------------------------------------- diff --git a/proton-c/bindings/ruby/lib/types/strings.rb b/proton-c/bindings/ruby/lib/types/strings.rb deleted file mode 100644 index ffbea3c..0000000 --- a/proton-c/bindings/ruby/lib/types/strings.rb +++ /dev/null @@ -1,62 +0,0 @@ -#-- -# 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. -#++ - -module Qpid::Proton::Types - - # @private - def self.is_valid_utf?(value) - # In Ruby 1.9+ we have encoding methods that can check the content of - # the string, so use them to see if what we have is unicode. If so, - # good! If not, then just treat is as binary. - # - # No such thing in Ruby 1.8. So there we need to use Iconv to try and - # convert it to unicode. If it works, good! But if it raises an - # exception then we'll treat it as binary. - if RUBY_VERSION < "1.9" - return true if value.isutf8 - return false - else - return true if (value.encoding == "UTF-8" || - value.encode("UTF-8").valid_encoding?) - - return false - end - end - - # UTFString lets an application explicitly state that a - # string of characters is to be UTF-8 encoded. - # - class UTFString < ::String - - def initialize(value) - if !Qpid::Proton::Types.is_valid_utf?(value) - raise RuntimeError.new("invalid UTF string") - end - - super(value) - end - - end - - # BinaryString lets an application explicitly declare that - # a string value represents arbitrary data. - # - class BinaryString < ::String; end - -end http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/ruby/lib/util/class_wrapper.rb ---------------------------------------------------------------------- diff --git a/proton-c/bindings/ruby/lib/util/class_wrapper.rb b/proton-c/bindings/ruby/lib/util/class_wrapper.rb deleted file mode 100644 index dec16e9..0000000 --- a/proton-c/bindings/ruby/lib/util/class_wrapper.rb +++ /dev/null @@ -1,54 +0,0 @@ -#-- -# 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. -#++ - -module Qpid::Proton::Util - - # This mixin provides a method for mapping from an underlying Proton - # C library class to a Ruby class. - # - # @private - # - module ClassWrapper - - WRAPPERS = - { - "pn_void" => proc {|x| Cproton.pn_void2rb(x)}, - "pn_rbref" => proc {|x| Cproton.pn_void2rb(x)}, - "pn_connection" => proc {|x| Qpid::Proton::Connection.wrap(Cproton.pn_cast_pn_connection(x))}, - "pn_session" => proc {|x| Qpid::Proton::Session.wrap(Cproton.pn_cast_pn_session(x))}, - "pn_link" => proc {|x| Qpid::Proton::Link.wrap(Cproton.pn_cast_pn_link(x))}, - "pn_delivery" => proc {|x| Qpid::Proton::Delivery.wrap(Cproton.pn_cast_pn_delivery(x))}, - "pn_transport" => proc {|x| Qpid::Proton::Transport.wrap(Cproton.pn_cast_pn_transport(x))}, - "pn_selectable" => proc {|x| Qpid::Proton::Selectable.wrap(Cproton.pn_cast_pn_selectable(x))}, - "pn_reactor" => proc {|x| Qpid::Proton::Reactor::Reactor.wrap(Cproton.pn_cast_pn_reactor(x))}, - "pn_task" => proc {|x| Qpid::Proton::Reactor::Task.wrap(Cproton.pn_cast_pn_task(x))}, - } - - def class_wrapper(clazz, c_impl, &block) - proc_func = WRAPPERS[clazz] - if !proc_func.nil? - proc_func.yield(c_impl) - elsif block_given? - yield(c_impl) - end - end - - end - -end http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/ruby/lib/util/condition.rb ---------------------------------------------------------------------- diff --git a/proton-c/bindings/ruby/lib/util/condition.rb b/proton-c/bindings/ruby/lib/util/condition.rb deleted file mode 100644 index b8fd94b..0000000 --- a/proton-c/bindings/ruby/lib/util/condition.rb +++ /dev/null @@ -1,45 +0,0 @@ -#-- -# 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. -#++ - -module Qpid::Proton::Util - - class Condition - - def initialize(name, description = nil, info = nil) - @name = name - @description = description - @info = info - end - - # @private - def to_s - "Condition(#{@name}, #{@description}, #{@info})" - end - - # @private - def ==(other) - ((other.class = self.class) && - (other.name == self.name) && - (other.description == self.description) && - (other.info == self.info)) - end - - end - -end http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/ruby/lib/util/constants.rb ---------------------------------------------------------------------- diff --git a/proton-c/bindings/ruby/lib/util/constants.rb b/proton-c/bindings/ruby/lib/util/constants.rb deleted file mode 100644 index 50225e6..0000000 --- a/proton-c/bindings/ruby/lib/util/constants.rb +++ /dev/null @@ -1,85 +0,0 @@ -#-- -# 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. -#++ - -module Qpid::Proton::Util - - # Provides a means for defining constant values within the namespace - # of a class. - # - # If the class has defined the class method, :post_add_constant, then that - # method will be invoked after each new item is added. It must be defined - # *before* any constants are defined. - # - # ==== Example - # - # class GrammarComponent - # - # include Qpid::Proton::Constants - # - # def self.post_add_constant(key, value) - # @terminal << value if value.terminal? - # @nonterminal << value if !value.terminal? && !value.rule - # @rule << value if value.rule - # end - # - # self.add_constant :LEFT_PARENTHESIS, new GrammarComponent("(", :terminal) - # self.add_constant :RIGHT_PARENTHESIS, new GrammarComponent(")", :terminal) - # self.add_constant :ELEMENT, new GrammarComponent("E", :rule) - # - # def initialize(component, type) - # @component = component - # @type = type - # end - # - # def terminal?; @type == :terminal; end - # - # def rule?; @type == :rule; end - # - # end - # - # @private - # - module Constants - - def self.included(base) - base.extend ClassMethods - end - - module ClassMethods - - def add_constant(key, value) - self.const_set(key, value) - - @pn_by_value ||= {} - @pn_by_value[value] = key - - if self.respond_to? :post_add_constant - self.post_add_constant(key, value) - end - end - - def by_value(value) - (@pn_by_value || {})[value] - end - - end - - end - -end http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/ruby/lib/util/engine.rb ---------------------------------------------------------------------- diff --git a/proton-c/bindings/ruby/lib/util/engine.rb b/proton-c/bindings/ruby/lib/util/engine.rb deleted file mode 100644 index 53aa672..0000000 --- a/proton-c/bindings/ruby/lib/util/engine.rb +++ /dev/null @@ -1,82 +0,0 @@ -#-- -# 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. -#++ - -module Qpid::Proton::Util - - # @private - module Engine - - # Convenience method to receive messages from a delivery. - # - # @param delivery [Qpid::Proton::Delivery] The delivery. - # @param message [Qpid::Proton::Message] The message to use. - # - # @return [Qpid::Proton::Message] the message - # - def self.receive_message(delivery, msg = nil) - msg = Qpid::Proton::Message.new if msg.nil? - msg.decode(delivery.link.receive(delivery.pending)) - delivery.link.advance - return msg - end - - def data_to_object(data_impl) # :nodoc: - object = nil - unless data_impl.nil? - data = Qpid::Proton::Codec::Data.new(data_impl) - data.rewind - data.next - object = data.object - data.rewind - end - return object - end - - def object_to_data(object, data_impl) # :nodoc: - unless object.nil? - data = Data.new(data_impl) - data.object = object - end - end - - def condition_to_object(condition) # :nodoc: - result = nil - if Cproton.pn_condition_is_set(condition) - result = Condition.new(Cproton.pn_condition_get_name(condition), - Cproton.pn_condition_get_description(condition), - data_to_object(Cproton.pn_condition_info(condition))) - end - return result - end - - def object_to_condition(object, condition) # :nodoc: - Cproton.pn_condition_clear(condition) - unless object.nil? - Cproton.pn_condition_set_name(condition, object.name) - Cproton.pn_condition_set_description(condition, object.description) - info = Data.new(Cproton.pn_condition_info(condition)) - if object.info? - info.object = object.info - end - end - end - - end - -end --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org For additional commands, e-mail: commits-h...@qpid.apache.org