RUBY-411 refactored ReplSetConnection#setup to remove code duplication

This commit is contained in:
Tyler Brock 2012-02-13 17:57:23 -05:00
parent c871a645ad
commit c954b75030
1 changed files with 2 additions and 47 deletions

View File

@ -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