[DRE-commits] [SCM] ruby-stomp.git branch, master, updated. debian/1.2.5-1-1-gc7c43ae

Jonas Genannt jonas at brachium-system.net
Mon Oct 8 15:47:44 UTC 2012


The following commit has been merged in the master branch:
commit c7c43aeed3a41edc399a55c260b8424ebe2e8ed7
Author: Jonas Genannt <jonas at brachium-system.net>
Date:   Mon Oct 8 17:37:02 2012 +0200

    Adding upstream version 1.2.6.

diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc
index ccd4b68..d23b0c5 100644
--- a/CHANGELOG.rdoc
+++ b/CHANGELOG.rdoc
@@ -1,3 +1,11 @@
+== 1.2.6 20120913
+
+* Provide ability to eliminate checks for closed in protocol methods
+* Cover ssl.connect with connection timeout parameter
+* If heartbeat send raises, do not reraise unless client requests that
+* Remove methods that invoke __send__
+* Move internal methods to 'private'
+
 == 1.2.5 20120804
 
 * Issue #48 any forks with modifications will be affected!
diff --git a/README.rdoc b/README.rdoc
index e7d2bb5..1212d30 100644
--- a/README.rdoc
+++ b/README.rdoc
@@ -10,6 +10,7 @@ An implementation of the Stomp protocol for Ruby. See:
 
 ===New
 
+* Gem version 1.2.6. Miscellaneous fixes and changes. See _CHANGELOG.rdoc_ for details.
 * Gem version 1.2.5. Restructure. Forks with modifcations will be affected. See _CHANGELOG.rdoc_ for details.
 * Gem version 1.2.4. Stomp 1.1 heartbeat fix, autoflush capability, miscellaneous fixes.
 * Gem version 1.2.3. Miscellaneous fixes, see changelog for details.
@@ -23,23 +24,26 @@ See _CHANGELOG.rdoc_ for details.
 
   hash = {
       :hosts => [
+        # First connect is to remotehost1
         {:login => "login1", :passcode => "passcode1", :host => "remotehost1", :port => 61612, :ssl => true},
+        # First failover connect is to remotehost2
         {:login => "login2", :passcode => "passcode2", :host => "remotehost2", :port => 61613, :ssl => false},
         
       ],
-      # These are the default parameters, don't need to be set
-      :reliable => true, # true for hash login
-      :initial_reconnect_delay => 0.01,
-      :max_reconnect_delay => 30.0,
-      :use_exponential_back_off => true,
-      :back_off_multiplier => 2,
-      :max_reconnect_attempts => 0,
-      :randomize => false,
-      :backup => false,
-      :timeout => -1,
-      :connect_headers => {},
-      :parse_timeout => 5,
-      :logger => nil,
+      # These are the default parameters and do not need to be set
+      :reliable => true,                  # reliable (use failover)
+      :initial_reconnect_delay => 0.01,   # initial delay before reconnect (secs)
+      :max_reconnect_delay => 30.0,       # max delay before reconnect
+      :use_exponential_back_off => true,  # increase delay between reconnect attpempts
+      :back_off_multiplier => 2,          # next delay multiplier
+      :max_reconnect_attempts => 0,       # retry forever, use # for maximum attempts
+      :randomize => false,                # do not radomize hosts hash before reconnect
+      :connect_headers => {},             # user supplied CONNECT headers (req'd for Stomp 1.1+)
+      :parse_timeout => 5,                # receive / read timeout, secs
+      :logger => nil,                     # user suplied callback logger instance
+      :dmh => false,                      # do not support multihomed IPV4 / IPV6 hosts during failover
+      :closed_check => true,              # check first if closed in each protocol method
+      :hbser => false,                    # raise on heartbeat send exception
     }
     
     # for client
@@ -101,8 +105,8 @@ The following people have contributed to Stomp:
 * jstrachan 
 * Marius Mathiesen <marius.mathiesen at gmail.com>
 * Johan S√∏rensen <johan at johansorensen.com>
-* Thiago Morello <stompgem at gmail.com>
-* Guy M. Allard
+* Thiago Morello
+* Guy M. Allard <stompgem at gmail.com>
 * kookster
 * Tony Garnock-Jones <tonyg at lshift.net>
 * chirino
diff --git a/lib/client/utils.rb b/lib/client/utils.rb
index 149beda..9807a04 100644
--- a/lib/client/utils.rb
+++ b/lib/client/utils.rb
@@ -56,7 +56,6 @@ module Stomp
     end
 
     # A very basic check of required arguments.
-    # *NOTE* This method will be made private in the next release.
     def check_arguments!()
       raise ArgumentError if @host.nil? || @host.empty?
       raise ArgumentError if @port.nil? || @port == '' || @port < 1 || @port > 65535
@@ -72,8 +71,7 @@ module Stomp
       new_options[:back_off_multiplier] = (options["backOffMultiplier"] || 2 ).to_i
       new_options[:max_reconnect_attempts] = (options["maxReconnectAttempts"] || 0 ).to_i
       new_options[:randomize] = options["randomize"] == "true" # Default: false
-      new_options[:backup] = false # Not implemented yet: I'm using a master X slave solution
-      new_options[:timeout] = -1 # Not implemented yet: a "timeout(5) do ... end" would do the trick, feel free
+      new_options[:connect_timeout] = 0
 
       new_options
     end
@@ -108,9 +106,11 @@ module Stomp
               listener.call(message)
             end
           end
-        end
+        end # while true
       end
-    end
-  end
-end
+    end # method start_listeners
+
+  end # class Client
+
+end # module Stomp
 
diff --git a/lib/connection/heartbeats.rb b/lib/connection/heartbeats.rb
index de862c2..dbd2c86 100644
--- a/lib/connection/heartbeats.rb
+++ b/lib/connection/heartbeats.rb
@@ -25,7 +25,7 @@ module Stomp
       # Init.
 
       #
-      @cx = @cy = @sx = @sy = 0, # Variable names as in spec
+      @cx = @cy = @sx = @sy = 0   # Variable names as in spec
 
       #
       @hbsend_interval = @hbrecv_interval = 0.0 # Send/Receive ticker interval.
@@ -60,13 +60,13 @@ module Stomp
 
       # See if we are doing anything at all.
 
-      #
       @hbs = @hbr = true # Sending/Receiving heartbeats. Assume yes at first.
       # Check if sending is possible.
-      @hbs = false if @cx == 0 || @sy == 0
+      @hbs = false if @cx == 0 || @sy == 0  # Reset if neither side wants
       # Check if receiving is possible.
-      @hbr = false if @sx == 0 || @cy == 0
-      # Should not do heartbeats at all
+      @hbr = false if @sx == 0 || @cy == 0  # Reset if neither side wants
+
+      # Check if we should not do heartbeats at all
       return if (!@hbs && !@hbr)
 
       # If sending
@@ -115,7 +115,9 @@ module Stomp
                   @logger.on_hbwrite_fail(log_params, {"ticker_interval" => @hbsend_interval,
                   "exception" => sendex})
                 end
-                raise # Re-raise.  What else could be done here?
+                if @hbser
+                  raise # Re-raise if user requested this, otherwise ignore
+                end
               end
             end
           end
@@ -167,7 +169,7 @@ module Stomp
       }
     end
 
-  end # class
+  end # class Connection
 
-end # module
+end # module Stomp
 
diff --git a/lib/connection/netio.rb b/lib/connection/netio.rb
index 20761a5..967cb4e 100644
--- a/lib/connection/netio.rb
+++ b/lib/connection/netio.rb
@@ -244,11 +244,11 @@ module Stomp
 
         Timeout::timeout(@connect_timeout, Stomp::Error::SocketOpenTimeout) do
           ssl = OpenSSL::SSL::SSLSocket.new(open_tcp_socket, ctx)
+          ssl.connect
         end
         def ssl.ready?
           ! @rbuffer.empty? || @io.ready?
         end
-        ssl.connect
         if @ssl != true
           # Pass back results if possible
           if RUBY_VERSION =~ /1\.8\.[56]/
@@ -316,7 +316,7 @@ module Stomp
       @subscriptions.each { |k,v| _transmit(used_socket, Stomp::CMD_SUBSCRIBE, v) }
     end
 
-  end # class
+  end # class Connection
 
-end # module
+end # module Stomp
 
diff --git a/lib/connection/utf8.rb b/lib/connection/utf8.rb
index d304147..92e5e89 100644
--- a/lib/connection/utf8.rb
+++ b/lib/connection/utf8.rb
@@ -288,7 +288,7 @@ module Stomp
       dh
     end
 
-  end # class
+  end # class Connection
 
-end # module
+end # module Stomp
 
diff --git a/lib/connection/utils.rb b/lib/connection/utils.rb
index 8bc211c..51290da 100644
--- a/lib/connection/utils.rb
+++ b/lib/connection/utils.rb
@@ -79,7 +79,7 @@ module Stomp
       _validate_hbheader()
     end
 
-    # _post_connect handles low level logic just post a physical connect.
+    # _post_connect handles low level logic just after a physical connect.
     def _post_connect()
       return unless (@connect_headers[:"accept-version"] && @connect_headers[:host])
       return if @connection_frame.command == Stomp::CMD_ERROR
@@ -98,7 +98,136 @@ module Stomp
       _init_heartbeats()
     end
 
-  end # class
+    # socket creates and returns a new socket for use by the connection.
+    def socket()
+      @socket_semaphore.synchronize do
+        used_socket = @socket
+        used_socket = nil if closed?
 
-end # module
+        while used_socket.nil? || !@failure.nil?
+          @failure = nil
+          begin
+            used_socket = open_socket()
+            # Open is complete
+            connect(used_socket)
+            if @logger && @logger.respond_to?(:on_connected)
+              @logger.on_connected(log_params)
+            end
+            @connection_attempts = 0
+          rescue
+            @failure = $!
+            used_socket = nil
+            raise unless @reliable
+            raise if @failure.is_a?(Stomp::Error::LoggerConnectionError)
+            @closed = true
+            if @logger && @logger.respond_to?(:on_connectfail)
+              # on_connectfail may raise
+              begin
+                @logger.on_connectfail(log_params)
+              rescue Exception => aex
+                raise if aex.is_a?(Stomp::Error::LoggerConnectionError)
+              end
+            else
+              $stderr.print "connect to #{@host} failed: #{$!} will retry(##{@connection_attempts}) in #{@reconnect_delay}\n"
+            end
+            raise Stomp::Error::MaxReconnectAttempts if max_reconnect_attempts?
+
+            sleep(@reconnect_delay)
+
+            @connection_attempts += 1
+
+            if @parameters
+              change_host()
+              increase_reconnect_delay()
+            end
+          end
+        end
+        @socket = used_socket
+      end
+    end
+
+    # refine_params sets up defaults for a Hash initialize.
+    def refine_params(params)
+      params = params.uncamelize_and_symbolize_keys
+      default_params = {
+        :connect_headers => {},
+        :reliable => true,
+        # Failover parameters
+        :initial_reconnect_delay => 0.01,
+        :max_reconnect_delay => 30.0,
+        :use_exponential_back_off => true,
+        :back_off_multiplier => 2,
+        :max_reconnect_attempts => 0,
+        :randomize => false,
+        :connect_timeout => 0,
+        # Parse Timeout
+        :parse_timeout => 5,
+        :dmh => false,
+        # Closed check logic
+        :closed_check => true,
+        :hbser => false,
+      }
+
+      res_params = default_params.merge(params)
+      if res_params[:dmh]
+        res_params = _expand_hosts(res_params)
+      end
+      return res_params
+    end
+
+    # change_host selects the next host for retires.
+    def change_host
+      @parameters[:hosts] = @parameters[:hosts].sort_by { rand } if @parameters[:randomize]
+
+      # Set first as master and send it to the end of array
+      current_host = @parameters[:hosts].shift
+      @parameters[:hosts] << current_host
+
+      @ssl = current_host[:ssl]
+      @host = current_host[:host]
+      @port = current_host[:port] || Connection::default_port(@ssl)
+      @login = current_host[:login] || ""
+      @passcode = current_host[:passcode] || ""
+
+    end
+
+    # max_reconnect_attempts? returns nil or the number of maximum reconnect
+    # attempts.
+    def max_reconnect_attempts?
+      !(@parameters.nil? || @parameters[:max_reconnect_attempts].nil?) && @parameters[:max_reconnect_attempts] != 0 && @connection_attempts >= @parameters[:max_reconnect_attempts]
+    end
+
+    # increase_reconnect_delay increases the reconnect delay for the next connection
+    # attempt.
+    def increase_reconnect_delay
+
+      @reconnect_delay *= @parameters[:back_off_multiplier] if @parameters[:use_exponential_back_off]
+      @reconnect_delay = @parameters[:max_reconnect_delay] if @reconnect_delay > @parameters[:max_reconnect_delay]
+
+      @reconnect_delay
+    end
+
+    # __old_receive receives a frame, blocks until the frame is received.
+    def __old_receive()
+      # The receive may fail so we may need to retry.
+      while TRUE
+        begin
+          used_socket = socket
+          return _receive(used_socket)
+        rescue
+          @failure = $!
+          raise unless @reliable
+          errstr = "receive failed: #{$!}"
+          if @logger && @logger.respond_to?(:on_miscerr)
+            @logger.on_miscerr(log_params, errstr)
+          else
+            $stderr.print errstr
+          end
+        end
+      end
+    end
+
+  end # class Connection
+
+end # module Stomp
 
diff --git a/lib/stomp/client.rb b/lib/stomp/client.rb
index 14bd9a7..3e497d3 100644
--- a/lib/stomp/client.rb
+++ b/lib/stomp/client.rb
@@ -48,7 +48,6 @@ module Stomp
     #     :back_off_multiplier => 2,
     #     :max_reconnect_attempts => 0,
     #     :randomize => false,
-    #     :backup => false,
     #     :connect_timeout => 0,
     #     :connect_headers => {},
     #     :parse_timeout => 5,
@@ -141,7 +140,7 @@ module Stomp
 
     end
 
-    # open is syntactic sugar for 'Client.new' See 'initialize' for usage.
+    # open is syntactic sugar for 'Client.new', see 'initialize' for usage.
     def self.open(login = '', passcode = '', host = 'localhost', port = 61613, reliable = false)
       Client.new(login, passcode, host, port, reliable)
     end
@@ -161,7 +160,7 @@ module Stomp
     def abort(name, headers = {})
       @connection.abort(name, headers)
 
-      # lets replay any ack'd messages in this transaction
+      # replay any ack'd messages in this transaction
       replay_list = @replay_messages_by_txn[name]
       if replay_list
         replay_list.each do |message|
@@ -243,13 +242,6 @@ module Stomp
       @connection.publish(destination, message, headers)
     end
 
-    # :TODO: This should not be used.  Currently only referenced in the 
-    # spec tests.
-    # *NOTE* This will be removed in the next release.
-    def obj_send(*args)
-      __send__(*args)
-    end
-
     # Return the broker's CONNECTED frame to the client.  Misnamed.
     def connection_frame()
       @connection.connection_frame
diff --git a/lib/stomp/connection.rb b/lib/stomp/connection.rb
index fe01678..a4d5cff 100644
--- a/lib/stomp/connection.rb
+++ b/lib/stomp/connection.rb
@@ -42,7 +42,7 @@ module Stomp
 
     # A new Connection object can be initialized using two forms:
     #
-    # Hash (this is the recommended Connection initialization method:
+    # Hash (this is the recommended Connection initialization method):
     #
     #   hash = {
     #     :hosts => [
@@ -56,11 +56,13 @@ module Stomp
     #     :back_off_multiplier => 2,
     #     :max_reconnect_attempts => 0,
     #     :randomize => false,
-    #     :backup => false,
     #     :connect_timeout => 0,
     #     :connect_headers => {},
     #     :parse_timeout => 5,
     #     :logger => nil,
+    #     :dmh => false,
+    #     :closed_check => true,
+    #     :hbser => false,
     #   }
     #
     #   e.g. c = Stomp::Connection.new(hash)
@@ -77,11 +79,10 @@ module Stomp
     #   e.g. c = Stomp::Connection.new("username", "password", "localhost", 61613, true)
     #
     def initialize(login = '', passcode = '', host = 'localhost', port = 61613, reliable = false, reconnect_delay = 5, connect_headers = {})
-      @received_messages = []
       @protocol = Stomp::SPL_10 # Assumed at first
-      @hb_received = true # Assumed at first
-      @hb_sent = true # Assumed at first
-      @hbs = @hbr = false # Sending/Receiving heartbeats. Assume no for now.
+      @hb_received = true       # Assumed at first
+      @hb_sent = true           # Assumed at first
+      @hbs = @hbr = false       # Sending/Receiving heartbeats. Assume no for now.
 
       if login.is_a?(Hash)
         hashed_initialize(login)
@@ -99,11 +100,13 @@ module Stomp
         @connect_timeout = 0	# To override, use hashed parameters
         @logger = nil     		# To override, use hashed parameters
         @autoflush = false    # To override, use hashed parameters or setter
+        @closed_check = true  # Run closed check in each protocol method
+        @hbser = false        # Raise if heartbeat send exception
         warn "login looks like a URL, do you have the correct parameters?" if @login =~ /:\/\//
       end
 
-      # Use Mutexes:  only one lock per each thread
-      # Revert to original implementation attempt
+      # Use Mutexes:  only one lock per each thread.
+      # Reverted to original implementation attempt using Mutex.
       @transmit_semaphore = Mutex.new
       @read_semaphore = Mutex.new
       @socket_semaphore = Mutex.new
@@ -127,128 +130,17 @@ module Stomp
       @connect_timeout =  @parameters[:connect_timeout]
       @logger =  @parameters[:logger]
       @autoflush = @parameters[:autoflush]
+      @closed_check = @parameters[:closed_check]
+      @hbser = @parameters[:hbser]
       #sets the first host to connect
       change_host
     end
 
-    # open is syntactic sugar for 'Connection.new' See 'initialize' for usage.
+    # open is syntactic sugar for 'Connection.new', see 'initialize' for usage.
     def Connection.open(login = '', passcode = '', host = 'localhost', port = 61613, reliable = false, reconnect_delay = 5, connect_headers = {})
       Connection.new(login, passcode, host, port, reliable, reconnect_delay, connect_headers)
     end
 
-    # socket creates and returns a new socket for use by the connection.
-    # *NOTE* this method will be made private in the next realease.
-    def socket()
-      @socket_semaphore.synchronize do
-        used_socket = @socket
-        used_socket = nil if closed?
-
-        while used_socket.nil? || !@failure.nil?
-          @failure = nil
-          begin
-            used_socket = open_socket()
-            # Open complete
-
-            connect(used_socket)
-            if @logger && @logger.respond_to?(:on_connected)
-              @logger.on_connected(log_params)
-            end
-            @connection_attempts = 0
-          rescue
-            @failure = $!
-            used_socket = nil
-            raise unless @reliable
-            raise if @failure.is_a?(Stomp::Error::LoggerConnectionError)
-            @closed = true
-            if @logger && @logger.respond_to?(:on_connectfail)
-              # on_connectfail may raise
-              begin
-                @logger.on_connectfail(log_params)
-              rescue Exception => aex
-                raise if aex.is_a?(Stomp::Error::LoggerConnectionError)
-              end
-            else
-              $stderr.print "connect to #{@host} failed: #{$!} will retry(##{@connection_attempts}) in #{@reconnect_delay}\n"
-            end
-            raise Stomp::Error::MaxReconnectAttempts if max_reconnect_attempts?
-
-            sleep(@reconnect_delay)
-
-            @connection_attempts += 1
-
-            if @parameters
-              change_host()
-              increase_reconnect_delay()
-            end
-          end
-        end
-        @socket = used_socket
-      end
-    end
-
-    # refine_params sets up defaults for a Hash initialize.
-    # *NOTE* This method will be made private in the next release.
-    def refine_params(params)
-      params = params.uncamelize_and_symbolize_keys
-      default_params = {
-        :connect_headers => {},
-        :reliable => true,
-        # Failover parameters
-        :initial_reconnect_delay => 0.01,
-        :max_reconnect_delay => 30.0,
-        :use_exponential_back_off => true,
-        :back_off_multiplier => 2,
-        :max_reconnect_attempts => 0,
-        :randomize => false,
-        :backup => false,
-        :connect_timeout => 0,
-        # Parse Timeout
-        :parse_timeout => 5,
-        :dmh => false,
-      }
-
-      res_params = default_params.merge(params)
-      if res_params[:dmh]
-        res_params = _expand_hosts(res_params)
-      end
-      return res_params
-    end
-
-    # change_host selects the next host for retires.
-    # *NOTE* This method will be made private in the next release.
-    def change_host
-      @parameters[:hosts] = @parameters[:hosts].sort_by { rand } if @parameters[:randomize]
-
-      # Set first as master and send it to the end of array
-      current_host = @parameters[:hosts].shift
-      @parameters[:hosts] << current_host
-
-      @ssl = current_host[:ssl]
-      @host = current_host[:host]
-      @port = current_host[:port] || Connection::default_port(@ssl)
-      @login = current_host[:login] || ""
-      @passcode = current_host[:passcode] || ""
-
-    end
-
-    # max_reconnect_attempts? returns nil or the number of maximum reconnect
-    # attempts.
-    # *NOTE* This method will be made private in the next release.
-    def max_reconnect_attempts?
-      !(@parameters.nil? || @parameters[:max_reconnect_attempts].nil?) && @parameters[:max_reconnect_attempts] != 0 && @connection_attempts >= @parameters[:max_reconnect_attempts]
-    end
-
-    # increase_reconnect_delay increases the reconnect delay for the next connection
-    # attempt.
-    # *NOTE* This method will be made private in the next release.
-    def increase_reconnect_delay
-
-      @reconnect_delay *= @parameters[:back_off_multiplier] if @parameters[:use_exponential_back_off]
-      @reconnect_delay = @parameters[:max_reconnect_delay] if @reconnect_delay > @parameters[:max_reconnect_delay]
-
-      @reconnect_delay
-    end
-
     # open? tests if this connection is open.
     def open?
       !@closed
@@ -261,7 +153,7 @@ module Stomp
 
     # Begin starts a transaction, and requires a name for the transaction
     def begin(name, headers = {})
-      raise Stomp::Error::NoCurrentConnection if closed?
+      raise Stomp::Error::NoCurrentConnection if @closed_check && closed?
       headers = headers.symbolize_keys
       headers[:transaction] = name
       _headerCheck(headers)
@@ -272,7 +164,7 @@ module Stomp
     # client acknowledgement i.e. connection.subscribe("/queue/a", :ack => 'client').
     # Accepts a transaction header ( :transaction => 'some_transaction_id' )
     def ack(message_id, headers = {})
-      raise Stomp::Error::NoCurrentConnection if closed?
+      raise Stomp::Error::NoCurrentConnection if @closed_check && closed?
       raise Stomp::Error::MessageIDRequiredError if message_id.nil? || message_id == ""
       headers = headers.symbolize_keys
       headers[:'message-id'] = message_id
@@ -285,7 +177,7 @@ module Stomp
 
     # STOMP 1.1+ NACK.
     def nack(message_id, headers = {})
-      raise Stomp::Error::NoCurrentConnection if closed?
+      raise Stomp::Error::NoCurrentConnection if @closed_check && closed?
       raise Stomp::Error::UnsupportedProtocolError if @protocol == Stomp::SPL_10
       raise Stomp::Error::MessageIDRequiredError if message_id.nil? || message_id == ""
       headers = headers.symbolize_keys
@@ -297,7 +189,7 @@ module Stomp
 
     # Commit commits a transaction by name.
     def commit(name, headers = {})
-      raise Stomp::Error::NoCurrentConnection if closed?
+      raise Stomp::Error::NoCurrentConnection if @closed_check && closed?
       headers = headers.symbolize_keys
       headers[:transaction] = name
       _headerCheck(headers)
@@ -306,7 +198,7 @@ module Stomp
 
     # Abort aborts a transaction by name.
     def abort(name, headers = {})
-      raise Stomp::Error::NoCurrentConnection if closed?
+      raise Stomp::Error::NoCurrentConnection if @closed_check && closed?
       headers = headers.symbolize_keys
       headers[:transaction] = name
       _headerCheck(headers)
@@ -314,9 +206,9 @@ module Stomp
     end
 
     # Subscribe subscribes to a destination.  A subscription name is required.
-    # For Stomp 1.1 a session unique subscription ID is required.
+    # For Stomp 1.1+ a session unique subscription ID is also required.
     def subscribe(name, headers = {}, subId = nil)
-      raise Stomp::Error::NoCurrentConnection if closed?
+      raise Stomp::Error::NoCurrentConnection if @closed_check && closed?
       headers = headers.symbolize_keys
       headers[:destination] = name
       if @protocol >= Stomp::SPL_11
@@ -328,7 +220,7 @@ module Stomp
         @logger.on_subscribe(log_params, headers)
       end
 
-      # Store the sub so that we can replay if we reconnect.
+      # Store the subscription so that we can replay if we reconnect.
       if @reliable
         subId = name if subId.nil?
         raise Stomp::Error::DuplicateSubscription if @subscriptions[subId]
@@ -339,9 +231,9 @@ module Stomp
     end
 
     # Unsubscribe from a destination.   A subscription name is required.
-    # For Stomp 1.1 a session unique subscription ID is required.
+    # For Stomp 1.1+ a session unique subscription ID is also required.
     def unsubscribe(dest, headers = {}, subId = nil)
-      raise Stomp::Error::NoCurrentConnection if closed?
+      raise Stomp::Error::NoCurrentConnection if @closed_check && closed?
       headers = headers.symbolize_keys
       headers[:destination] = dest
       if @protocol >= Stomp::SPL_11
@@ -359,7 +251,7 @@ module Stomp
     # To disable content length header use header ( :suppress_content_length => true ).
     # Accepts a transaction header ( :transaction => 'some_transaction_id' ).
     def publish(destination, message, headers = {})
-      raise Stomp::Error::NoCurrentConnection if closed?
+      raise Stomp::Error::NoCurrentConnection if @closed_check && closed?
       headers = headers.symbolize_keys
       headers[:destination] = destination
       _headerCheck(headers)
@@ -369,18 +261,12 @@ module Stomp
       transmit(Stomp::CMD_SEND, headers, message)
     end
 
-    # :TODO: Remove this method.
-    # *NOTE* This method will be removed in the next release.
-    def obj_send(*args)
-      __send__(*args)
-    end
-
     # Send a message back to the source or to the dead letter queue.
     # Accepts a dead letter queue option ( :dead_letter_queue => "/queue/DLQ" ).
     # Accepts a limit number of redeliveries option ( :max_redeliveries => 6 ).
     # Accepts a force client acknowledgement option (:force_client_ack => true).
     def unreceive(message, options = {})
-      raise Stomp::Error::NoCurrentConnection if closed?
+      raise Stomp::Error::NoCurrentConnection if @closed_check && closed?
       options = { :dead_letter_queue => "/queue/DLQ", :max_redeliveries => 6 }.merge(options)
       # Lets make sure all keys are symbols
       message.headers = message.headers.symbolize_keys
@@ -421,9 +307,9 @@ module Stomp
     end
 
     # disconnect closes this connection.  If requested, a disconnect RECEIPT 
-    # is received.
+    # will be received.
     def disconnect(headers = {})
-      raise Stomp::Error::NoCurrentConnection if closed?
+      raise Stomp::Error::NoCurrentConnection if @closed_check && closed?
       headers = headers.symbolize_keys
       _headerCheck(headers)
       if @protocol >= Stomp::SPL_11
@@ -441,37 +327,16 @@ module Stomp
     # poll returns a pending message if one is available, otherwise
     # returns nil.
     def poll()
-      raise Stomp::Error::NoCurrentConnection if closed?
+      raise Stomp::Error::NoCurrentConnection if @closed_check && closed?
       # No need for a read lock here.  The receive method eventually fulfills
       # that requirement.
       return nil if @socket.nil? || !@socket.ready?
       receive()
     end
 
-    # __old_receive receives a frame, blocks until the frame is received.
-    # *NOTE* This method will be made private in the next release.
-    def __old_receive()
-      # The receive may fail so we may need to retry.
-      while TRUE
-        begin
-          used_socket = socket
-          return _receive(used_socket)
-        rescue
-          @failure = $!
-          raise unless @reliable
-          errstr = "receive failed: #{$!}"
-          if @logger && @logger.respond_to?(:on_miscerr)
-            @logger.on_miscerr(log_params, errstr)
-          else
-            $stderr.print errstr
-          end
-        end
-      end
-    end
-
     # receive returns the next Message off of the wire.
     def receive()
-      raise Stomp::Error::NoCurrentConnection if closed?
+      raise Stomp::Error::NoCurrentConnection if @closed_check && closed?
       super_result = __old_receive
       if super_result.nil? && @reliable && !closed?
         errstr = "connection.receive returning EOF as nil - resetting connection.\n"
diff --git a/lib/stomp/constants.rb b/lib/stomp/constants.rb
index 04dbbf6..8d25228 100644
--- a/lib/stomp/constants.rb
+++ b/lib/stomp/constants.rb
@@ -2,7 +2,7 @@
 
 module Stomp
 
-  # Client side
+  # Client generated frames
   CMD_CONNECT     = "CONNECT"
   CMD_STOMP       = "STOMP"
   CMD_DISCONNECT  = "DISCONNECT"
@@ -15,7 +15,7 @@ module Stomp
   CMD_COMMIT      = "COMMIT"
   CMD_ABORT       = "ABORT"
 
-  # Server side
+  # Server generated names
   CMD_CONNECTED = "CONNECTED"
   CMD_MESSAGE   = "MESSAGE"
   CMD_RECEIPT   = "RECEIPT"
@@ -75,6 +75,7 @@ module Stomp
     "\\c", ":",
   ]
 
+  # A fairly safe and generally supported ciphers list.
   DEFAULT_CIPHERS = [
     ["DHE-RSA-AES256-SHA", "TLSv1/SSLv3", 256, 256], 
     ["DHE-DSS-AES256-SHA", "TLSv1/SSLv3", 256, 256], 
@@ -97,4 +98,4 @@ module Stomp
     ["EXP-RC4-MD5", "TLSv1/SSLv3", 40, 128],
   ]
 
-end
+end # Module Stomp
diff --git a/lib/stomp/errors.rb b/lib/stomp/errors.rb
index 9430b08..a6f09af 100644
--- a/lib/stomp/errors.rb
+++ b/lib/stomp/errors.rb
@@ -48,6 +48,7 @@ module Stomp
 
     # NoCurrentConnection is raised if:
     # * Any method is called when a current connection does not exist.
+    # * And @closed_check is true (the default).
     class NoCurrentConnection < RuntimeError
       def message
         "no current connection exists"
@@ -189,5 +190,6 @@ module Stomp
     end
 
   end # module Error
+
 end # module Stomp
 
diff --git a/lib/stomp/ext/hash.rb b/lib/stomp/ext/hash.rb
index 9c1c171..5e92eb5 100644
--- a/lib/stomp/ext/hash.rb
+++ b/lib/stomp/ext/hash.rb
@@ -27,4 +27,5 @@ class ::Hash
 
     symbolized
   end unless self.method_defined?(:symbolize_keys)
-end
+
+end # class Hash
diff --git a/lib/stomp/message.rb b/lib/stomp/message.rb
index f9f27eb..0273602 100644
--- a/lib/stomp/message.rb
+++ b/lib/stomp/message.rb
@@ -94,7 +94,7 @@ module Stomp
       self.body = work_body[0..body_length]
     end
 
-    # to_s returns a string prepresentation of this Message
+    # to_s returns a string prepresentation of this Message.
     def to_s
       "<Stomp::Message headers=#{headers.inspect} body='#{body}' command='#{command}' >"
     end
@@ -111,7 +111,7 @@ module Stomp
       is_blank?(command) && is_blank?(headers) && is_blank?(body)
     end
 
-  end
+  end # class Message
 
-end
+end # module Stomp
 
diff --git a/lib/stomp/sslparams.rb b/lib/stomp/sslparams.rb
index 98d3f99..c6bbd52 100644
--- a/lib/stomp/sslparams.rb
+++ b/lib/stomp/sslparams.rb
@@ -41,7 +41,7 @@ module Stomp
   # Client wants file existance check on initialize. true/value or false/nil.
   attr_reader :fsck #
 
-  # initialize returns a valid set of SSLParams or raises an error.
+  # initialize returns a valid instance of SSLParams or raises an error.
   def initialize(opts={})
 
    # Server authentication parameters
diff --git a/lib/stomp/version.rb b/lib/stomp/version.rb
index f7ac410..f34eea1 100644
--- a/lib/stomp/version.rb
+++ b/lib/stomp/version.rb
@@ -6,7 +6,7 @@ module Stomp
   module Version  #:nodoc: all
     MAJOR = 1
     MINOR = 2
-    PATCH = 5
+    PATCH = 6
     STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
   end
 end
diff --git a/metadata.yml b/metadata.yml
index 70d98a1..a272206 100644
--- a/metadata.yml
+++ b/metadata.yml
@@ -1,13 +1,13 @@
 --- !ruby/object:Gem::Specification 
 name: stomp
 version: !ruby/object:Gem::Version 
-  hash: 21
+  hash: 19
   prerelease: false
   segments: 
   - 1
   - 2
-  - 5
-  version: 1.2.5
+  - 6
+  version: 1.2.6
 platform: ruby
 authors: 
 - Brian McCallister
@@ -18,7 +18,7 @@ autorequire:
 bindir: bin
 cert_chain: []
 
-date: 2012-08-04 00:00:00 -04:00
+date: 2012-10-05 00:00:00 -04:00
 default_executable: 
 dependencies: 
 - !ruby/object:Gem::Dependency 
diff --git a/spec/client_spec.rb b/spec/client_spec.rb
index 78e7d15..b8721f7 100644
--- a/spec/client_spec.rb
+++ b/spec/client_spec.rb
@@ -236,8 +236,7 @@ describe Stomp::Client do
         :back_off_multiplier => 2,
         :max_reconnect_attempts => 0,
         :randomize => false,
-        :backup => false,
-        :timeout => -1
+        :connect_timeout => 0
       }
     end
     it "should properly parse a URL with failover://" do
@@ -311,8 +310,7 @@ describe Stomp::Client do
         :back_off_multiplier => 3,
         :max_reconnect_attempts => 4,
         :randomize => true,
-        :backup => false,
-        :timeout => -1
+        :connect_timeout => 0
       }
       
       @parameters[:hosts] = [
diff --git a/spec/connection_spec.rb b/spec/connection_spec.rb
index ae83e1e..8a82794 100644
--- a/spec/connection_spec.rb
+++ b/spec/connection_spec.rb
@@ -17,11 +17,12 @@ describe Stomp::Connection do
       :back_off_multiplier => 2,
       :max_reconnect_attempts => 0,
       :randomize => false,
-      :backup => false,
       :connect_timeout => 0,
       :parse_timeout => 5,
       :connect_headers => {},
-      :dmh => false
+      :dmh => false,
+      :closed_check => true,
+      :hbser => false,
     }
         
     #POG:
@@ -52,7 +53,6 @@ describe Stomp::Connection do
         "backOffMultiplier" => 2,
         "maxReconnectAttempts" => 0,
         "randomize" => false,
-        "backup" => false,
         "connect_timeout" => 0,
         "parse_timeout" => 5,
       }
@@ -85,7 +85,6 @@ describe Stomp::Connection do
         "backOffMultiplier" => 2,
         "maxReconnectAttempts" => 0,
         "randomize" => false,
-        "backup" => false,
         "connect_timeout" => 0,
         "parse_timeout" => 5
       }
@@ -99,7 +98,7 @@ describe Stomp::Connection do
     end
     
     it "should change host to next one with randomize false" do
-      @connection.change_host
+      @connection.send(:change_host) # use .send(:name) to test a private method!
       @connection.instance_variable_get(:@host).should == "remotehost"
     end
     
@@ -287,21 +286,21 @@ describe Stomp::Connection do
 
     describe "when called to increase reconnect delay" do
       it "should exponentialy increase when use_exponential_back_off is true" do
-        @connection.increase_reconnect_delay.should == 0.02
-        @connection.increase_reconnect_delay.should == 0.04
-        @connection.increase_reconnect_delay.should == 0.08
+        @connection.send(:increase_reconnect_delay).should == 0.02
+        @connection.send(:increase_reconnect_delay).should == 0.04
+        @connection.send(:increase_reconnect_delay).should == 0.08
       end
       it "should not increase when use_exponential_back_off is false" do
         @parameters[:use_exponential_back_off] = false
         @connection = Stomp::Connection.new(@parameters)
-        @connection.increase_reconnect_delay.should == 0.01
-        @connection.increase_reconnect_delay.should == 0.01
+        @connection.send(:increase_reconnect_delay).should == 0.01
+        @connection.send(:increase_reconnect_delay).should == 0.01
       end
       it "should not increase when max_reconnect_delay is reached" do
         @parameters[:initial_reconnect_delay] = 8.0
         @connection = Stomp::Connection.new(@parameters)
-        @connection.increase_reconnect_delay.should == 16.0
-        @connection.increase_reconnect_delay.should == 30.0
+        @connection.send(:increase_reconnect_delay).should == 16.0
+        @connection.send(:increase_reconnect_delay).should == 30.0
       end
       
       it "should change to next host on socket error" do
@@ -311,7 +310,7 @@ describe Stomp::Connection do
         #tries the new host
         TCPSocket.should_receive(:open).and_return @tcp_socket
 
-        @connection.socket
+        @connection.send(:socket)
         @connection.instance_variable_get(:@host).should == "remotehost"
       end
       
@@ -329,11 +328,12 @@ describe Stomp::Connection do
           :back_off_multiplier => 2,
           :max_reconnect_attempts => 0,
           :randomize => false,
-          :backup => false,
           :connect_timeout => 0,
           :parse_timeout => 5,
           :connect_headers => {},
           :dmh => false,
+          :closed_check => true,
+          :hbser => false,
         }
         
         used_hash =  {
@@ -367,12 +367,14 @@ describe Stomp::Connection do
           :dead_letter_queue => "queue/Error",
           :max_redeliveries => 10,
           :dmh => false,
+          :closed_check => true,
+          :hbser => false,
         }
         
         @connection = Stomp::Connection.new(used_hash)
         received_hash = @connection.instance_variable_get(:@parameters)
         
-        #Using randomize we can't assure the hosts order
+        # Using randomize we can't assure the hosts order
         received_hash.delete(:hosts)
         used_hash.delete(:hosts)
         
@@ -386,11 +388,11 @@ describe Stomp::Connection do
   describe "when closing a socket" do
     it "should close the tcp connection" do
       @tcp_socket.should_receive(:close)
-      @connection.obj_send(:close_socket).should be_true
+      @connection.__send__(:close_socket).should be_true # Use Object.__send__
     end
     it "should ignore exceptions" do
       @tcp_socket.should_receive(:close).and_raise "exception"
-      @connection.obj_send(:close_socket).should be_true
+      @connection.__send__(:close_socket).should be_true # Use Object.__send__
     end
   end
 
@@ -399,11 +401,11 @@ describe Stomp::Connection do
       host = @parameters[:hosts][0]
       @connection = Stomp::Connection.new(host[:login], host[:passcode], host[:host], host[:port], reliable = true, 5, connect_headers = {})
       @connection.instance_variable_set(:@connection_attempts, 10000)
-      @connection.max_reconnect_attempts?.should be_false
+      @connection.send(:max_reconnect_attempts?).should be_false
     end
     it "should return false if max_reconnect_attempts = 0" do
       @connection.instance_variable_set(:@connection_attempts, 10000)
-      @connection.max_reconnect_attempts?.should be_false
+      @connection.send(:max_reconnect_attempts?).should be_false
     end
     it "should return true if connection attempts > max_reconnect_attempts" do
       limit = 10000
@@ -411,10 +413,10 @@ describe Stomp::Connection do
       @connection = Stomp::Connection.new(@parameters)
       
       @connection.instance_variable_set(:@connection_attempts, limit-1)
-      @connection.max_reconnect_attempts?.should be_false
+      @connection.send(:max_reconnect_attempts?).should be_false
       
       @connection.instance_variable_set(:@connection_attempts, limit)
-      @connection.max_reconnect_attempts?.should be_true
+      @connection.send(:max_reconnect_attempts?).should be_true
       
     end
   end
diff --git a/stomp.gemspec b/stomp.gemspec
index 56b8fb8..23b06b1 100644
--- a/stomp.gemspec
+++ b/stomp.gemspec
@@ -5,11 +5,11 @@
 
 Gem::Specification.new do |s|
   s.name = %q{stomp}
-  s.version = "1.2.5"
+  s.version = "1.2.6"
 
   s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
   s.authors = ["Brian McCallister", "Marius Mathiesen", "Thiago Morello", "Guy M. Allard"]
-  s.date = %q{2012-08-04}
+  s.date = %q{2012-10-05}
   s.description = %q{Ruby client for the Stomp messaging protocol.  Note that this gem is no longer supported on rubyforge.}
   s.email = ["brianm at apache.org", "marius at stones.com", "morellon at gmail.com", "allard.guy.m at gmail.com"]
   s.executables = ["catstomp", "stompcat"]
diff --git a/test/tlogger.rb b/test/tlogger.rb
index 99295fc..2197b6f 100644
--- a/test/tlogger.rb
+++ b/test/tlogger.rb
@@ -93,16 +93,6 @@ class Tlogger
     end
   end
 
-  # Stomp 1.1+ - heart beat read (receive) failed
-  def on_hbread_fail(parms, ticker_data)
-    begin
-      @log.debug "Hbreadf Parms #{info(parms)}"
-      @log.debug "Hbreadf Result #{ticker_data}"
-    rescue
-      @log.debug "Hbreadf oops"
-    end
-  end
-
   # Stomp 1.1+ - heart beat send (transmit) failed
   def on_hbwrite_fail(parms, ticker_data)
     begin

-- 
ruby-stomp.git



More information about the Pkg-ruby-extras-commits mailing list