From c954b75030f768984bd5b56459d5543dc616a60c Mon Sep 17 00:00:00 2001 From: Tyler Brock Date: Mon, 13 Feb 2012 17:57:23 -0500 Subject: [PATCH] RUBY-411 refactored ReplSetConnection#setup to remove code duplication --- lib/mongo/repl_set_connection.rb | 49 ++------------------------------ 1 file changed, 2 insertions(+), 47 deletions(-) diff --git a/lib/mongo/repl_set_connection.rb b/lib/mongo/repl_set_connection.rb index 085d34b..cf88057 100644 --- a/lib/mongo/repl_set_connection.rb +++ b/lib/mongo/repl_set_connection.rb @@ -440,64 +440,19 @@ module Mongo # Generic initialization code. def setup(opts) - # Default maximum BSON object size - @max_bson_size = Mongo::DEFAULT_MAX_BSON_SIZE - + super opts + @safe_mutex_lock = Mutex.new @safe_mutexes = Hash.new {|hash, key| hash[key] = Mutex.new} - # Determine whether to use SSL. - @ssl = opts.fetch(:ssl, false) - if @ssl - @socket_class = Mongo::SSLSocket - else - @socket_class = ::TCPSocket - end - - # Authentication objects - @auths = opts.fetch(:auths, []) - - # Lock for request ids. - @id_lock = Mutex.new - - # Pool size and timeout. - @pool_size = opts[:pool_size] || 1 - if opts[:timeout] - warn "The :timeout option has been deprecated " + - "and will be removed in the 2.0 release. Use :pool_timeout instead." - end - @pool_timeout = opts[:pool_timeout] || opts[:timeout] || 5.0 - - # Timeout on socket read operation. - @op_timeout = opts[:op_timeout] || nil - # Timeout on socket connect. @connect_timeout = opts[:connect_timeout] || 30 - # Mutex for synchronizing pool access - # TODO: remove this. - @connection_mutex = Mutex.new - - # Global safe option. This is false by default. - @safe = opts[:safe] || false - - # Condition variable for signal and wait - @queue = ConditionVariable.new - - @logger = opts[:logger] || nil - # Clean up connections to dead threads. @last_cleanup = Time.now @cleanup_lock = Mutex.new - if @logger - write_logging_startup_message - end - @last_refresh = Time.now - - should_connect = opts.fetch(:connect, true) - connect if should_connect end # Checkout a socket connected to a node with one of