lib/connection/utils.rb in stomp-1.3.1 vs lib/connection/utils.rb in stomp-1.3.2

- old
+ new

@@ -114,13 +114,11 @@ @failure = nil begin used_socket = open_socket() # sets @closed = false if OK # Open is complete connect(used_socket) - if @logger && @logger.respond_to?(:on_connected) - @logger.on_connected(log_params) - end + slog(:on_connected, log_params) @connection_attempts = 0 rescue @failure = $! used_socket = nil @closed = true @@ -130,24 +128,20 @@ # Catch errors which are: # a) emitted from corrupted 1.1+ 'connect' (caller programming error) # b) should never be retried raise if @failure.is_a?(Stomp::Error::ProtocolError11p) - 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) + begin + unless slog(:on_connectfail,log_params) + $stderr.print "connect to #{@host} failed: #{$!} will retry(##{@connection_attempts}) in #{@reconnect_delay}\n" end - else - $stderr.print "connect to #{@host} failed: #{$!} will retry(##{@connection_attempts}) in #{@reconnect_delay}\n" + rescue Exception => aex + raise if aex.is_a?(Stomp::Error::LoggerConnectionError) end - raise Stomp::Error::MaxReconnectAttempts if max_reconnect_attempts? + raise Stomp::Error::MaxReconnectAttempts if max_reconnect_attempts? sleep(@reconnect_delay) - @connection_attempts += 1 if @parameters change_host() increase_reconnect_delay() @@ -181,11 +175,12 @@ :stompconn => false, :max_hbread_fails => 0, :max_hbrlck_fails => 0, :fast_hbs_adjust => 0.0, :connread_timeout => 0, - :tcp_nodelay => true + :tcp_nodelay => true, + :start_timeout => 10, } res_params = default_params.merge(params) if res_params[:dmh] res_params = _expand_hosts(res_params) @@ -206,10 +201,22 @@ @port = current_host[:port] || Connection::default_port(@ssl) @login = current_host[:login] || "" @passcode = current_host[:passcode] || "" end + # Duplicate parameters hash + def _hdup(h) + ldup = {} + ldup.merge!(h) + ldup[:hosts] = [] + hvals = h[:hosts].nil? ? h["hosts"] : h[:hosts] + hvals.each do |hv| + ldup[:hosts] << hv.dup + end + ldup + 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 @@ -235,12 +242,10 @@ raise rescue @failure = $! raise unless @reliable errstr = "receive failed: #{$!}" - if @logger && @logger.respond_to?(:on_miscerr) - @logger.on_miscerr(log_params, "es_oldrecv: " + errstr) - else + unless slog(:on_miscerr, log_params, "es_oldrecv: " + errstr) $stderr.print errstr end # !!! This initiates a re-connect !!! _reconn_prep()