You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by mc...@apache.org on 2015/06/08 20:13:30 UTC
[01/31] qpid-proton git commit: PROTON-781: Added the Task class to
the Ruby reactor APIs.
Repository: qpid-proton
Updated Branches:
refs/heads/PROTON-781-ruby-reactor-apis [created] f63454c5c
PROTON-781: Added the Task class to the Ruby reactor APIs.
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/44d062c4
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/44d062c4
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/44d062c4
Branch: refs/heads/PROTON-781-ruby-reactor-apis
Commit: 44d062c43979c2147a8c2ebe9d3e3c885c0b6869
Parents: 271b3a0
Author: Darryl L. Pierce <mc...@gmail.com>
Authored: Mon Feb 23 16:19:33 2015 -0500
Committer: Darryl L. Pierce <mc...@gmail.com>
Committed: Mon Jun 8 13:57:51 2015 -0400
----------------------------------------------------------------------
proton-c/bindings/ruby/lib/qpid_proton.rb | 3 ++
proton-c/bindings/ruby/lib/reactor/task.rb | 39 +++++++++++++++++++++++++
2 files changed, 42 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/44d062c4/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
index a60a028..f3da844 100644
--- a/proton-c/bindings/ruby/lib/qpid_proton.rb
+++ b/proton-c/bindings/ruby/lib/qpid_proton.rb
@@ -92,6 +92,9 @@ require "handler/outgoing_message_handler"
require "handler/c_flow_controller"
require "handler/messaging_handler"
+# Reactor classes
+require "reactor/task"
+
module Qpid::Proton
# @private
def self.registry
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/44d062c4/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
new file mode 100644
index 0000000..6818ed2
--- /dev/null
+++ b/proton-c/bindings/ruby/lib/reactor/task.rb
@@ -0,0 +1,39 @@
+#--
+# 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
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org
[10/31] qpid-proton git commit: PROTON-781: Added MessagingHandler to
the Ruby reactive APIs.
Posted by mc...@apache.org.
PROTON-781: Added MessagingHandler to the Ruby reactive APIs.
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/271b3a00
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/271b3a00
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/271b3a00
Branch: refs/heads/PROTON-781-ruby-reactor-apis
Commit: 271b3a006927537545d899615150671b026e4c86
Parents: 9eaa62a
Author: Darryl L. Pierce <mc...@gmail.com>
Authored: Wed Feb 25 13:32:09 2015 -0500
Committer: Darryl L. Pierce <mc...@gmail.com>
Committed: Mon Jun 8 13:57:51 2015 -0400
----------------------------------------------------------------------
.../ruby/lib/handler/messaging_handler.rb | 218 +++++++++++++++++++
proton-c/bindings/ruby/lib/qpid_proton.rb | 1 +
2 files changed, 219 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/271b3a00/proton-c/bindings/ruby/lib/handler/messaging_handler.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/handler/messaging_handler.rb b/proton-c/bindings/ruby/lib/handler/messaging_handler.rb
new file mode 100644
index 0000000..b4a0bcf
--- /dev/null
+++ b/proton-c/bindings/ruby/lib/handler/messaging_handler.rb
@@ -0,0 +1,218 @@
+#--
+# 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::Handler
+
+ # A general purpose handler that simplifies processing events.
+ #
+ # @example
+ #
+ class MessagingHandler < Qpid::Proton::BaseHandler
+
+ attr_reader :handlers
+
+ # Creates a new instance.
+ #
+ # @param [Fixnum] prefetch
+ # @param [Boolean] auto_accept
+ # @param [Boolean] auto_settle
+ # @param [Boolean] peer_close_is_error
+ #
+ def initialize(prefetch = 10, auto_accept = true, auto_settle = true, peer_close_is_error = false)
+ @handlers = Array.new
+ @handlers << CFlowController.new(prefetch) unless prefetch.zero?
+ @handlers << EndpointStateHandler.new(peer_close_is_error, self)
+ @handlers << IncomingMessageHandler.new(auto_accept, self)
+ @handlers << OutgoingMessageHandler.new(auto_settle,self)
+ end
+
+ # Called when the peer closes the connection with an error condition.
+ #
+ # @param event [Qpid::Proton::Event::Event] The event.
+ #
+ def on_connection_error(event)
+ EndpointStateHandler.print_error(event.connection, "connection")
+ end
+
+ # Called when the peer closes the session with an error condition.
+ #
+ # @param event [Qpid:Proton::Event::Event] The event.
+ #
+ def on_session_error(event)
+ EndpointStateHandler.print_error(event.session, "session")
+ event.connection.close
+ end
+
+ # Called when the peer closes the link with an error condition.
+ #
+ # @param event [Qpid::Proton::Event::Event] The event.
+ #
+ def on_link_error(event)
+ EndpointStateHandler.print_error(event.link, "link")
+ event.connection.close
+ end
+
+ # Called when the event loop starts.
+ #
+ # @param event [Qpid::Proton::Event::Event] The event.
+ #
+ def on_reactor_init(event)
+ self.on_start(event)
+ end
+
+ # Called when the event loop starts.
+ #
+ # This method needs to be overridden.
+ #
+ # @param event [Qpid::Proton::Event::Event] The event.
+ #
+ def on_start(event)
+ end
+
+ # Called when the connection is closed.
+ #
+ # This method needs to be overridden.
+ #
+ # @param event [Qpid::Proton::Event::Event] The event.
+ #
+ def on_connection_closed(event)
+ end
+
+ # Called when the session is closed.
+ #
+ # This method needs to be overridden.
+ #
+ # @param event [Qpid::Proton::Event::Event] The event.
+ #
+ def on_session_closed(event)
+ end
+
+ # Called when the link is closed.
+ #
+ # This method needs to be overridden.
+ #
+ # @param event [Qpid::Proton::Event::Event] The event.
+ #
+ def on_link_closed(event)
+ end
+
+ # Called when the peer initiates the closing of the connection.
+ #
+ # This method needs to be overridden.
+ #
+ # @param event [Qpid::Proton::Event::Event] The event.
+ #
+ def on_connection_closing(event)
+ end
+
+ # Called when the peer initiates the closing of the session.
+ #
+ # This method needs to be overridden.
+ #
+ # @param event [Qpid::Proton::Event::Event] The event.
+ #
+ def on_session_closing(event)
+ end
+
+ # Called when the peer initiates the closing of the link.
+ #
+ # This method needs to be overridden.
+ #
+ # @param event [Qpid::Proton::Event::Event] The event.
+ #
+ def on_link_closing(event)
+ end
+
+ # Called when the socket is disconnected.
+ #
+ # This method needs to be overridden.
+ #
+ # @param event [Qpid::Proton::Event::Event] The event.
+ #
+ def on_disconnected(event)
+ end
+
+ # Called when the sender link has credit and messages can therefore
+ # be transferred.
+ #
+ # This method needs to be overridden.
+ #
+ # @param event [Qpid::Proton::Event::Event] The event.
+ #
+ def on_sendable(event)
+ end
+
+ # Called when the remote peer accepts an outgoing message.
+ #
+ # This method needs to be overridden.
+ #
+ # @param event [Qpid::Proton::Event::Event] The event.
+ #
+ def on_accepted(event)
+ end
+
+ # Called when the remote peer rejects an outgoing message.
+ #
+ # This method needs to be overridden.
+ #
+ # @param event [Qpid::Proton::Event::Event] The event.
+ #
+ def on_rejected(event)
+ end
+
+ # Called when the remote peer releases an outgoing message.
+ #
+ # Note that this may be in response to either the RELEASE or
+ # MODIFIED state as defined by the AMPQ specification.
+ #
+ # This method needs to be overridden.
+ #
+ # @param event [Qpid::Proton::Event::Event] The event.
+ #
+ def on_released(event)
+ end
+
+ # Called when the remote peer has settled hte outgoing message.
+ #
+ # This is the point at which it should never be retransmitted.
+ #
+ # This method needs to be overridden.
+ #
+ # @param event [Qpid::Proton::Event::Event] The event.
+ #
+ def on_settled(event)
+ end
+
+ # Called when a message is received.
+ #
+ # The message itself can be obtained as a property on the event. For
+ # the purpose of referring to this message in further actions, such as
+ # explicitly accepting it) the delivery should be used. This is also
+ # obtainable vi a property on the event.
+ #
+ # This method needs to be overridden.
+ #
+ # @param event [Qpid::Proton::Event::Event] The event.
+ #
+ def on_message(event)
+ end
+
+ end
+
+end
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/271b3a00/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
index 5c2e1bc..a60a028 100644
--- a/proton-c/bindings/ruby/lib/qpid_proton.rb
+++ b/proton-c/bindings/ruby/lib/qpid_proton.rb
@@ -90,6 +90,7 @@ require "handler/endpoint_state_handler"
require "handler/incoming_message_handler"
require "handler/outgoing_message_handler"
require "handler/c_flow_controller"
+require "handler/messaging_handler"
module Qpid::Proton
# @private
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org
[20/31] qpid-proton git commit: PROTON-781: Added the Timeout mixin
to the Ruby APIs.
Posted by mc...@apache.org.
PROTON-781: Added the Timeout mixin to the Ruby APIs.
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/5b72338a
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/5b72338a
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/5b72338a
Branch: refs/heads/PROTON-781-ruby-reactor-apis
Commit: 5b72338aee39379c56b799b6ec91aa2dbce3388f
Parents: 44f1312
Author: Darryl L. Pierce <mc...@gmail.com>
Authored: Mon Mar 2 15:42:20 2015 -0500
Committer: Darryl L. Pierce <mc...@gmail.com>
Committed: Mon Jun 8 13:57:52 2015 -0400
----------------------------------------------------------------------
proton-c/bindings/ruby/lib/qpid_proton.rb | 1 +
proton-c/bindings/ruby/lib/util/timeout.rb | 50 +++++++++++++++++++++++++
2 files changed, 51 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/5b72338a/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
index 5b0d23f..0c84f20 100644
--- a/proton-c/bindings/ruby/lib/qpid_proton.rb
+++ b/proton-c/bindings/ruby/lib/qpid_proton.rb
@@ -40,6 +40,7 @@ require "util/wrapper"
require "util/class_wrapper"
require "util/engine"
require "util/uuid"
+require "util/timeout"
# Types
require "types/strings"
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/5b72338a/proton-c/bindings/ruby/lib/util/timeout.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/util/timeout.rb b/proton-c/bindings/ruby/lib/util/timeout.rb
new file mode 100644
index 0000000..f4647f5
--- /dev/null
+++ b/proton-c/bindings/ruby/lib/util/timeout.rb
@@ -0,0 +1,50 @@
+#--
+# 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 methods for converting between milliseconds, seconds
+ # and timeout values.
+ #
+ # @private
+ module Timeout
+
+ def sec_to_millis(s)
+ return (s * 1000).to_int
+ end
+
+ def millis_to_sec(ms)
+ return (ms.to_f / 1000.0).to_int
+ end
+
+ def timeout_to_millis(s)
+ return Cproton::PN_MILLIS_MAX if s.nil?
+
+ return sec_to_millis(s)
+ end
+
+ def millis_to_timeout(ms)
+ return nil if ms == Cproton::PN_MILLIS_MAX
+
+ return millis_to_sec(ms)
+ end
+
+ end
+
+end
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org
[06/31] qpid-proton git commit: PROTON-781: Repackaged the Ruby
Selectable class to Qpid::Proton.
Posted by mc...@apache.org.
PROTON-781: Repackaged the Ruby Selectable class to Qpid::Proton.
It's now a part of the core APIs and not part of the Messenger APIs.
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/9e8583c3
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/9e8583c3
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/9e8583c3
Branch: refs/heads/PROTON-781-ruby-reactor-apis
Commit: 9e8583c32c0e993643b012b2c42745ff30fc64cf
Parents: 4dffce6
Author: Darryl L. Pierce <mc...@gmail.com>
Authored: Tue Feb 24 13:31:51 2015 -0500
Committer: Darryl L. Pierce <mc...@gmail.com>
Committed: Mon Jun 8 13:57:51 2015 -0400
----------------------------------------------------------------------
proton-c/bindings/ruby/lib/core/selectable.rb | 118 +++++++++++++++++++
.../bindings/ruby/lib/messenger/selectable.rb | 118 -------------------
proton-c/bindings/ruby/lib/qpid_proton.rb | 2 +-
3 files changed, 119 insertions(+), 119 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/9e8583c3/proton-c/bindings/ruby/lib/core/selectable.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/core/selectable.rb b/proton-c/bindings/ruby/lib/core/selectable.rb
new file mode 100644
index 0000000..8a5b223
--- /dev/null
+++ b/proton-c/bindings/ruby/lib/core/selectable.rb
@@ -0,0 +1,118 @@
+#--
+# 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
+
+ # Selectable enables accessing the underlying file descriptors
+ # for Messenger.
+ #
+ # @private
+ class Selectable
+
+
+ def initialize(messenger, impl) # :nodoc:
+ @messenger = messenger
+ @impl = impl
+ @io = nil
+ @freed = false
+ end
+
+ # Returns the underlying file descriptor.
+ #
+ # This can be used in conjunction with the IO class.
+ #
+ def fileno
+ Cproton.pn_selectable_get_fd(@impl)
+ end
+
+ def to_io
+ @io ||= IO.new(fileno)
+ end
+
+ # The number of bytes the selectable is capable of consuming.
+ #
+ #def capacity
+ # Cproton.pn_selectable_capacity(@impl)
+ #end
+
+ # The number of bytes waiting to be written to the file descriptor.
+ #
+ def pending
+ Cproton.pn_selectable_pending(@impl)
+ end
+
+ # The future expiry time at which control will be returned to the
+ # selectable.
+ #
+ def deadline
+ tstamp = Cproton.pn_selectable_deadline(@impl)
+ tstamp.nil? ? nil : tstamp / 1000
+ end
+
+ def readable
+ Cproton.pn_selectable_readable(@impl)
+ end
+
+ def writable
+ Cproton.pn_selectable_writable(@impl)
+ end
+
+ def expired?
+ Cproton.pn_selectable_expired(@impl)
+ end
+
+ def registered=(registered)
+ Cproton.pn_selectable_set_registered(@impl, registered)
+ end
+
+ def registered?
+ Cproton.pn_selectable_is_registered(@impl)
+ end
+
+ def terminal?
+ return true if @impl.nil?
+ Cproton.pn_selectable_is_terminal(@impl)
+ end
+
+ def to_s
+ "fileno=#{self.fileno} registered=#{self.registered?} terminal=#{self.terminal?}"
+ end
+
+ def free
+ return if @freed
+ @freed = true
+ @messenger.unregister_selectable(fileno)
+ @io.close unless @io.nil?
+ Cproton.pn_selectable_free(@impl)
+ @impl = nil
+ end
+
+ def freed? # :nodoc:
+ @freed
+ end
+
+ private
+
+ def check_is_initialized
+ raise RuntimeError.new("selectable freed") if @impl.nil?
+ end
+
+ end
+
+end
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/9e8583c3/proton-c/bindings/ruby/lib/messenger/selectable.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/messenger/selectable.rb b/proton-c/bindings/ruby/lib/messenger/selectable.rb
deleted file mode 100644
index da1a3d5..0000000
--- a/proton-c/bindings/ruby/lib/messenger/selectable.rb
+++ /dev/null
@@ -1,118 +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
-
- # Selectable enables accessing the underlying file descriptors
- # for Messenger.
- #
- # @private
- class Selectable
-
-
- def initialize(messenger, impl) # :nodoc:
- @messenger = messenger
- @impl = impl
- @io = nil
- @freed = false
- end
-
- # Returns the underlying file descriptor.
- #
- # This can be used in conjunction with the IO class.
- #
- def fileno
- Cproton.pn_selectable_get_fd(@impl)
- end
-
- def to_io
- @io ||= IO.new(fileno)
- end
-
- # The number of bytes the selectable is capable of consuming.
- #
- #def capacity
- # Cproton.pn_selectable_capacity(@impl)
- #end
-
- # The number of bytes waiting to be written to the file descriptor.
- #
- def pending
- Cproton.pn_selectable_pending(@impl)
- end
-
- # The future expiry time at which control will be returned to the
- # selectable.
- #
- def deadline
- tstamp = Cproton.pn_selectable_deadline(@impl)
- tstamp.nil? ? nil : tstamp / 1000
- end
-
- def readable
- Cproton.pn_selectable_readable(@impl)
- end
-
- def writable
- Cproton.pn_selectable_writable(@impl)
- end
-
- def expired?
- Cproton.pn_selectable_expired(@impl)
- end
-
- def registered=(registered)
- Cproton.pn_selectable_set_registered(@impl, registered)
- end
-
- def registered?
- Cproton.pn_selectable_is_registered(@impl)
- end
-
- def terminal?
- return true if @impl.nil?
- Cproton.pn_selectable_is_terminal(@impl)
- end
-
- def to_s
- "fileno=#{self.fileno} registered=#{self.registered?} terminal=#{self.terminal?}"
- end
-
- def free
- return if @freed
- @freed = true
- @messenger.unregister_selectable(fileno)
- @io.close unless @io.nil?
- Cproton.pn_selectable_free(@impl)
- @impl = nil
- end
-
- def freed? # :nodoc:
- @freed
- end
-
- private
-
- def check_is_initialized
- raise RuntimeError.new("selectable freed") if @impl.nil?
- end
-
- end
-
-end
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/9e8583c3/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
index 21f96a1..a4b3391 100644
--- a/proton-c/bindings/ruby/lib/qpid_proton.rb
+++ b/proton-c/bindings/ruby/lib/qpid_proton.rb
@@ -58,6 +58,7 @@ require "event/event"
require "event/collector"
# Main Proton classes
+require "core/selectable"
require "core/message"
require "core/endpoint"
require "core/session"
@@ -78,7 +79,6 @@ require "core/transport"
require "messenger/subscription"
require "messenger/tracker_status"
require "messenger/tracker"
-require "messenger/selectable"
require "messenger/messenger"
# Handler classes
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org
[28/31] qpid-proton git commit: PROTON-781: Added Reactor and Task to
the ClassWrapper
Posted by mc...@apache.org.
PROTON-781: Added Reactor and Task to the ClassWrapper
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/953ba96f
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/953ba96f
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/953ba96f
Branch: refs/heads/PROTON-781-ruby-reactor-apis
Commit: 953ba96fab906233a5522ce61881d7f5110375d1
Parents: 5fc194a
Author: Darryl L. Pierce <mc...@gmail.com>
Authored: Wed Mar 4 10:54:54 2015 -0500
Committer: Darryl L. Pierce <mc...@gmail.com>
Committed: Mon Jun 8 13:57:52 2015 -0400
----------------------------------------------------------------------
proton-c/bindings/ruby/lib/util/class_wrapper.rb | 2 ++
1 file changed, 2 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/953ba96f/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
index 134f655..dec16e9 100644
--- a/proton-c/bindings/ruby/lib/util/class_wrapper.rb
+++ b/proton-c/bindings/ruby/lib/util/class_wrapper.rb
@@ -36,6 +36,8 @@ module Qpid::Proton::Util
"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)
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org
[07/31] qpid-proton git commit: PROTON-781: Added the CFlowController
class to the Ruby reactive APIs.
Posted by mc...@apache.org.
PROTON-781: Added the CFlowController class to the Ruby reactive APIs.
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/b65cd5e1
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/b65cd5e1
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/b65cd5e1
Branch: refs/heads/PROTON-781-ruby-reactor-apis
Commit: b65cd5e1c7f1525d00226fe6332b1da4762e31e4
Parents: 43970df
Author: Darryl L. Pierce <mc...@gmail.com>
Authored: Wed Feb 25 13:29:22 2015 -0500
Committer: Darryl L. Pierce <mc...@gmail.com>
Committed: Mon Jun 8 13:57:51 2015 -0400
----------------------------------------------------------------------
.../ruby/lib/handler/c_flow_controller.rb | 33 ++++++++++++++++++++
proton-c/bindings/ruby/lib/qpid_proton.rb | 1 +
2 files changed, 34 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b65cd5e1/proton-c/bindings/ruby/lib/handler/c_flow_controller.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/handler/c_flow_controller.rb b/proton-c/bindings/ruby/lib/handler/c_flow_controller.rb
new file mode 100644
index 0000000..377cc2f
--- /dev/null
+++ b/proton-c/bindings/ruby/lib/handler/c_flow_controller.rb
@@ -0,0 +1,33 @@
+#--
+# 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::Handler
+
+ # @private
+ class CFlowController < Qpid::Proton::Handler::WrappedHandler
+
+ include Qpid::Proton::Util::Wrapper
+
+ def initialize(window = 1024)
+ super(Cproton.pn_flowcontroller(window))
+ end
+
+ end
+
+end
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b65cd5e1/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
index 08e60b9..e14ff9d 100644
--- a/proton-c/bindings/ruby/lib/qpid_proton.rb
+++ b/proton-c/bindings/ruby/lib/qpid_proton.rb
@@ -86,6 +86,7 @@ require "handler/c_adaptor"
require "handler/wrapped_handler"
require "handler/acking"
require "handler/endpoint_state_handler"
+require "handler/c_flow_controller"
module Qpid::Proton
# @private
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org
[18/31] qpid-proton git commit: PROTON-781: Added the Reactor class
to the Ruby reactor APIs.
Posted by mc...@apache.org.
PROTON-781: Added the Reactor class to the Ruby reactor APIs.
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/1573e5bf
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/1573e5bf
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/1573e5bf
Branch: refs/heads/PROTON-781-ruby-reactor-apis
Commit: 1573e5bf6744e6e016dc89ecc4dff264ed69f41e
Parents: 0f45ba0
Author: Darryl L. Pierce <mc...@gmail.com>
Authored: Mon Feb 23 16:21:02 2015 -0500
Committer: Darryl L. Pierce <mc...@gmail.com>
Committed: Mon Jun 8 13:57:52 2015 -0400
----------------------------------------------------------------------
proton-c/bindings/ruby/lib/qpid_proton.rb | 1 +
proton-c/bindings/ruby/lib/reactor/reactor.rb | 198 +++++++++++++++++++++
2 files changed, 199 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/1573e5bf/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
index bffd4d1..f8703e7 100644
--- a/proton-c/bindings/ruby/lib/qpid_proton.rb
+++ b/proton-c/bindings/ruby/lib/qpid_proton.rb
@@ -95,6 +95,7 @@ require "handler/messaging_handler"
# Reactor classes
require "reactor/task"
require "reactor/acceptor"
+require "reactor/reactor"
module Qpid::Proton
# @private
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/1573e5bf/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
new file mode 100644
index 0000000..1cf4f6c
--- /dev/null
+++ b/proton-c/bindings/ruby/lib/reactor/reactor.rb
@@ -0,0 +1,198 @@
+#--
+# 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?
+ io = Cproton.pn_reactor_io(@impl)
+ raise IOError.new(Cproton.pn_io_error(io))
+ 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 = Cproton.pn_reactor_io(@impl)
+ io_error = Cproton.pn_io_error(io)
+ 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
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org
[13/31] qpid-proton git commit: PROTON-781: Added GlobalOverrides to
the Ruby reactive APIs.
Posted by mc...@apache.org.
PROTON-781: Added GlobalOverrides to the Ruby reactive APIs.
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/44f13125
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/44f13125
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/44f13125
Branch: refs/heads/PROTON-781-ruby-reactor-apis
Commit: 44f1312525c51a13ab6b82e1bff9050ec54297d2
Parents: cb84a67
Author: Darryl L. Pierce <mc...@gmail.com>
Authored: Thu Feb 26 11:28:35 2015 -0500
Committer: Darryl L. Pierce <mc...@gmail.com>
Committed: Mon Jun 8 13:57:52 2015 -0400
----------------------------------------------------------------------
proton-c/bindings/ruby/lib/qpid_proton.rb | 1 +
.../ruby/lib/reactor/global_overrides.rb | 44 ++++++++++++++++++++
2 files changed, 45 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/44f13125/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
index d8783bc..5b0d23f 100644
--- a/proton-c/bindings/ruby/lib/qpid_proton.rb
+++ b/proton-c/bindings/ruby/lib/qpid_proton.rb
@@ -97,6 +97,7 @@ require "reactor/task"
require "reactor/acceptor"
require "reactor/reactor"
require "reactor/ssl_config"
+require "reactor/global_overrides"
module Qpid::Proton
# @private
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/44f13125/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
new file mode 100644
index 0000000..11d05a5
--- /dev/null
+++ b/proton-c/bindings/ruby/lib/reactor/global_overrides.rb
@@ -0,0 +1,44 @@
+#--
+# 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
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org
[04/31] qpid-proton git commit: PROTON-781: Deleted the Ruby Filter
mixin.
Posted by mc...@apache.org.
PROTON-781: Deleted the Ruby Filter mixin.
It was only used by Selectable, which is being refactored based on the
new underlying C Selectable type.
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/4dffce64
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/4dffce64
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/4dffce64
Branch: refs/heads/PROTON-781-ruby-reactor-apis
Commit: 4dffce64ff5f4e706043686fce781580322b7acb
Parents: e77477b
Author: Darryl L. Pierce <mc...@gmail.com>
Authored: Tue Feb 24 10:55:25 2015 -0500
Committer: Darryl L. Pierce <mc...@gmail.com>
Committed: Mon Jun 8 13:57:51 2015 -0400
----------------------------------------------------------------------
proton-c/bindings/ruby/lib/messenger/filters.rb | 64 --------------------
.../bindings/ruby/lib/messenger/selectable.rb | 6 --
proton-c/bindings/ruby/lib/qpid_proton.rb | 1 -
3 files changed, 71 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/4dffce64/proton-c/bindings/ruby/lib/messenger/filters.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/messenger/filters.rb b/proton-c/bindings/ruby/lib/messenger/filters.rb
deleted file mode 100644
index 0ab3407..0000000
--- a/proton-c/bindings/ruby/lib/messenger/filters.rb
+++ /dev/null
@@ -1,64 +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
-
- # @private
- module Filters
-
- def self.included(base)
- base.class_eval do
- extend ClassMethods
- end
- end
-
- module ClassMethods
-
- def method_added(method_name)
- @@hooked_methods ||= []
- return if @@hooked_methods.include?(method_name)
- @@hooked_methods << method_name
- hooks = @@before_hooks[method_name]
- return if hooks.nil?
- orig_method = instance_method(method_name)
- define_method(method_name) do |*args, &block|
- hooks = @@before_hooks[method_name]
- hooks.each do |hook|
- method(hook).call
- end
-
- orig_method.bind(self).call(*args, &block)
- end
- end
-
- def call_before(before_method, *methods)
- @@before_hooks ||= {}
- methods.each do |method|
- hooks = @@before_hooks[method] || []
- raise "Repeat filter: #{before_method}" if hooks.include? before_method
- hooks << before_method
- @@before_hooks[method] = hooks
- end
- end
-
- end
-
- end
-
-end
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/4dffce64/proton-c/bindings/ruby/lib/messenger/selectable.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/messenger/selectable.rb b/proton-c/bindings/ruby/lib/messenger/selectable.rb
index ec5174f..da1a3d5 100644
--- a/proton-c/bindings/ruby/lib/messenger/selectable.rb
+++ b/proton-c/bindings/ruby/lib/messenger/selectable.rb
@@ -25,12 +25,6 @@ module Qpid::Proton::Messenger
# @private
class Selectable
- include Filters
-
- call_before :check_is_initialized,
- :fileno, :capacity, :pending, :deadline,
- :readable, :writable, :expired,
- :registered=, :registered?
def initialize(messenger, impl) # :nodoc:
@messenger = messenger
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/4dffce64/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
index 2791538..21f96a1 100644
--- a/proton-c/bindings/ruby/lib/qpid_proton.rb
+++ b/proton-c/bindings/ruby/lib/qpid_proton.rb
@@ -75,7 +75,6 @@ require "core/ssl"
require "core/transport"
# Messenger API classes
-require "messenger/filters"
require "messenger/subscription"
require "messenger/tracker_status"
require "messenger/tracker"
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org
[14/31] qpid-proton git commit: PROTON-781: Added Backoff to the Ruby
reactive APIs.
Posted by mc...@apache.org.
PROTON-781: Added Backoff to the Ruby reactive APIs.
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/ca7f8f99
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/ca7f8f99
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/ca7f8f99
Branch: refs/heads/PROTON-781-ruby-reactor-apis
Commit: ca7f8f993aa8a071e7cd4b380858b2a494ac4335
Parents: 58519ad
Author: Darryl L. Pierce <mc...@gmail.com>
Authored: Wed Mar 4 16:39:13 2015 -0500
Committer: Darryl L. Pierce <mc...@gmail.com>
Committed: Mon Jun 8 13:57:52 2015 -0400
----------------------------------------------------------------------
proton-c/bindings/ruby/lib/qpid_proton.rb | 1 +
proton-c/bindings/ruby/lib/reactor/backoff.rb | 41 ++++++++++++++++++++++
2 files changed, 42 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ca7f8f99/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
index 6047613..661927e 100644
--- a/proton-c/bindings/ruby/lib/qpid_proton.rb
+++ b/proton-c/bindings/ruby/lib/qpid_proton.rb
@@ -104,6 +104,7 @@ require "reactor/ssl_config"
require "reactor/global_overrides"
require "reactor/urls"
require "reactor/connector"
+require "reactor/backoff"
module Qpid::Proton
# @private
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ca7f8f99/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
new file mode 100644
index 0000000..99682e5
--- /dev/null
+++ b/proton-c/bindings/ruby/lib/reactor/backoff.rb
@@ -0,0 +1,41 @@
+#--
+# 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
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org
[29/31] qpid-proton git commit: PROTON-781: Added Connector to the
Ruby reactive APIs.
Posted by mc...@apache.org.
PROTON-781: Added Connector to the Ruby reactive APIs.
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/58519ad8
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/58519ad8
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/58519ad8
Branch: refs/heads/PROTON-781-ruby-reactor-apis
Commit: 58519ad865746177c48f9d3bc05183948e7974de
Parents: 4c09ae2
Author: Darryl L. Pierce <mc...@gmail.com>
Authored: Wed Mar 4 16:38:47 2015 -0500
Committer: Darryl L. Pierce <mc...@gmail.com>
Committed: Mon Jun 8 13:57:52 2015 -0400
----------------------------------------------------------------------
proton-c/bindings/ruby/lib/qpid_proton.rb | 1 +
proton-c/bindings/ruby/lib/reactor/connector.rb | 98 ++++++++++++++++++++
2 files changed, 99 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/58519ad8/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
index 4f017e1..6047613 100644
--- a/proton-c/bindings/ruby/lib/qpid_proton.rb
+++ b/proton-c/bindings/ruby/lib/qpid_proton.rb
@@ -103,6 +103,7 @@ require "reactor/reactor"
require "reactor/ssl_config"
require "reactor/global_overrides"
require "reactor/urls"
+require "reactor/connector"
module Qpid::Proton
# @private
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/58519ad8/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
new file mode 100644
index 0000000..a6523db
--- /dev/null
+++ b/proton-c/bindings/ruby/lib/reactor/connector.rb
@@ -0,0 +1,98 @@
+#--
+# 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
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org
[12/31] qpid-proton git commit: PROTON-781: Added
IncomingMessageHandler to the Ruby reactive APIs.
Posted by mc...@apache.org.
PROTON-781: Added IncomingMessageHandler to the Ruby reactive APIs.
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/498225e7
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/498225e7
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/498225e7
Branch: refs/heads/PROTON-781-ruby-reactor-apis
Commit: 498225e77c61aa3e9bf642c63b1c66d6cde47357
Parents: 3179116
Author: Darryl L. Pierce <mc...@gmail.com>
Authored: Thu Feb 26 09:23:00 2015 -0500
Committer: Darryl L. Pierce <mc...@gmail.com>
Committed: Mon Jun 8 13:57:51 2015 -0400
----------------------------------------------------------------------
proton-c/bindings/ruby/lib/core/exceptions.rb | 10 +++
.../lib/handler/incoming_message_handler.rb | 74 ++++++++++++++++++++
proton-c/bindings/ruby/lib/qpid_proton.rb | 1 +
3 files changed, 85 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/498225e7/proton-c/bindings/ruby/lib/core/exceptions.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/core/exceptions.rb b/proton-c/bindings/ruby/lib/core/exceptions.rb
index 94d2957..75d6552 100644
--- a/proton-c/bindings/ruby/lib/core/exceptions.rb
+++ b/proton-c/bindings/ruby/lib/core/exceptions.rb
@@ -111,6 +111,16 @@ module Qpid
class SSLUnavailableError < SSLError
end
+ # Raised when a message is rejected.
+ #
+ class Reject < ProtonError
+ end
+
+ # Raised when a message is released.
+ #
+ class Release < ProtonError
+ end
+
end
end
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/498225e7/proton-c/bindings/ruby/lib/handler/incoming_message_handler.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/handler/incoming_message_handler.rb b/proton-c/bindings/ruby/lib/handler/incoming_message_handler.rb
new file mode 100644
index 0000000..ced84a2
--- /dev/null
+++ b/proton-c/bindings/ruby/lib/handler/incoming_message_handler.rb
@@ -0,0 +1,74 @@
+#--
+# 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::Handler
+
+ # A utility for simpler and more intuitive handling of delivery events
+ # related to incoming messages.
+ #
+ class IncomingMessageHandler < Qpid::Proton::BaseHandler
+
+ include Acking
+
+ def initialize(auto_accept = true, delegate = nil)
+ @delegate = delegate
+ @auto_accept = auto_accept
+ end
+
+ def on_delivery(event)
+ delivery = event.delivery
+ return unless delivery.link.receiver?
+ if delivery.readable? && !delivery.partial?
+ event.message = Qpid::Proton::Util::Engine.receive_message(delivery)
+ if event.link.local_closed?
+ if @auto_accept
+ delivery.update(Qpid::Proton::Disposition::RELEASED)
+ delivery.settle
+ end
+ else
+ begin
+ self.on_message(event)
+ if @auto_accept
+ delivery.update(Qpid::Proton::Disposition::ACCEPTED)
+ delivery.settle
+ end
+ rescue Qpid::Proton::Reject
+ delivery.update(Qpid::Proton::Disposition::REJECTED)
+ delivery.settle
+ rescue Qpid::Proton::Release
+ delivery.update(Qpid::Proton::Disposition::MODIFIED)
+ delivery.settle
+ end
+ end
+ elsif delivery.updated? && delivery.settled?
+ self.on_settled(event)
+ end
+ end
+
+ def on_message(event)
+ Qpid::Proton::Event.dispatch(@delegate, :on_message, event) if !@delegate.nil?
+ end
+
+ def on_settled(event)
+ Qpid::Proton::Event.dispatch(@delegate, :on_settled, event) if !@delegate.nil?
+ end
+
+ end
+
+end
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/498225e7/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
index ef7f300..1fbf710 100644
--- a/proton-c/bindings/ruby/lib/qpid_proton.rb
+++ b/proton-c/bindings/ruby/lib/qpid_proton.rb
@@ -87,6 +87,7 @@ require "handler/c_adaptor"
require "handler/wrapped_handler"
require "handler/acking"
require "handler/endpoint_state_handler"
+require "handler/incoming_message_handler"
require "handler/c_flow_controller"
module Qpid::Proton
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org
[05/31] qpid-proton git commit: PROTON-781: Added the WrappedHandler
class to the Ruby reactor APIs.
Posted by mc...@apache.org.
PROTON-781: Added the WrappedHandler class to the Ruby reactor APIs.
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/e77477b9
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/e77477b9
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/e77477b9
Branch: refs/heads/PROTON-781-ruby-reactor-apis
Commit: e77477b93b27a32eebc52dbde5c6793c5e6e42b6
Parents: d921c6b
Author: Darryl L. Pierce <mc...@gmail.com>
Authored: Mon Feb 23 16:18:01 2015 -0500
Committer: Darryl L. Pierce <mc...@gmail.com>
Committed: Mon Jun 8 13:57:51 2015 -0400
----------------------------------------------------------------------
proton-c/bindings/ruby/lib/handler/c_adaptor.rb | 47 ++++++++++++
.../ruby/lib/handler/wrapped_handler.rb | 76 ++++++++++++++++++++
proton-c/bindings/ruby/lib/qpid_proton.rb | 4 ++
proton-c/bindings/ruby/ruby.i | 53 ++++++++++++++
4 files changed, 180 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/e77477b9/proton-c/bindings/ruby/lib/handler/c_adaptor.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/handler/c_adaptor.rb b/proton-c/bindings/ruby/lib/handler/c_adaptor.rb
new file mode 100644
index 0000000..ef4852e
--- /dev/null
+++ b/proton-c/bindings/ruby/lib/handler/c_adaptor.rb
@@ -0,0 +1,47 @@
+#--
+# 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::Handler
+
+ # @private
+ class CAdaptor
+
+ def initialize(handler, on_error = nil)
+ @handler = handler
+ @on_error = on_error
+ end
+
+ def dispatch(cevent, ctype)
+ event = Qpid::Proton::Event::Event.wrap(cevent, ctype)
+ # TODO add a variable to enable this programmatically
+ # print "EVENT: #{event} going to #{@handler}\n"
+ event.dispatch(@handler)
+ end
+
+ def exception(error)
+ if @on_error.nil?
+ raise error
+ else
+ @on_error.call(error)
+ end
+ end
+
+ end
+
+end
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/e77477b9/proton-c/bindings/ruby/lib/handler/wrapped_handler.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/handler/wrapped_handler.rb b/proton-c/bindings/ruby/lib/handler/wrapped_handler.rb
new file mode 100644
index 0000000..6d55dee
--- /dev/null
+++ b/proton-c/bindings/ruby/lib/handler/wrapped_handler.rb
@@ -0,0 +1,76 @@
+#--
+# 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::Handler
+
+ class WrappedHandler
+
+ # @private
+ include Qpid::Proton::Util::Wrapper
+
+ def self.wrap(impl, on_error = nil)
+ return nil if impl.nil?
+
+ result = self.fetch_instance(impl) || WrappedHandler.new(impl)
+ result.on_error = on_error
+ return result
+ end
+
+ include Qpid::Proton::Util::Handler
+
+ def initialize(impl_or_constructor)
+ if impl_or_constructor.is_a?(Method)
+ @impl = impl_or_constructor.call
+ else
+ @impl = impl_or_constructor
+ Cproton.pn_incref(@impl)
+ end
+ @on_error = nil
+ self.class.store_instance(self)
+ end
+
+ def add(handler)
+ return if handler.nil?
+
+ impl = chandler(handler, self.method(:_on_error))
+ Cproton.pn_handler_add(@impl, impl)
+ Cproton.pn_decref(impl)
+ end
+
+ def clear
+ Cproton.pn_handler_clear(@impl)
+ end
+
+ def on_error=(on_error)
+ @on_error = on_error
+ end
+
+ private
+
+ def _on_error(info)
+ if self.has?['on_error']
+ self['on_error'].call(info)
+ else
+ raise info
+ end
+ end
+
+ end
+
+end
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/e77477b9/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
index 467d959..2791538 100644
--- a/proton-c/bindings/ruby/lib/qpid_proton.rb
+++ b/proton-c/bindings/ruby/lib/qpid_proton.rb
@@ -82,6 +82,10 @@ require "messenger/tracker"
require "messenger/selectable"
require "messenger/messenger"
+# Handler classes
+require "handler/c_adaptor"
+require "handler/wrapped_handler"
+
module Qpid::Proton
# @private
def self.registry
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/e77477b9/proton-c/bindings/ruby/ruby.i
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/ruby.i b/proton-c/bindings/ruby/ruby.i
index 0534808..1c34cd6 100644
--- a/proton-c/bindings/ruby/ruby.i
+++ b/proton-c/bindings/ruby/ruby.i
@@ -570,4 +570,57 @@ VALUE pni_address_of(void *object) {
%}
%ignore pn_ssl_get_peer_hostname;
+%inline %{
+
+ VALUE pni_ruby_get_proton_module() {
+ VALUE mQpid = rb_define_module("Qpid");
+ return rb_define_module_under(mQpid, "Proton");
+ }
+
+ void pni_ruby_add_to_registry(VALUE key, VALUE value) {
+ VALUE result = rb_funcall(pni_ruby_get_proton_module(), rb_intern("add_to_registry"), 2, key, value);
+ }
+
+ VALUE pni_ruby_get_from_registry(VALUE key) {
+ rb_funcall(pni_ruby_get_proton_module(), rb_intern("get_from_registry"), 1, key);
+ }
+
+ void pni_ruby_delete_from_registry(VALUE stored_key) {
+ rb_funcall(pni_ruby_get_proton_module(), rb_intern("delete_from_registry"), 1, stored_key);
+ }
+
+ typedef struct {
+ VALUE handler_key;
+ } pni_rbhandler_t;
+
+ static pni_rbhandler_t *pni_rbhandler(pn_handler_t *handler) {
+ return (pni_rbhandler_t *) pn_handler_mem(handler);
+ }
+
+ static void pni_rbdispatch(pn_handler_t *handler, pn_event_t *event, pn_event_type_t type) {
+ pni_rbhandler_t *rbh = pni_rbhandler(handler);
+ VALUE rbhandler = pni_ruby_get_from_registry(rbh->handler_key);
+
+ rb_funcall(rbhandler, rb_intern("dispatch"), 2, SWIG_NewPointerObj(event, SWIGTYPE_p_pn_event_t, 0), INT2FIX(type));
+ }
+
+ static void pni_rbhandler_finalize(pn_handler_t *handler) {
+ pni_rbhandler_t *rbh = pni_rbhandler(handler);
+ pni_ruby_delete_from_registry(rbh->handler_key);
+ }
+
+ pn_handler_t *pn_rbhandler(VALUE handler) {
+ pn_handler_t *chandler = pn_handler_new(pni_rbdispatch, sizeof(pni_rbhandler_t), pni_rbhandler_finalize);
+ pni_rbhandler_t *rhy = pni_rbhandler(chandler);
+
+ VALUE ruby_key = rb_class_new_instance(0, NULL, rb_cObject);
+ pni_ruby_add_to_registry(ruby_key, handler);
+
+ rhy->handler_key = ruby_key;
+
+ return chandler;
+ }
+
+%}
+
%include "proton/cproton.i"
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org
[09/31] qpid-proton git commit: PROTON-781: Added the Acking mixin to
the Ruby reactive APIs.
Posted by mc...@apache.org.
PROTON-781: Added the Acking mixin to the Ruby reactive APIs.
The Acking mixin provides methods for handling the settling of messages
based on reactive callbacks.
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/9ff3e048
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/9ff3e048
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/9ff3e048
Branch: refs/heads/PROTON-781-ruby-reactor-apis
Commit: 9ff3e048d3f4a0af8bfa76806025f14b6f501f39
Parents: 340a9da
Author: Darryl L. Pierce <mc...@gmail.com>
Authored: Wed Feb 25 13:27:30 2015 -0500
Committer: Darryl L. Pierce <mc...@gmail.com>
Committed: Mon Jun 8 13:57:51 2015 -0400
----------------------------------------------------------------------
proton-c/bindings/ruby/lib/handler/acking.rb | 70 +++++++++++++++++++++++
proton-c/bindings/ruby/lib/qpid_proton.rb | 1 +
2 files changed, 71 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/9ff3e048/proton-c/bindings/ruby/lib/handler/acking.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/handler/acking.rb b/proton-c/bindings/ruby/lib/handler/acking.rb
new file mode 100644
index 0000000..2c94cfe
--- /dev/null
+++ b/proton-c/bindings/ruby/lib/handler/acking.rb
@@ -0,0 +1,70 @@
+#--
+# 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::Handler
+
+ # Mixing that provides methods for acknowledging a delivery.
+ #
+ module Acking
+
+ # Accept the receivered message.
+ #
+ # @param delivery [Qpid::Proton::Delivery] The delivery.
+ #
+ def accept(delivery)
+ self.settle(delivery, Qpid::Proton::Delivery::ACCEPTED)
+ end
+
+ # Rejects a received message that is considered invalid or unprocessable.
+ #
+ # @param delivery [Qpid::Proton::Delivery] The delivery.
+ #
+ def reject(delivery)
+ self.settle(delivery, Qpid::Proton::Delivery::REJECTED)
+ end
+
+ # Releases a received message, making it available at the source for any
+ # other interested receiver.
+ #
+ # @param delivery [Qpid::Proton::Delivery] The delivery
+ # @param delivered [Boolean] True if this was considered a delivery
+ # attempt.
+ #
+ def release(delivery, delivered = true)
+ if delivered
+ self.settle(delivery, Qpid::Proton::Delivery::MODIFIED)
+ else
+ self.settle(delivery, Qpid::Proton::Delivery::RELEASED)
+ end
+ end
+
+ # Settles the specified delivery. Updates the delivery state if a state
+ # is specified.
+ #
+ # @param delivery [Qpid::Proton::Delivery] The delivery.
+ # @param state [Fixnum] The delivery state.
+ #
+ def settle(delivery, state = nil)
+ delivery.update(state) unless state.nil?
+ delivery.settle
+ end
+
+ end
+
+end
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/9ff3e048/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
index a4b3391..8db28f3 100644
--- a/proton-c/bindings/ruby/lib/qpid_proton.rb
+++ b/proton-c/bindings/ruby/lib/qpid_proton.rb
@@ -84,6 +84,7 @@ require "messenger/messenger"
# Handler classes
require "handler/c_adaptor"
require "handler/wrapped_handler"
+require "handler/acking"
module Qpid::Proton
# @private
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org
[19/31] qpid-proton git commit: PROTON-781: Added reactor support to
the Ruby Event class.
Posted by mc...@apache.org.
PROTON-781: Added reactor support to the Ruby Event class.
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/1383abf3
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/1383abf3
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/1383abf3
Branch: refs/heads/PROTON-781-ruby-reactor-apis
Commit: 1383abf33d5874c7f482f67734b1c7c4343163f8
Parents: 1573e5b
Author: Darryl L. Pierce <mc...@gmail.com>
Authored: Mon May 18 15:02:18 2015 -0400
Committer: Darryl L. Pierce <mc...@gmail.com>
Committed: Mon Jun 8 13:57:52 2015 -0400
----------------------------------------------------------------------
proton-c/bindings/ruby/lib/event/event.rb | 38 ++++++++++++++++++++------
1 file changed, 30 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/1383abf3/proton-c/bindings/ruby/lib/event/event.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/event/event.rb b/proton-c/bindings/ruby/lib/event/event.rb
index dd5d869..e839f63 100644
--- a/proton-c/bindings/ruby/lib/event/event.rb
+++ b/proton-c/bindings/ruby/lib/event/event.rb
@@ -37,6 +37,13 @@ module Qpid::Proton
# be generated.
NONE = event_type(:PN_EVENT_NONE)
+ # A reactor has been started.
+ REACTOR_INIT = event_type(:PN_REACTOR_INIT)
+ # A reactor has no more events to process.
+ REACTOR_QUIESCED = event_type(:PN_REACTOR_QUIESCED)
+ # A reactor has been stopred.
+ REACTOR_FINAL = event_type(:PN_REACTOR_FINAL)
+
# A timer event has occurred.
TIMER_TASK = event_type(:PN_TIMER_TASK)
@@ -199,17 +206,32 @@ module Qpid::Proton
#
def dispatch(handler, type = nil)
type = @type if type.nil?
- #notify any and all attached handlers
- if handler.respond_to?(:handlers?) && handler.handlers?
- handler.handlers.each {|hndlr| self.dispatch(hndlr, type)}
- end
- if handler.respond_to?(type.method)
- handler.__send__(type.method, self)
- elsif handler.respond_to?(:on_unhandled)
- handler.on_unhandled(self)
+ if handler.is_a?(Qpid::Proton::Handler::WrappedHandler)
+ Cproton.pn_handler_dispatch(handler.impl, @impl, type.number)
+ else
+ result = Qpid::Proton::Event.dispatch(handler, type.method, self)
+ if (result != "DELEGATED") && handler.respond_to?(:handlers)
+ handler.handlers.each do |hndlr|
+ self.dispatch(hndlr)
+ end
+ end
end
end
+ # Returns the reactor for this event.
+ #
+ # @return [Reactor, nil] The reactor.
+ #
+ def reactor
+ impl = Cproton.pn_event_reactor(@impl)
+ Qpid::Proton::Util::ClassWrapper::WRAPPERS["pn_reactor"].call(impl)
+ end
+
+ def container
+ impl = Cproton.pn_event_reactor(@impl)
+ Qpid::Proton::Util::ClassWrapper::WRAPPERS["pn_reactor"].call(impl)
+ end
+
# Returns the transport for this event.
#
# @return [Transport, nil] The transport.
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org
[08/31] qpid-proton git commit: PROTON-781: Added
EndpointStateHandler to the Ruby reactive APIs.
Posted by mc...@apache.org.
PROTON-781: Added EndpointStateHandler to the Ruby reactive APIs.
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/43970df0
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/43970df0
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/43970df0
Branch: refs/heads/PROTON-781-ruby-reactor-apis
Commit: 43970df0cfc68f9acbc5458afffa9230c234885e
Parents: 9ff3e04
Author: Darryl L. Pierce <mc...@gmail.com>
Authored: Wed Feb 25 13:28:38 2015 -0500
Committer: Darryl L. Pierce <mc...@gmail.com>
Committed: Mon Jun 8 13:57:51 2015 -0400
----------------------------------------------------------------------
.../ruby/lib/handler/endpoint_state_handler.rb | 217 +++++++++++++++++++
proton-c/bindings/ruby/lib/qpid_proton.rb | 1 +
2 files changed, 218 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/43970df0/proton-c/bindings/ruby/lib/handler/endpoint_state_handler.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/handler/endpoint_state_handler.rb b/proton-c/bindings/ruby/lib/handler/endpoint_state_handler.rb
new file mode 100644
index 0000000..727a20b
--- /dev/null
+++ b/proton-c/bindings/ruby/lib/handler/endpoint_state_handler.rb
@@ -0,0 +1,217 @@
+#--
+# 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::Handler
+
+ # A utility that exposes endpoint events; i.e., the open/close of a link,
+ # session or connection, in a more intuitive manner.
+ #
+ # A XXX_opened method will be called when both local and remote peers have
+ # opened the link, session or connection. This can be used to confirm a
+ # locally initiated action for example.
+ #
+ # A XXX_opening method will be called when the remote peer has requested
+ # an open that was not initiated locally. By default this will simply open
+ # locally, which then trigtgers the XXX_opened called.
+ #
+ # The same applies to close.
+ #
+ class EndpointStateHandler < Qpid::Proton::BaseHandler
+
+ def initialize(peer_close_is_error = false, delegate = nil)
+ @delegate = delegate
+ @peer_close_is_error = peer_close_is_error
+ end
+
+ def self.print_error(endpoint, endpoint_type)
+ if !endpoint.remote_condition.nil?
+ elsif self.local_endpoint?(endpoint) && endpoint.remote_closed?
+ logging.error("#{endpoint_type} closed by peer")
+ end
+ end
+
+ def on_link_remote_close(event)
+ if !event.link.remote_condition.nil?
+ self.on_link_error(event)
+ elsif event.link.local_closed?
+ self.on_link_closed(event)
+ else
+ self.on_link_closing(event)
+ end
+ event.link.close
+ end
+
+ def on_session_remote_close(event)
+ if !event.session.remote_condition.nil?
+ self.on_session_error(event)
+ elsif event.session.local_closed?
+ self.on_session_closed(event)
+ else
+ self.on_session_closing(event)
+ end
+ event.session.close
+ end
+
+ def on_connection_remote_close(event)
+ if !event.connection.remote_condition.nil?
+ self.on_connection_error(event)
+ elsif event.connection.local_closed?
+ self.on_connection_closed(event)
+ else
+ self.on_connection_closing(event)
+ end
+ event.connection.close
+ end
+
+ def on_connection_local_open(event)
+ self.on_connection_opened(event) if event.connection.remote_active?
+ end
+
+ def on_connection_remote_open(event)
+ if !(event.connection.state & Qpid::Proton::Endpoint::LOCAL_ACTIVE).zero?
+ self.on_connection_opened(event)
+ elsif event.connection.local_uninit?
+ self.on_connection_opening(event)
+ event.connection.open
+ end
+ end
+
+ def on_session_local_open(event)
+ self.on_session_opened(event) if event.session.remote_active?
+ end
+
+ def on_session_remote_open(event)
+ if !(event.session.state & Qpid::Proton::Endpoint::LOCAL_ACTIVE).zero?
+ self.on_session_opened(event)
+ elsif event.session.local_uninit?
+ self.on_session_opening(event)
+ event.session.open
+ end
+ end
+
+ def on_link_local_open(event)
+ self.on_link_opened(event) if event.link.remote_active?
+ end
+
+ def on_link_remote_open(event)
+ if !(event.link.state & Qpid::Proton::Endpoint::LOCAL_ACTIVE).zero?
+ self.on_link_opened(event)
+ elsif event.link.local_uninit?
+ self.on_link_opening(event)
+ event.link.open
+ end
+ end
+
+ def on_connection_opened(event)
+ Qpid::Proton::Event.dispatch(@delegate, :on_session_opened, event) if !@delegate.nil?
+ end
+
+ def on_session_opened(event)
+ Qpid::Proton::Event.dispatch(@delegate, :on_session_opened, event) if !@delegate.nil?
+ end
+
+ def on_link_opened(event)
+ Qpid::Proton::Event.dispatch(@delegate, :on_link_opened, event) if !@delegate.nil?
+ end
+
+ def on_connection_opening(event)
+ Qpid::Proton::Event.dispatch(@delegate, :on_connection_opening, event) if !@delegate.nil?
+ end
+
+ def on_session_opening(event)
+ Qpid::Proton::Event.dispatch(@delegate, :on_session_opening, event) if !@delegate.nil?
+ end
+
+ def on_link_opening(event)
+ Qpid::Proton::Event.dispatch(@delegate, :on_link_opening, event) if !@delegate.nil?
+ end
+
+ def on_connection_error(event)
+ if !@delegate.nil?
+ Qpid::Proton::Event.dispatch(@delegate, :on_connection_error, event)
+ else
+ self.log_error(event.connection, "connection")
+ end
+ end
+
+ def on_session_error(event)
+ if !@delegate.nil?
+ Qpid::Proton::Event.dispatch(@delegate, :on_session_error, event)
+ else
+ self.log_error(event.session, "session")
+ event.connection.close
+ end
+ end
+
+ def on_link_error(event)
+ if !@delegate.nil?
+ Qpid::Proton::Event.dispatch(@delegate, :on_link_error, event)
+ else
+ self.log_error(event.link, "link")
+ event.conneciton.close
+ end
+ end
+
+ def on_connection_closed(event)
+ Qpid::Proton::Event.dispatch(@delegate, :on_connection_closed, event) if !@delegate.nil?
+ end
+
+ def on_session_closed(event)
+ Qpid::Proton::Event.dispatch(@delegate, :on_session_closed, event) if !@delegate.nil?
+ end
+
+ def on_link_closed(event)
+ Qpid::Proton::Event.dispatch(@delegate, :on_link_closed, event) if !@delegate.nil?
+ end
+
+ def on_connection_closing(event)
+ if !@delegate.nil?
+ Qpid::Proton::Event.dispatch(@delegate, :on_connection_closing, event)
+ elsif @peer_close_is_error
+ self.on_connection_error(event)
+ end
+ end
+
+ def on_session_closing(event)
+ if !@delegate.nil?
+ Qpid::Proton::Event.dispatch(@delegate, :on_session_closing, event)
+ elsif @peer_close_is_error
+ self.on_session_error(event)
+ end
+ end
+
+ def on_link_closing(event)
+ if !@delegate.nil?
+ Qpid::Proton::Event.dispatch(@delegate, :on_link_closing, event)
+ elsif @peer_close_is_error
+ self.on_link_error(event)
+ end
+ end
+
+ def on_transport_tail_closed(event)
+ self.on_transport_closed(event)
+ end
+
+ def on_transport_closed(event)
+ Qpid::Proton::Event.dispatch(@delegate, :on_disconnected, event) if !@delegate.nil?
+ end
+
+ end
+
+end
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/43970df0/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
index 8db28f3..08e60b9 100644
--- a/proton-c/bindings/ruby/lib/qpid_proton.rb
+++ b/proton-c/bindings/ruby/lib/qpid_proton.rb
@@ -85,6 +85,7 @@ require "messenger/messenger"
require "handler/c_adaptor"
require "handler/wrapped_handler"
require "handler/acking"
+require "handler/endpoint_state_handler"
module Qpid::Proton
# @private
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org
[15/31] qpid-proton git commit: PROTON-781: Added the Reactor mixin
to the Ruby reactive APIs.
Posted by mc...@apache.org.
PROTON-781: Added the Reactor mixin to the Ruby reactive APIs.
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/5fc194ad
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/5fc194ad
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/5fc194ad
Branch: refs/heads/PROTON-781-ruby-reactor-apis
Commit: 5fc194adfea522fa36031f7648986e271357a7f7
Parents: f69b972
Author: Darryl L. Pierce <mc...@gmail.com>
Authored: Wed Mar 4 16:37:12 2015 -0500
Committer: Darryl L. Pierce <mc...@gmail.com>
Committed: Mon Jun 8 13:57:52 2015 -0400
----------------------------------------------------------------------
proton-c/bindings/ruby/lib/qpid_proton.rb | 1 +
proton-c/bindings/ruby/lib/util/reactor.rb | 32 +++++++++++++++++++++++++
2 files changed, 33 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/5fc194ad/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
index 03f5632..33fe9b6 100644
--- a/proton-c/bindings/ruby/lib/qpid_proton.rb
+++ b/proton-c/bindings/ruby/lib/qpid_proton.rb
@@ -42,6 +42,7 @@ require "util/engine"
require "util/uuid"
require "util/timeout"
require "util/handler"
+require "util/reactor"
# Types
require "types/strings"
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/5fc194ad/proton-c/bindings/ruby/lib/util/reactor.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/util/reactor.rb b/proton-c/bindings/ruby/lib/util/reactor.rb
new file mode 100644
index 0000000..0bcb557
--- /dev/null
+++ b/proton-c/bindings/ruby/lib/util/reactor.rb
@@ -0,0 +1,32 @@
+#--
+# 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
+
+ module Reactor
+
+ def create_session(connection, handler = nil)
+ session = connection.session
+ session.open
+ return session
+ end
+
+ end
+
+end
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org
[16/31] qpid-proton git commit: PROTON-781: Added the URL class to
the Ruby core APIs.
Posted by mc...@apache.org.
PROTON-781: Added the URL class to the Ruby core APIs.
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/5504a7ab
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/5504a7ab
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/5504a7ab
Branch: refs/heads/PROTON-781-ruby-reactor-apis
Commit: 5504a7abca68cd303fc8273b438c5a08d9d1b36e
Parents: 953ba96
Author: Darryl L. Pierce <mc...@gmail.com>
Authored: Wed Mar 4 16:36:39 2015 -0500
Committer: Darryl L. Pierce <mc...@gmail.com>
Committed: Mon Jun 8 13:57:52 2015 -0400
----------------------------------------------------------------------
proton-c/bindings/ruby/lib/core/url.rb | 77 ++++++++++++++++++++++++++
proton-c/bindings/ruby/lib/qpid_proton.rb | 1 +
2 files changed, 78 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/5504a7ab/proton-c/bindings/ruby/lib/core/url.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/core/url.rb b/proton-c/bindings/ruby/lib/core/url.rb
new file mode 100644
index 0000000..a68811a
--- /dev/null
+++ b/proton-c/bindings/ruby/lib/core/url.rb
@@ -0,0 +1,77 @@
+#--
+# 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
+
+ class URL
+
+ attr_reader :scheme
+ attr_reader :username
+ attr_reader :password
+ attr_reader :host
+ attr_reader :port
+ attr_reader :path
+
+ def initialize(url = nil, options = {})
+ options[:defaults] = true
+
+ if url
+ @url = Cproton.pn_url_parse(url)
+ if @url.nil?
+ raise ArgumentError.new("invalid url: #{url}")
+ end
+ else
+ @url = Cproton.pn_url
+ end
+ @scheme = Cproton.pn_url_get_scheme(@url)
+ @username = Cproton.pn_url_get_username(@url)
+ @password = Cproton.pn_url_get_password(@url)
+ @host = Cproton.pn_url_get_host(@url)
+ @port = Cproton.pn_url_get_port(@url)
+ @path = Cproton.pn_url_get_path(@url)
+ defaults
+ end
+
+ def port=(port)
+ if port.nil?
+ Cproton.pn_url_set_port(@url, nil)
+ else
+ Cproton.pn_url_set_port(@url, port)
+ end
+ end
+
+ def port
+ Cproton.pn_url_get_port(@url).to_i
+ end
+
+ def to_s
+ "#{@scheme}://#{@username.nil? ? '' : @username}#{@password.nil? ? '' : '@' + @password + ':'}#{@host}:#{@port}/#{@path}"
+ end
+
+ private
+
+ def defaults
+ @scheme = @scheme || "ampq"
+ @host = @host || "0.0.0.0"
+ @port = @port || 5672
+ end
+
+ end
+
+end
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/5504a7ab/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
index 33fe9b6..11a555f 100644
--- a/proton-c/bindings/ruby/lib/qpid_proton.rb
+++ b/proton-c/bindings/ruby/lib/qpid_proton.rb
@@ -78,6 +78,7 @@ require "core/ssl_details"
require "core/ssl"
require "core/transport"
require "core/base_handler"
+require "core/url"
# Messenger API classes
require "messenger/subscription"
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org
[17/31] qpid-proton git commit: PROTON-781: Added Acceptor to the
Ruby reactive APIs.
Posted by mc...@apache.org.
PROTON-781: Added Acceptor to the Ruby reactive APIs.
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/0f45ba0f
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/0f45ba0f
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/0f45ba0f
Branch: refs/heads/PROTON-781-ruby-reactor-apis
Commit: 0f45ba0f614438720cd16ba53d9e89e017b5779d
Parents: 44d062c
Author: Darryl L. Pierce <mc...@gmail.com>
Authored: Fri Feb 27 10:14:57 2015 -0500
Committer: Darryl L. Pierce <mc...@gmail.com>
Committed: Mon Jun 8 13:57:52 2015 -0400
----------------------------------------------------------------------
proton-c/bindings/ruby/lib/qpid_proton.rb | 1 +
proton-c/bindings/ruby/lib/reactor/acceptor.rb | 41 +++++++++++++++++++++
2 files changed, 42 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/0f45ba0f/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
index f3da844..bffd4d1 100644
--- a/proton-c/bindings/ruby/lib/qpid_proton.rb
+++ b/proton-c/bindings/ruby/lib/qpid_proton.rb
@@ -94,6 +94,7 @@ require "handler/messaging_handler"
# Reactor classes
require "reactor/task"
+require "reactor/acceptor"
module Qpid::Proton
# @private
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/0f45ba0f/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
new file mode 100644
index 0000000..83e0596
--- /dev/null
+++ b/proton-c/bindings/ruby/lib/reactor/acceptor.rb
@@ -0,0 +1,41 @@
+#--
+# 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
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org
[22/31] qpid-proton git commit: PROTON-781: Added the set of
LinkOption classes to Ruby.
Posted by mc...@apache.org.
PROTON-781: Added the set of LinkOption classes to Ruby.
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/3d946127
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/3d946127
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/3d946127
Branch: refs/heads/PROTON-781-ruby-reactor-apis
Commit: 3d94612780d5f299a2eb47cd54ddb488ff1360d4
Parents: 9b30655
Author: Darryl L. Pierce <mc...@gmail.com>
Authored: Mon May 4 13:26:26 2015 -0400
Committer: Darryl L. Pierce <mc...@gmail.com>
Committed: Mon Jun 8 13:57:52 2015 -0400
----------------------------------------------------------------------
proton-c/bindings/ruby/lib/qpid_proton.rb | 1 +
.../bindings/ruby/lib/reactor/link_option.rb | 90 ++++++++++++++++++++
2 files changed, 91 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/3d946127/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
index ba1e66e..1d614a4 100644
--- a/proton-c/bindings/ruby/lib/qpid_proton.rb
+++ b/proton-c/bindings/ruby/lib/qpid_proton.rb
@@ -107,6 +107,7 @@ require "reactor/connector"
require "reactor/backoff"
require "reactor/session_per_connection"
require "reactor/container"
+require "reactor/link_option"
module Qpid::Proton
# @private
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/3d946127/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
new file mode 100644
index 0000000..628a811
--- /dev/null
+++ b/proton-c/bindings/ruby/lib/reactor/link_option.rb
@@ -0,0 +1,90 @@
+#--
+# 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
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org
[24/31] qpid-proton git commit: PROTON-781: Added Container to the
Ruby reactive APIs.
Posted by mc...@apache.org.
PROTON-781: Added Container to the Ruby reactive APIs.
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/b8ba5acb
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/b8ba5acb
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/b8ba5acb
Branch: refs/heads/PROTON-781-ruby-reactor-apis
Commit: b8ba5acb285d8f540dbf2226bb97cb564e8c09ff
Parents: aa8222e
Author: Darryl L. Pierce <mc...@gmail.com>
Authored: Thu Feb 26 10:26:11 2015 -0500
Committer: Darryl L. Pierce <mc...@gmail.com>
Committed: Mon Jun 8 13:57:52 2015 -0400
----------------------------------------------------------------------
proton-c/bindings/ruby/lib/qpid_proton.rb | 1 +
proton-c/bindings/ruby/lib/reactor/container.rb | 272 +++++++++++++++++++
2 files changed, 273 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b8ba5acb/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
index f40c608..ba1e66e 100644
--- a/proton-c/bindings/ruby/lib/qpid_proton.rb
+++ b/proton-c/bindings/ruby/lib/qpid_proton.rb
@@ -106,6 +106,7 @@ require "reactor/urls"
require "reactor/connector"
require "reactor/backoff"
require "reactor/session_per_connection"
+require "reactor/container"
module Qpid::Proton
# @private
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b8ba5acb/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
new file mode 100644
index 0000000..93b49bb
--- /dev/null
+++ b/proton-c/bindings/ruby/lib/reactor/container.rb
@@ -0,0 +1,272 @@
+#--
+# 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
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org
[25/31] qpid-proton git commit: PROTON-781: Added support for
reactors to the Ruby Endpoint class.
Posted by mc...@apache.org.
PROTON-781: Added support for reactors to the Ruby Endpoint class.
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/9b30655f
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/9b30655f
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/9b30655f
Branch: refs/heads/PROTON-781-ruby-reactor-apis
Commit: 9b30655f0dfefdc868989ff429b5d8b4395e6fea
Parents: b8ba5ac
Author: Darryl L. Pierce <mc...@gmail.com>
Authored: Thu Apr 16 10:41:08 2015 -0400
Committer: Darryl L. Pierce <mc...@gmail.com>
Committed: Mon Jun 8 13:57:52 2015 -0400
----------------------------------------------------------------------
proton-c/bindings/ruby/lib/core/endpoint.rb | 25 ++++++++++++++++++++++++
1 file changed, 25 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/9b30655f/proton-c/bindings/ruby/lib/core/endpoint.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/core/endpoint.rb b/proton-c/bindings/ruby/lib/core/endpoint.rb
index cbf1015..f3ddbcb 100644
--- a/proton-c/bindings/ruby/lib/core/endpoint.rb
+++ b/proton-c/bindings/ruby/lib/core/endpoint.rb
@@ -110,6 +110,31 @@ module Qpid::Proton
!(self.state & state_mask).zero?
end
+ def handler
+ reactor = Qpid::Proton::Reactor::Reactor.wrap(Cproton.pn_object_reactor(@impl))
+ if reactor.nil?
+ on_error = nil
+ else
+ on_error = reactor.method(:on_error)
+ end
+ record = self.attachments
+ puts "record=#{record}"
+ WrappedHandler.wrap(Cproton.pn_record_get_handler(record), on_error)
+ end
+
+ def handler=(handler)
+ reactor = Qpid::Proton::Reactor::Reactor.wrap(Cproton.pn_object_reactor(@impl))
+ if reactor.nil?
+ on_error = nil
+ else
+ on_error = reactor.method(:on_error)
+ end
+ impl = chandler(handler, on_error)
+ record = self.attachments
+ Cproton.pn_record_set_handler(record, impl)
+ Cproton.pn_decref(impl)
+ end
+
end
end
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org
[02/31] qpid-proton git commit: PROTON-781: Added the BaseHandler
class to the Ruby reactive APIs.
Posted by mc...@apache.org.
PROTON-781: Added the BaseHandler class to the Ruby reactive APIs.
This is the Ruby analog to the Handler class from Python. It needed to
be renamed, though, since it's in the Qpid::Proton namespace but would
collide with the Qpid::Proton::Handler namespace.
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/31791164
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/31791164
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/31791164
Branch: refs/heads/PROTON-781-ruby-reactor-apis
Commit: 3179116427fcac4c4ff24cbae1e70965b09d955f
Parents: b65cd5e
Author: Darryl L. Pierce <mc...@gmail.com>
Authored: Wed Feb 25 13:30:30 2015 -0500
Committer: Darryl L. Pierce <mc...@gmail.com>
Committed: Mon Jun 8 13:57:51 2015 -0400
----------------------------------------------------------------------
proton-c/bindings/ruby/lib/core/base_handler.rb | 31 ++++++++++++++++++++
proton-c/bindings/ruby/lib/qpid_proton.rb | 1 +
2 files changed, 32 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/31791164/proton-c/bindings/ruby/lib/core/base_handler.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/core/base_handler.rb b/proton-c/bindings/ruby/lib/core/base_handler.rb
new file mode 100644
index 0000000..9a7ece4
--- /dev/null
+++ b/proton-c/bindings/ruby/lib/core/base_handler.rb
@@ -0,0 +1,31 @@
+#--
+# 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
+
+ class BaseHandler
+
+ # Override to process unhandled events.
+ #
+ def on_unhandled(method, *args)
+ end
+
+ end
+
+end
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/31791164/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
index e14ff9d..ef7f300 100644
--- a/proton-c/bindings/ruby/lib/qpid_proton.rb
+++ b/proton-c/bindings/ruby/lib/qpid_proton.rb
@@ -74,6 +74,7 @@ require "core/ssl_domain"
require "core/ssl_details"
require "core/ssl"
require "core/transport"
+require "core/base_handler"
# Messenger API classes
require "messenger/subscription"
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org
[30/31] qpid-proton git commit: PROTON-781: Ruby registry and memory
management testing
Posted by mc...@apache.org.
PROTON-781: Ruby registry and memory management testing
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/81c5cbd1
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/81c5cbd1
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/81c5cbd1
Branch: refs/heads/PROTON-781-ruby-reactor-apis
Commit: 81c5cbd178141c959662a1c776a1df98556a90e0
Parents: 3d94612
Author: Darryl L. Pierce <mc...@gmail.com>
Authored: Fri May 8 10:54:13 2015 -0400
Committer: Darryl L. Pierce <mc...@gmail.com>
Committed: Mon Jun 8 13:57:52 2015 -0400
----------------------------------------------------------------------
examples/ruby/registry_test.rb | 76 +++++++++++++++++++++++++++++++++++++
1 file changed, 76 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/81c5cbd1/examples/ruby/registry_test.rb
----------------------------------------------------------------------
diff --git a/examples/ruby/registry_test.rb b/examples/ruby/registry_test.rb
new file mode 100644
index 0000000..b4b1f6c
--- /dev/null
+++ b/examples/ruby/registry_test.rb
@@ -0,0 +1,76 @@
+#--
+# 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 'qpid_proton'
+require 'weakref'
+
+def show_registry(registry)
+ registry.each_pair do |key, value|
+ registry.delete(key) if value.weakref_alive?
+ end
+ puts "The contents of the registry: size=#{registry.size}"
+end
+
+def show_object_count(clazz)
+ puts "There are #{ObjectSpace.each_object(clazz).count} instances of #{clazz}."
+end
+
+impl = Cproton.pn_transport
+implclazz = impl.class
+transport = Qpid::Proton::Transport.wrap(impl)
+
+puts "Initial setup:"
+show_object_count(Qpid::Proton::Transport)
+show_object_count(implclazz)
+
+transport = nil
+
+show_registry(Qpid::Proton.registry)
+
+ObjectSpace.garbage_collect
+
+puts "After garbage collection:"
+show_object_count(Qpid::Proton::Transport)
+show_object_count(implclazz)
+
+MAXCOUNT=100000
+(1..MAXCOUNT).each do |which|
+ nimpl = Cproton.pn_transport
+ Cproton.pn_incref(nimpl)
+ transport = Qpid::Proton::Transport.wrap(nimpl)
+ transport = Qpid::Proton::Transport.wrap(nimpl)
+end
+
+transport = nil
+
+puts "After creating #{MAXCOUNT} instances"
+show_object_count(Qpid::Proton::Transport)
+show_object_count(implclazz)
+show_registry(Qpid::Proton.registry)
+
+ObjectSpace.garbage_collect
+
+transport = Qpid::Proton::Transport.wrap(impl)
+
+puts "After garbage collection:"
+puts "impl=#{impl}"
+puts "transport=#{transport}"
+show_object_count(Qpid::Proton::Transport)
+show_object_count(implclazz)
+show_registry(Qpid::Proton.registry)
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org
[11/31] qpid-proton git commit: PROTON-781: Added
OutgoingMessageHandler to the Ruby reactive APIs.
Posted by mc...@apache.org.
PROTON-781: Added OutgoingMessageHandler to the Ruby reactive APIs.
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/9eaa62ae
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/9eaa62ae
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/9eaa62ae
Branch: refs/heads/PROTON-781-ruby-reactor-apis
Commit: 9eaa62ae275d619b0332af7da9f95f5298891d10
Parents: 498225e
Author: Darryl L. Pierce <mc...@gmail.com>
Authored: Thu Feb 26 09:59:18 2015 -0500
Committer: Darryl L. Pierce <mc...@gmail.com>
Committed: Mon Jun 8 13:57:51 2015 -0400
----------------------------------------------------------------------
.../lib/handler/outgoing_message_handler.rb | 98 ++++++++++++++++++++
proton-c/bindings/ruby/lib/qpid_proton.rb | 1 +
2 files changed, 99 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/9eaa62ae/proton-c/bindings/ruby/lib/handler/outgoing_message_handler.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/handler/outgoing_message_handler.rb b/proton-c/bindings/ruby/lib/handler/outgoing_message_handler.rb
new file mode 100644
index 0000000..056a131
--- /dev/null
+++ b/proton-c/bindings/ruby/lib/handler/outgoing_message_handler.rb
@@ -0,0 +1,98 @@
+#--
+# 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::Handler
+
+ # A utility for simpler and more intuitive handling of delivery events
+ # related to outgoing messages.
+ #
+ class OutgoingMessageHandler < Qpid::Proton::BaseHandler
+
+ def initialize(auto_settle = true, delegate = nil)
+ @auto_settle = auto_settle
+ @delegate = delegate
+ end
+
+ def on_link_flow(event)
+ self.on_sendable(event) if event.link.sender? && event.link.credit > 0
+ end
+
+ def on_delivery(event)
+ delivery = event.delivery
+ if delivery.link.sender? && delivery.updated?
+ if delivery.remote_accepted?
+ self.on_accepted(event)
+ elsif delivery.remote_rejected?
+ self.on_rejected(event)
+ elsif delivery.remote_released? || delivery.remote_modified?
+ self.on_released(event)
+ end
+ self.on_settled(event) if delivery.settled?
+ delivery.settle if @auto_settle
+ end
+ end
+
+ # Called when the sender link has credit and messages and be transferred.
+ #
+ # @param event [Qpid::Proton::Event::Event] The event.
+ #
+ def on_sendable(event)
+ Qpid::Proton::Event.dispatch(@delegate, :on_sendable, event) if !@delegate.nil?
+ end
+
+ # Called when the remote peer accepts a sent message.
+ #
+ # @param event [Qpid::Proton::Event::Event] The event.
+ #
+ def on_accepted(event)
+ Qpid::Proton::Event.dispatch(@delegate, :on_accepted, event) if !@delegate.nil?
+ end
+
+ # Called when the remote peer rejects a sent message.
+ #
+ # @param event [Qpid::Proton::Event::Event] The event.
+ #
+ def on_rejected(event)
+ Qpid::Proton::Event.dispatch(@delegate, :on_rejected, event) if !@delegate.nil?
+ end
+
+ # Called when the remote peer releases an outgoing message.
+ #
+ # Note that this may be in resposnse to either the REELAASE or MODIFIED
+ # state as defined by the AMQP specification.
+ #
+ # @param event [Qpid::Proton::Event::Event] The event.
+ #
+ def on_released(event)
+ Qpid::Proton::Event.dispatch(@delegate, :on_released, event) if !@delegate.nil?
+ end
+
+ # Called when the remote peer has settled the outgoing message.
+ #
+ # This is the point at which it should never be retransmitted.
+ #
+ # @param event [Qpid::Proton::Event::Event] The event.
+ #
+ def on_settled(event)
+ Qpid::Proton::Event.dispatch(@delegate, :on_settled, event) if !@delegate.nil?
+ end
+
+ end
+
+end
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/9eaa62ae/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
index 1fbf710..5c2e1bc 100644
--- a/proton-c/bindings/ruby/lib/qpid_proton.rb
+++ b/proton-c/bindings/ruby/lib/qpid_proton.rb
@@ -88,6 +88,7 @@ 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"
module Qpid::Proton
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org
[26/31] qpid-proton git commit: PROTON-781: Added URLs to the Ruby
reactive APIs.
Posted by mc...@apache.org.
PROTON-781: Added URLs to the Ruby reactive APIs.
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/4c09ae23
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/4c09ae23
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/4c09ae23
Branch: refs/heads/PROTON-781-ruby-reactor-apis
Commit: 4c09ae236bd0238a2444cd0237d7b001621a1c34
Parents: 5504a7a
Author: Darryl L. Pierce <mc...@gmail.com>
Authored: Wed Mar 4 16:38:04 2015 -0500
Committer: Darryl L. Pierce <mc...@gmail.com>
Committed: Mon Jun 8 13:57:52 2015 -0400
----------------------------------------------------------------------
proton-c/bindings/ruby/lib/qpid_proton.rb | 1 +
proton-c/bindings/ruby/lib/reactor/urls.rb | 40 +++++++++++++++++++++++++
2 files changed, 41 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/4c09ae23/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
index 11a555f..4f017e1 100644
--- a/proton-c/bindings/ruby/lib/qpid_proton.rb
+++ b/proton-c/bindings/ruby/lib/qpid_proton.rb
@@ -102,6 +102,7 @@ require "reactor/acceptor"
require "reactor/reactor"
require "reactor/ssl_config"
require "reactor/global_overrides"
+require "reactor/urls"
module Qpid::Proton
# @private
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/4c09ae23/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
new file mode 100644
index 0000000..8cdb16c
--- /dev/null
+++ b/proton-c/bindings/ruby/lib/reactor/urls.rb
@@ -0,0 +1,40 @@
+#--
+# 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
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org
[27/31] qpid-proton git commit: PROTON-781: Added SSLConfig to the
Ruby reactive APIs.
Posted by mc...@apache.org.
PROTON-781: Added SSLConfig to the Ruby reactive APIs.
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/cb84a677
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/cb84a677
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/cb84a677
Branch: refs/heads/PROTON-781-ruby-reactor-apis
Commit: cb84a677606a3265c73ec9ae07f3c96e964aa143
Parents: 1383abf
Author: Darryl L. Pierce <mc...@gmail.com>
Authored: Thu Feb 26 11:28:04 2015 -0500
Committer: Darryl L. Pierce <mc...@gmail.com>
Committed: Mon Jun 8 13:57:52 2015 -0400
----------------------------------------------------------------------
proton-c/bindings/ruby/lib/qpid_proton.rb | 1 +
.../bindings/ruby/lib/reactor/ssl_config.rb | 41 ++++++++++++++++++++
2 files changed, 42 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/cb84a677/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
index f8703e7..d8783bc 100644
--- a/proton-c/bindings/ruby/lib/qpid_proton.rb
+++ b/proton-c/bindings/ruby/lib/qpid_proton.rb
@@ -96,6 +96,7 @@ require "handler/messaging_handler"
require "reactor/task"
require "reactor/acceptor"
require "reactor/reactor"
+require "reactor/ssl_config"
module Qpid::Proton
# @private
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/cb84a677/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
new file mode 100644
index 0000000..56fec71
--- /dev/null
+++ b/proton-c/bindings/ruby/lib/reactor/ssl_config.rb
@@ -0,0 +1,41 @@
+#--
+# 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
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org
[03/31] qpid-proton git commit: PROTON-781: Refactored the Ruby
Selectable class.
Posted by mc...@apache.org.
PROTON-781: Refactored the Ruby Selectable class.
It now more closely matches the Python version.
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/340a9da7
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/340a9da7
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/340a9da7
Branch: refs/heads/PROTON-781-ruby-reactor-apis
Commit: 340a9da719f1fcea1298d0dc71f40b4e641925a8
Parents: 9e8583c
Author: Darryl L. Pierce <mc...@gmail.com>
Authored: Thu Jun 4 13:56:49 2015 -0400
Committer: Darryl L. Pierce <mc...@gmail.com>
Committed: Mon Jun 8 13:57:51 2015 -0400
----------------------------------------------------------------------
proton-c/bindings/ruby/lib/core/selectable.rb | 124 +++++++++++----------
1 file changed, 68 insertions(+), 56 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/340a9da7/proton-c/bindings/ruby/lib/core/selectable.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/core/selectable.rb b/proton-c/bindings/ruby/lib/core/selectable.rb
index 8a5b223..0ae2efe 100644
--- a/proton-c/bindings/ruby/lib/core/selectable.rb
+++ b/proton-c/bindings/ruby/lib/core/selectable.rb
@@ -25,13 +25,11 @@ module Qpid::Proton
# @private
class Selectable
+ # @private
+ include Util::SwigHelper
- def initialize(messenger, impl) # :nodoc:
- @messenger = messenger
- @impl = impl
- @io = nil
- @freed = false
- end
+ # @private
+ PROTON_METHOD_PREFIX = "pn_selectable"
# Returns the underlying file descriptor.
#
@@ -41,76 +39,90 @@ module Qpid::Proton
Cproton.pn_selectable_get_fd(@impl)
end
- def to_io
- @io ||= IO.new(fileno)
- end
+ proton_reader :reading, :is_or_get => :is
- # The number of bytes the selectable is capable of consuming.
- #
- #def capacity
- # Cproton.pn_selectable_capacity(@impl)
- #end
+ proton_reader :writing, :is_or_get => :is
- # The number of bytes waiting to be written to the file descriptor.
- #
- def pending
- Cproton.pn_selectable_pending(@impl)
- end
+ proton_caller :readable
- # The future expiry time at which control will be returned to the
- # selectable.
- #
- def deadline
- tstamp = Cproton.pn_selectable_deadline(@impl)
- tstamp.nil? ? nil : tstamp / 1000
- end
+ proton_caller :writable
- def readable
- Cproton.pn_selectable_readable(@impl)
- end
+ proton_caller :expired
- def writable
- Cproton.pn_selectable_writable(@impl)
- end
+ proton_accessor :registered, :is_or_get => :is
- def expired?
- Cproton.pn_selectable_expired(@impl)
- end
+ proton_accessor :terminal, :is_or_get => :is
- def registered=(registered)
- Cproton.pn_selectable_set_registered(@impl, registered)
+ proton_caller :terminate
+
+ proton_caller :release
+
+ # @private
+ def self.wrap(impl)
+ return nil if impl.nil?
+
+ self.fetch_instance(impl, :pn_selectable_attachments) || Selectable.new(impl)
end
- def registered?
- Cproton.pn_selectable_is_registered(@impl)
+ # @private
+ include Util::Wrapper
+
+ # @private
+ def initialize(impl)
+ @impl = impl
+ self.class.store_instance(self, :pn_selectable_attachments)
end
- def terminal?
- return true if @impl.nil?
- Cproton.pn_selectable_is_terminal(@impl)
+ private
+
+ DEFAULT = Object.new
+
+ public
+
+ def fileno(fd = DEFAULT)
+ if fd == DEFAULT
+ Cproton.pn_selectable_get_fd(@impl)
+ elsif fd.nil?
+ Cproton.pn_selectable_set_fd(@impl, Cproton::PN_INVALID_SOCKET)
+ else
+ Cproton.pn_selectable_set_fd(@impl, fd)
+ end
end
- def to_s
- "fileno=#{self.fileno} registered=#{self.registered?} terminal=#{self.terminal?}"
+ def reading=(reading)
+ if reading.nil?
+ reading = false
+ elsif reading == "0"
+ reading = false
+ else
+ reading = true
+ end
+ Cproton.pn_selectable_set_reading(@impl, reading ? true : false)
end
- def free
- return if @freed
- @freed = true
- @messenger.unregister_selectable(fileno)
- @io.close unless @io.nil?
- Cproton.pn_selectable_free(@impl)
- @impl = nil
+ def writing=(writing)
+ if writing.nil?
+ writing = false
+ elsif writing == "0"
+ writing = false
+ else
+ writing = true
+ end
+ Cproton.pn_selectable_set_writing(@impl, writing ? true : false)
end
- def freed? # :nodoc:
- @freed
+ def deadline
+ tstamp = Cproton.pn_selectable_get_deadline(@impl)
+ return nil if tstamp.nil?
+ mills_to_sec(tstamp)
end
- private
+ def deadline=(deadline)
+ Cproton.pn_selectable_set_deadline(sec_to_millis(deadline))
+ end
- def check_is_initialized
- raise RuntimeError.new("selectable freed") if @impl.nil?
+ def to_io
+ @io ||= IO.new(fileno)
end
end
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org
[31/31] qpid-proton git commit: PROTON-781: Reactive Ruby examples
Posted by mc...@apache.org.
PROTON-781: Reactive Ruby examples
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/f63454c5
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/f63454c5
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/f63454c5
Branch: refs/heads/PROTON-781-ruby-reactor-apis
Commit: f63454c5caac0124f600793a96d9c560c15fa22f
Parents: 81c5cbd
Author: Darryl L. Pierce <mc...@gmail.com>
Authored: Tue May 26 15:34:11 2015 -0400
Committer: Darryl L. Pierce <mc...@gmail.com>
Committed: Mon Jun 8 13:59:49 2015 -0400
----------------------------------------------------------------------
examples/ruby/lib/debugging.rb | 26 +++
examples/ruby/lib/send_and_receive.rb | 90 +++++++++++
examples/ruby/reactor/README.md | 103 ++++++++++++
examples/ruby/reactor/broker.rb | 200 ++++++++++++++++++++++++
examples/ruby/reactor/client.rb | 68 ++++++++
examples/ruby/reactor/direct_recv.rb | 60 +++++++
examples/ruby/reactor/direct_send.rb | 59 +++++++
examples/ruby/reactor/helloworld.rb | 69 ++++++++
examples/ruby/reactor/helloworld_direct.rb | 74 +++++++++
examples/ruby/reactor/server.rb | 64 ++++++++
examples/ruby/reactor/simple_recv.rb | 58 +++++++
examples/ruby/reactor/simple_send.rb | 55 +++++++
12 files changed, 926 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f63454c5/examples/ruby/lib/debugging.rb
----------------------------------------------------------------------
diff --git a/examples/ruby/lib/debugging.rb b/examples/ruby/lib/debugging.rb
new file mode 100644
index 0000000..5065d51
--- /dev/null
+++ b/examples/ruby/lib/debugging.rb
@@ -0,0 +1,26 @@
+#--
+# 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 Debugging
+
+ def debug(text)
+ print "[#{Time.now.strftime('%s')}] #{text}\n"
+ end
+
+end
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f63454c5/examples/ruby/lib/send_and_receive.rb
----------------------------------------------------------------------
diff --git a/examples/ruby/lib/send_and_receive.rb b/examples/ruby/lib/send_and_receive.rb
new file mode 100644
index 0000000..9fd7417
--- /dev/null
+++ b/examples/ruby/lib/send_and_receive.rb
@@ -0,0 +1,90 @@
+#--
+# 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.
+#++
+
+class ExampleSend < Qpid::Proton::Handler::MessagingHandler
+
+ attr_reader :url
+
+ def initialize(url, expected)
+ super()
+ @url = url
+ @sent = 0
+ @confirmed = 0
+ @expected = expected
+ end
+
+ def on_sendable(event)
+ while event.sender.credit > 0 && @sent < @expected
+ msg = Qpid::Proton::Message.new
+ msg.body = "sequence #{@sent}"
+ msg.id = @sent
+ event.sender.send(msg)
+ @sent = @sent + 1
+ end
+ end
+
+ def on_accepted(event)
+ @confirmed = @confirmed + 1
+ if self.finished?
+ puts "#{@expected > 1 ? 'All ' : ''}#{@expected} message#{@expected > 1 ? 's' : ''} confirmed!"
+ event.connection.close
+ end
+ end
+
+ def on_disconnected(event)
+ @sent = @confirmed
+ end
+
+ def finished?
+ @confirmed == @expected
+ end
+
+end
+
+class ExampleReceive < Qpid::Proton::Handler::MessagingHandler
+
+ attr_reader :url
+
+ def initialize(url, expected)
+ super()
+ @url = url
+ @expected = expected
+ @received = 0
+ end
+
+ def on_message(event)
+ if event.message.id.nil? || event.message.id < @received
+ puts "Missing or old message id: id=#{event.message.id}"
+ return
+ end
+ if @expected.zero? || (@received < @expected)
+ puts "Received: #{event.message.body}"
+ @received = @received + 1
+ if finished?
+ event.receiver.close
+ event.connection.close
+ end
+ end
+ end
+
+ def finished?
+ @received == @expected
+ end
+
+end
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f63454c5/examples/ruby/reactor/README.md
----------------------------------------------------------------------
diff --git a/examples/ruby/reactor/README.md b/examples/ruby/reactor/README.md
new file mode 100644
index 0000000..38cc6ba
--- /dev/null
+++ b/examples/ruby/reactor/README.md
@@ -0,0 +1,103 @@
+## What Is The Reactor?
+
+A little outside of the scope of this document, but the reactor is an event source for letting an application know about events in the Proton messaging system. With this set of APIs an application can be register handlers that are notified when a connection is created, a message received, or a session closes.
+
+### Handlers
+
+An application creates **handlers**, objects which provide methods through which the reactor notifies the application's components of events and allows them each to handle the ones in which they are interested (see the Chain Of Responsibility design pattern for more on this idea). There are some pre-defined handlers for responding to incoming message events, outgoing message events, data flow and managing the AMQP endpoints. Look in the **Qpid::Proton::Handlers** package for more details on these classes.
+
+## Simple Reactor Examples
+
+### The Broker
+
+The reactor examples come with a sample broker which can be used by other examples and which also works as an example itself. For now we'll just start up the broker example and tell it to listen on port 8888:
+
+````
+$ ruby ../examples/ruby/reactor/broker.rb --address=0.0.0.0:8888
+Listening on 0.0.0.0:8888
+````
+
+This example broker will receive messages, create queues as needed, and deliver messages to endpoints.
+
+### Hello World Using A Broker
+
+Our first example creates an endpoint that sends messages to a queue to which it is subscribed. So it both sends and receives its message in one pass.
+
+To start it, simply run:
+
+```
+$ ruby ../examples/ruby/reactor/helloworld.rb --address=0.0.0.0:8888 --queue=examples
+Hello world!
+```
+
+As you can see, the classic message was output by the example. Now let's take a look at what's going on under the covers.
+
+#### Events When Talking To A Broker
+
+The following events occur while **helloworld.rb** runs:
+
+ * **on_start** - Fired when the application is started.
+ * **on_sendable** - Fired when a message can be sent.
+ * **on_message** - Fired when a message is received.
+
+### Hello World Without A Broker required
+
+The next example we'll look at will send the classic "Hello world" message to itself directly. This example shows some very fundamental elements of the reactor APIs that you should understand.
+
+To launch the example:
+
+```
+ $ ruby helloworld_direct.rb --address=0.0.0.0:8888/examples
+ Hello world!
+```
+
+Not very different from the example that uses the broker, which is what we'd expect from the outside. But let's take a look inside of the example and see how it's different at that level
+
+The direct version takes on the responsibility for listening to incoming connections as well as making an outgoing connection. So we see the following additional events occurring:
+
+ * **on_accepted** - Fired when a message is received.
+ * **on_connection_closed** - Fired when an endpoint closes its connection.
+
+## More Complex Reactor Examples
+
+Now that we've covered the basics with the archetypical hello world app, let's look at some more interesting examples.
+
+There are four example applications that demonstrate how to send and receive messages both directly and through an intermediary, such as a broker:
+
+ * **simple_send.rb** - sends messages to a receiver at a specific address and receives responses via an intermediary,
+ * **simple_recv.rb** - receives messages from via an intermediary,
+ * **direct_send.rb** - sends messages directly to a receiver and listens for responses itself, and
+ * **direct_recv.rb** - receives messages directly.
+
+ Simple send and direct send may, at first, seem to be so similar that you wonder why they're not just the same applciation. And I know for me I was wonder as I wrote the list above why there were two examples. The reason is that **simple_send.rb** uses the intermediary transfer responses to the messages it sends, while **direct_send.rb** uses an *Acceptor* to listen for an process responses.
+
+ You can use the examples in the follow ways:
+
+ ```
+ simple_send.rb -> broker <- simple_recv.rb
+ simple_send.rb -> direct_recv.rb
+ direct_send.rb -> simple_recv.rb
+ ```
+
+In this set of examples we see the following event occurring, in addition to what we've seen before:
+
+ * **on_disconnected** - Fired when the transport is closed.
+
+## Now About That Broker example
+
+The **broker.rb** example application is a nice demonstration of doing something more interesting in Ruby with Proton.
+
+The way the broker works is to listen to incoming connections, examine the components of the address for that connection, attach that connection to an exchange managing that address and then it sends any messages destined for that address to them.
+
+The components of the broker example include:
+ * **Broker** - A class that extends the MessagingHandler class. It accepts incoming connections, manages subscribing them to exchanges, and transfers messages between them.
+ * **Exchange** - A class that represents a message queue, tracking what endpoints are subscribed to it.
+
+The Broker manages a map connecting a queue address to the instance of Exchange that holds references to the endpoints of interest.
+
+The broker application demonstrates a new set of reactor events:
+
+ * **on_link_opening** - Fired when a remote link is opened but the local end is not yet open. From this event the broker grabs the address and subscribes the link to an exchange for that address.
+ * **on_link_closing** - Fired when a remote link is closed but the local end is still open. From this event the broker grabs the address and unsubscribes the link from that exchange.
+ * **on_connection_closing** - Fired when a remote connection is closed but the local end is still open.
+ * **on_disconnected** - Fired when the protocol transport has closed. The broker removes all links for the disconnected connection, avoiding workign with endpoints that are now gone.
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f63454c5/examples/ruby/reactor/broker.rb
----------------------------------------------------------------------
diff --git a/examples/ruby/reactor/broker.rb b/examples/ruby/reactor/broker.rb
new file mode 100644
index 0000000..9d7e5be
--- /dev/null
+++ b/examples/ruby/reactor/broker.rb
@@ -0,0 +1,200 @@
+#--
+# 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 'qpid_proton'
+require 'optparse'
+require 'pathname'
+
+require_relative '../lib/debugging'
+
+class Exchange
+
+ include Debugging
+
+ def initialize(dynamic = false)
+ @dynamic = dynamic
+ @queue = Queue.new
+ @consumers = []
+ end
+
+ def subscribe(consumer)
+ debug("subscribing #{consumer}") if $options[:debug]
+ @consumers << (consumer)
+ debug(" there are #{@consumers.size} consumers") if $options[:debug]
+ end
+
+ def unsubscribe(consumer)
+ debug("unsubscribing #{consumer}") if $options[:debug]
+ if @consumers.include?(consumer)
+ @consumers.delete(consumer)
+ else
+ debug(" consumer doesn't exist") if $options[:debug]
+ end
+ debug(" there are #{@consumers.size} consumers") if $options[:debug]
+ @consumers.empty? && (@dynamic || @queue.empty?)
+ end
+
+ def publish(message)
+ debug("queueing message: #{message.body}") if $options[:debug]
+ @queue << message
+ self.dispatch
+ end
+
+ def dispatch(consumer = nil)
+ debug("dispatching: consumer=#{consumer}") if $options[:debug]
+ if consumer
+ c = [consumer]
+ else
+ c = @consumers
+ end
+
+ while self.deliver_to(c) do
+ end
+ end
+
+ def deliver_to(consumers)
+ debug("delivering to #{consumers.size} consumer(s)") if $options[:debug]
+ result = false
+ consumers.each do |consumer|
+ debug(" current consumer=#{consumer} credit=#{consumer.credit}") if $options[:debug]
+ if consumer.credit > 0 && !@queue.empty?
+ consumer.send(@queue.pop(true))
+ result = true
+ end
+ end
+ return result
+ end
+
+end
+
+class Broker < Qpid::Proton::Handler::MessagingHandler
+
+ include Debugging
+
+ def initialize(url)
+ super()
+ @url = url
+ @queues = {}
+ end
+
+ def on_start(event)
+ debug("on_start event") if $options[:debug]
+ @acceptor = event.container.listen(@url)
+ print "Listening on #{@url}\n"
+ end
+
+ def queue(address)
+ debug("fetching queue for #{address}: (there are #{@queues.size} queues)") if $options[:debug]
+ unless @queues.has_key?(address)
+ debug(" creating new queue") if $options[:debug]
+ @queues[address] = Exchange.new
+ else
+ debug(" using existing queue") if $options[:debug]
+ end
+ result = @queues[address]
+ debug(" returning #{result}") if $options[:debug]
+ return result
+ end
+
+ def on_link_opening(event)
+ debug("processing on_link_opening") if $options[:debug]
+ debug("link is#{event.link.sender? ? '' : ' not'} a sender") if $options[:debug]
+ if event.link.sender?
+ if event.link.remote_source.dynamic?
+ address = generate_uuid
+ event.link.source.address = address
+ q = Exchange.new(true)
+ @queues[address] = q
+ q.subscribe(event.link)
+ elsif event.link.remote_source.address
+ event.link.source.address = event.link.remote_source.address
+ self.queue(event.link.source.address).subscribe(event.link)
+ end
+ elsif event.link.remote_target.address
+ event.link.target.address = event.link.remote_target.address
+ end
+ end
+
+ def unsubscribe(link)
+ debug("unsubscribing #{link.address}") if $options[:debug]
+ if @queues.has_key?(link.source.address)
+ if @queues[link.source.address].unsubscribe(link)
+ @queues.delete(link.source.address)
+ end
+ end
+ end
+
+ def on_link_closing(event)
+ self.unsubscribe(event.link) if event.link.sender?
+ end
+
+ def on_connection_closing(event)
+ self.remove_stale_consumers(event.connection)
+ end
+
+ def on_disconnected(event)
+ self.remove_stale_consumers(event.connection)
+ end
+
+ def remove_stale_consumers(connection)
+ l = connection.link_head(Qpid::Proton::Endpoint::REMOTE_ACTIVE)
+ while !l.nil?
+ self.unsubscribe(l) if l.sender?
+ l = l.next(Qpid::Proton::Endpoint::REMOTE_ACTIVE)
+ end
+ end
+
+ def on_sendable(event)
+ debug("on_sendable event") if $options[:debug]
+ q = self.queue(event.link.source.address)
+ debug(" dispatching #{event.message} to #{q}") if $options[:debug]
+ q.dispatch(event.link)
+ end
+
+ def on_message(event)
+ debug("on_message event") if $options[:debug]
+ q = self.queue(event.link.target.address)
+ debug(" dispatching #{event.message} to #{q}") if $options[:debug]
+ q.publish(event.message)
+ end
+
+end
+
+$options = {
+ :address => "localhost:5672",
+ :debug => false
+}
+
+OptionParser.new do |opts|
+ opts.banner = "Usage: #{Pathname.new(__FILE__).basename} [$options]"
+
+ opts.on("-a", "--address=ADDRESS", "Send messages to ADDRESS (def. #{$options[:address]}).") do |address|
+ $options[:address] = address
+ end
+
+ opts.on("-d", "--debug", "Enable debugging output (def. #{$options[:debug]})") do
+ $options[:debug] = true
+ end
+
+end.parse!
+
+begin
+ Qpid::Proton::Reactor::Container.new(Broker.new($options[:address])).run
+rescue Interrupt
+end
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f63454c5/examples/ruby/reactor/client.rb
----------------------------------------------------------------------
diff --git a/examples/ruby/reactor/client.rb b/examples/ruby/reactor/client.rb
new file mode 100644
index 0000000..8bb58da
--- /dev/null
+++ b/examples/ruby/reactor/client.rb
@@ -0,0 +1,68 @@
+#--
+# 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 'qpid_proton'
+
+class Client < Qpid::Proton::Handler::MessagingHandler
+
+ def initialize(url, requests)
+ super()
+ @url = url
+ @requests = requests
+ end
+
+ def on_start(event)
+ @sender = event.container.create_sender(@url)
+ @receiver = event.container.create_receiver(@sender.connection, :dynamic => true)
+ end
+
+ def next_request
+ if @receiver.remote_source.address
+ req = Qpid::Proton::Message.new
+ req.reply_to = @receiver.remote_source.address
+ req.body = @requests.first
+ puts "-> #{req.body}"
+ @sender.send(req)
+ end
+ end
+
+ def on_link_opened(event)
+ if event.receiver == @receiver
+ next_request
+ end
+ end
+
+ def on_message(event)
+ puts "<- #{event.message.body}"
+ @requests.delete_at(0)
+ if !@requests.empty?
+ next_request
+ else
+ event.connection.close
+ end
+ end
+
+end
+
+REQUESTS = ["Twas brillig, and the slithy toves",
+ "Did gire and gymble in the wabe.",
+ "All mimsy were the borogroves,",
+ "And the mome raths outgrabe."]
+
+Qpid::Proton::Reactor::Container.new(Client.new("0.0.0.0:5672/examples", REQUESTS)).run
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f63454c5/examples/ruby/reactor/direct_recv.rb
----------------------------------------------------------------------
diff --git a/examples/ruby/reactor/direct_recv.rb b/examples/ruby/reactor/direct_recv.rb
new file mode 100644
index 0000000..2e19b04
--- /dev/null
+++ b/examples/ruby/reactor/direct_recv.rb
@@ -0,0 +1,60 @@
+#--
+# 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 'qpid_proton'
+require 'optparse'
+
+require_relative '../lib/send_and_receive'
+
+class DirectReceive < ExampleReceive
+
+ def initialize(url, expected)
+ super
+ end
+
+ def on_start(event)
+ @acceptor = event.container.listen(self.url)
+ end
+
+ def on_message(event)
+ super(event)
+ @acceptor.close if self.finished?
+ end
+
+end
+
+options = {
+ :address => "localhost:5672/examples",
+ :messages => 100,
+}
+
+OptionParser.new do |opts|
+ opts.banner = "Usage: simple_send.rb [options]"
+
+ opts.on("-a", "--address=ADDRESS", "Send messages to ADDRESS (def. #{options[:address]}).") do |address|
+ options[:address] = address
+ end
+
+ opts.on("-m", "--messages=COUNT", "The number of messages to send (def. #{options[:messages]}",
+ OptionParser::DecimalInteger) do |messages|
+ options[:messages] = messages
+ end
+end.parse!
+
+Qpid::Proton::Reactor::Container.new(DirectReceive.new(options[:address], options[:messages])).run
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f63454c5/examples/ruby/reactor/direct_send.rb
----------------------------------------------------------------------
diff --git a/examples/ruby/reactor/direct_send.rb b/examples/ruby/reactor/direct_send.rb
new file mode 100644
index 0000000..22ce7de
--- /dev/null
+++ b/examples/ruby/reactor/direct_send.rb
@@ -0,0 +1,59 @@
+#--
+# 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 'qpid_proton'
+require 'optparse'
+
+require_relative '../lib/send_and_receive'
+
+options = {
+ :address => "localhost:5672/examples",
+ :messages => 100,
+}
+
+class SimpleSend < ExampleSend
+
+ def initialize(url, messages)
+ super(url, messages)
+ end
+
+ def on_start(event)
+ @acceptor = event.container.listen(url)
+ end
+
+end
+
+OptionParser.new do |opts|
+ opts.banner = "Usage: simple_send.rb [options]"
+
+ opts.on("-a", "--address=ADDRESS", "Send messages to ADDRESS (def. #{options[:address]}).") do |address|
+ options[:address] = address
+ end
+
+ opts.on("-m", "--messages=COUNT", "The number of messages to send (def. #{options[:messages]}",
+ OptionParser::DecimalInteger) do |messages|
+ options[:messages] = messages
+ end
+end.parse!
+
+begin
+ Qpid::Proton::Reactor::Container.new(SimpleSend.new(options[:address], options[:messages])).run
+rescue Interrupt => error
+ puts "ERROR: #{error}"
+end
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f63454c5/examples/ruby/reactor/helloworld.rb
----------------------------------------------------------------------
diff --git a/examples/ruby/reactor/helloworld.rb b/examples/ruby/reactor/helloworld.rb
new file mode 100644
index 0000000..03eb561
--- /dev/null
+++ b/examples/ruby/reactor/helloworld.rb
@@ -0,0 +1,69 @@
+#--
+# 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 'qpid_proton'
+require 'optparse'
+
+class HelloWorld < Qpid::Proton::Handler::MessagingHandler
+
+ def initialize(server, address)
+ super()
+ @server = server
+ @address = address
+ end
+
+ def on_start(event)
+ conn = event.container.connect(:address => @server)
+ event.container.create_sender(conn, :target => @address)
+ event.container.create_receiver(conn, :source => @address)
+ end
+
+ def on_sendable(event)
+ msg = Qpid::Proton::Message.new
+ msg.body = "Hello world!"
+ event.sender.send(msg)
+ event.sender.close
+ end
+
+ def on_message(event)
+ puts event.message.body
+ event.connection.close
+ end
+end
+
+options = {
+ :address => "localhost:5672",
+ :queue => "examples"
+}
+
+OptionParser.new do |opts|
+ opts.banner = "Usage: helloworld_direct.rb [options]"
+
+ opts.on("-a", "--address=ADDRESS", "Send messages to ADDRESS (def. #{options[:address]}).") do |address|
+ options[:address] = address
+ end
+
+ opts.on("-q", "--queue=QUEUE", "Send messages to QUEUE (def. #{options[:queue]})") do |queue|
+ options[:queue] = queue
+ end
+
+end.parse!
+
+hw = HelloWorld.new(options[:address], "examples")
+Qpid::Proton::Reactor::Container.new(hw).run
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f63454c5/examples/ruby/reactor/helloworld_direct.rb
----------------------------------------------------------------------
diff --git a/examples/ruby/reactor/helloworld_direct.rb b/examples/ruby/reactor/helloworld_direct.rb
new file mode 100644
index 0000000..e98cc1f
--- /dev/null
+++ b/examples/ruby/reactor/helloworld_direct.rb
@@ -0,0 +1,74 @@
+#--
+# 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 'qpid_proton'
+require 'optparse'
+
+options = {
+ :address => "localhost:5672/examples",
+}
+
+class HelloWorldDirect < Qpid::Proton::Handler::MessagingHandler
+
+ include Qpid::Proton::Util::Wrapper
+
+ def initialize(url)
+ super()
+ @url = url
+ end
+
+ def on_start(event)
+ @acceptor = event.container.listen(@url)
+ event.container.create_sender(@url)
+ end
+
+ def on_sendable(event)
+ msg = Qpid::Proton::Message.new
+ msg.body = "Hello world!"
+ event.sender.send(msg)
+ event.sender.close
+ end
+
+ def on_message(event)
+ puts "#{event.message.body}"
+ end
+
+ def on_accepted(event)
+ event.connection.close
+ end
+
+ def on_connection_closed(event)
+ @acceptor.close
+ end
+
+end
+
+OptionParser.new do |opts|
+ opts.banner = "Usage: helloworld_direct.rb [options]"
+
+ opts.on("-a", "--address=ADDRESS", "Send messages to ADDRESS (def. #{options[:address]}).") do |address|
+ options[:address] = address
+ end
+
+end.parse!
+
+begin
+ Qpid::Proton::Reactor::Container.new(HelloWorldDirect.new(options[:address])).run
+rescue Interrupt => error
+end
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f63454c5/examples/ruby/reactor/server.rb
----------------------------------------------------------------------
diff --git a/examples/ruby/reactor/server.rb b/examples/ruby/reactor/server.rb
new file mode 100644
index 0000000..e149dba
--- /dev/null
+++ b/examples/ruby/reactor/server.rb
@@ -0,0 +1,64 @@
+#--
+# 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 'qpid_proton'
+
+class Server < Qpid::Proton::Handler::MessagingHandler
+
+ def initialize(url, address)
+ super()
+ @url = url
+ @address = address
+ @senders = {}
+ end
+
+ def on_start(event)
+ puts "Listening on #{@url}"
+ @container = event.container
+ @conn = @container.connect(:address => @url)
+ @receiver = @container.create_receiver(@conn, :source => @address)
+ @relay = nil
+ end
+
+ def on_connection_opened(event)
+ if event.connection.remote_offered_capabilities &&
+ event.connection.remote_offered_capabilities.contain?("ANONYMOUS-RELAY")
+ @relay = @container.create_sender(@conn, nil)
+ end
+ end
+
+ def on_message(event)
+ msg = event.message
+ puts "<- #{msg.body}"
+ sender = @relay || @senders[msg.reply_to]
+ if sender.nil?
+ sender = @container.create_sender(@conn, :target => msg.reply_to)
+ @senders[msg.reply_to] = sender
+ end
+ reply = Qpid::Proton::Message.new
+ reply.address = msg.reply_to
+ reply.body = msg.body.upcase
+ puts "-> #{reply.body}"
+ reply.correlation_id = msg.correlation_id
+ sender.send(reply)
+ end
+
+end
+
+Qpid::Proton::Reactor::Container.new(Server.new("0.0.0.0:5672", "examples")).run()
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f63454c5/examples/ruby/reactor/simple_recv.rb
----------------------------------------------------------------------
diff --git a/examples/ruby/reactor/simple_recv.rb b/examples/ruby/reactor/simple_recv.rb
new file mode 100644
index 0000000..55a37ee
--- /dev/null
+++ b/examples/ruby/reactor/simple_recv.rb
@@ -0,0 +1,58 @@
+#--
+# 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 'qpid_proton'
+require 'optparse'
+
+require_relative '../lib/send_and_receive'
+
+class Receiver < ExampleReceive
+
+ def initialize(url, count)
+ super(url, count)
+ end
+
+ def on_start(event)
+ event.container.create_receiver(@url)
+ end
+
+end
+
+options = {
+ :address => "localhost:5672/examples",
+ :messages => 100,
+}
+
+OptionParser.new do |opts|
+ opts.banner = "Usage: simple_send.rb [options]"
+
+ opts.on("-a", "--address=ADDRESS", "Send messages to ADDRESS (def. #{options[:address]}).") do |address|
+ options[:address] = address
+ end
+
+ opts.on("-m", "--messages=COUNT", "The number of messages to send (def. #{options[:messages]}",
+ OptionParser::DecimalInteger) do |messages|
+ options[:messages] = messages
+ end
+end.parse!
+
+begin
+ Qpid::Proton::Reactor::Container.new(Receiver.new(options[:address], options[:messages])).run
+rescue Interrupt
+end
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f63454c5/examples/ruby/reactor/simple_send.rb
----------------------------------------------------------------------
diff --git a/examples/ruby/reactor/simple_send.rb b/examples/ruby/reactor/simple_send.rb
new file mode 100644
index 0000000..1dd4150
--- /dev/null
+++ b/examples/ruby/reactor/simple_send.rb
@@ -0,0 +1,55 @@
+#--
+# 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 'qpid_proton'
+require 'optparse'
+
+require_relative '../lib/send_and_receive'
+
+options = {
+ :address => "localhost:5672/examples",
+ :messages => 100,
+}
+
+class SimpleSend < ExampleSend
+
+ def initialize(url, messages)
+ super(url, messages)
+ end
+
+ def on_start(event)
+ event.container.create_sender(url)
+ end
+
+end
+
+OptionParser.new do |opts|
+ opts.banner = "Usage: simple_send.rb [options]"
+
+ opts.on("-a", "--address=ADDRESS", "Send messages to ADDRESS (def. #{options[:address]}).") do |address|
+ options[:address] = address
+ end
+
+ opts.on("-m", "--messages=COUNT", "The number of messages to send (def. #{options[:messages]}",
+ OptionParser::DecimalInteger) do |messages|
+ options[:messages] = messages
+ end
+end.parse!
+
+Qpid::Proton::Reactor::Container.new(SimpleSend.new(options[:address], options[:messages])).run
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org
[23/31] qpid-proton git commit: PROTON-781: Added
SessionPerConnection to the Ruby reactive APIs.
Posted by mc...@apache.org.
PROTON-781: Added SessionPerConnection to the Ruby reactive APIs.
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/aa8222e0
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/aa8222e0
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/aa8222e0
Branch: refs/heads/PROTON-781-ruby-reactor-apis
Commit: aa8222e093c2035b9d21042d1fb58c85bec643a8
Parents: ca7f8f9
Author: Darryl L. Pierce <mc...@gmail.com>
Authored: Wed Mar 4 16:40:01 2015 -0500
Committer: Darryl L. Pierce <mc...@gmail.com>
Committed: Mon Jun 8 13:57:52 2015 -0400
----------------------------------------------------------------------
proton-c/bindings/ruby/lib/qpid_proton.rb | 1 +
.../ruby/lib/reactor/session_per_connection.rb | 45 ++++++++++++++++++++
2 files changed, 46 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/aa8222e0/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
index 661927e..f40c608 100644
--- a/proton-c/bindings/ruby/lib/qpid_proton.rb
+++ b/proton-c/bindings/ruby/lib/qpid_proton.rb
@@ -105,6 +105,7 @@ require "reactor/global_overrides"
require "reactor/urls"
require "reactor/connector"
require "reactor/backoff"
+require "reactor/session_per_connection"
module Qpid::Proton
# @private
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/aa8222e0/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
new file mode 100644
index 0000000..f8180c0
--- /dev/null
+++ b/proton-c/bindings/ruby/lib/reactor/session_per_connection.rb
@@ -0,0 +1,45 @@
+#--
+# 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
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org
[21/31] qpid-proton git commit: PROTON-781: Added the Handler mixin
to the Ruby reactive APIs.
Posted by mc...@apache.org.
PROTON-781: Added the Handler mixin to the Ruby reactive APIs.
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/f69b9727
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/f69b9727
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/f69b9727
Branch: refs/heads/PROTON-781-ruby-reactor-apis
Commit: f69b9727f85768c07a46cd3759cc3c7bb342472c
Parents: 5b72338
Author: Darryl L. Pierce <mc...@gmail.com>
Authored: Wed Mar 4 08:06:19 2015 -0500
Committer: Darryl L. Pierce <mc...@gmail.com>
Committed: Mon Jun 8 13:57:52 2015 -0400
----------------------------------------------------------------------
proton-c/bindings/ruby/lib/qpid_proton.rb | 1 +
proton-c/bindings/ruby/lib/util/handler.rb | 41 +++++++++++++++++++++++++
2 files changed, 42 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f69b9727/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
index 0c84f20..03f5632 100644
--- a/proton-c/bindings/ruby/lib/qpid_proton.rb
+++ b/proton-c/bindings/ruby/lib/qpid_proton.rb
@@ -41,6 +41,7 @@ require "util/class_wrapper"
require "util/engine"
require "util/uuid"
require "util/timeout"
+require "util/handler"
# Types
require "types/strings"
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f69b9727/proton-c/bindings/ruby/lib/util/handler.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/util/handler.rb b/proton-c/bindings/ruby/lib/util/handler.rb
new file mode 100644
index 0000000..e7d07b1
--- /dev/null
+++ b/proton-c/bindings/ruby/lib/util/handler.rb
@@ -0,0 +1,41 @@
+#--
+# 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 Handler
+
+ def chandler(handler, on_error)
+ return nil if handler.nil?
+
+ if handler.instance_of?(Qpid::Proton::Handler::WrappedHandler)
+ impl = handler.impl
+ Cproton.pn_incref(impl)
+ return impl
+ else
+ cadaptor = Qpid::Proton::Handler::CAdaptor.new(handler, on_error)
+ rbhandler = Cproton.pn_rbhandler(cadaptor)
+ return rbhandler
+ end
+ end
+
+ end
+
+end
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org