Sha256: c335ab8c03b9f43856d623117e1fdd056c6e61b83bb15480c9d1fd4973945021
Contents?: true
Size: 1.1 KB
Versions: 2
Compression:
Stored size: 1.1 KB
Contents
module EbisuConnection class Replica attr_reader :hostname, :weight def initialize(conf, replica_group) case conf when String host, weight = conf.split(/\s*,\s*/) @hostname, port = host.split(/\s*:\s*/) when Hash @hostname = conf["host"] || conf[:host] weight = conf["weight"] || conf[:weight] port = conf["port"] || conf[:port] else raise ArgumentError, "replica config is invalid" end spec = modify_spec(port) @connection_factory = FreshConnection::ConnectionFactory.new(replica_group, spec) @weight = (weight || 1).to_i end def connection @connection ||= @connection_factory.new_connection end def active? connection.active? end def disconnect! if @connection @connection.disconnect! @connection = nil end rescue end def modify_spec(port) modify_spec = {"host" => @hostname} return modify_spec unless port modify_spec["port"] = port.to_i if port.is_a?(Integer) || !port.empty? modify_spec end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
ebisu_connection-2.3.1 | lib/ebisu_connection/replica.rb |
ebisu_connection-2.3.0 | lib/ebisu_connection/replica.rb |