RUBY-411 refactored ReplSetConnection#setup to remove code duplication
This commit is contained in:
parent
c871a645ad
commit
c954b75030
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user