qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mcpie...@apache.org
Subject [44/50] qpid-proton git commit: PROTON-781: Added Connector to the Ruby reactive APIs.
Date Thu, 18 Jun 2015 14:03:51 GMT
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/566a8e57
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/566a8e57
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/566a8e57

Branch: refs/heads/PROTON-781-ruby-reactor-apis
Commit: 566a8e577727aa08d3257b802f91bd3a931bc590
Parents: 56f461f
Author: Darryl L. Pierce <mcpierce@gmail.com>
Authored: Wed Mar 4 16:38:47 2015 -0500
Committer: Darryl L. Pierce <mcpierce@gmail.com>
Committed: Thu Jun 18 09:27:21 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/566a8e57/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/566a8e57/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


Mime
View raw message