Class: Fastdfs::Client::Tracker

Inherits:
Object
  • Object
show all
Includes:
Delegation
Defined in:
lib/fastdfs-client/tracker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Delegation

included

Constructor Details

#initialize(options = {}) ⇒ Tracker

Returns a new instance of Tracker.



14
15
16
17
18
19
20
21
# File 'lib/fastdfs-client/tracker.rb', line 14

def initialize(options = {})
  @options = default_options_merge(options)
  @proxies = @options[:trackers].map do |tracker| 
    opt = tracker.fs_symbolize_keys
    ClientProxy.new(opt[:host], opt[:port], extract_proxy_options.merge(alive: true)) 
  end

end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



10
11
12
# File 'lib/fastdfs-client/tracker.rb', line 10

def options
  @options
end

Instance Method Details

#get_storage(alive = false) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/fastdfs-client/tracker.rb', line 23

def get_storage(alive = false)
  res = proxy.dispose(CMD::STORE_WITHOUT_GROUP_ONE) do |body|
    storage_ip = body[ProtoCommon::IPADDR].strip
    storage_port = body[ProtoCommon::PORT].unpack("C*").to_pack_long
    store_path = body[ProtoCommon::TRACKER_BODY_LEN-1].unpack("C*")[0]
  
    Storage.new(storage_ip, storage_port, store_path, extract_proxy_options.merge(alive: alive))
  end
  raise res[:err_msg] unless res[:status]
  res[:result]
end

#pipelineObject



35
36
37
38
39
40
41
# File 'lib/fastdfs-client/tracker.rb', line 35

def pipeline
  storage = get_storage(true)
  yield storage
  storage
ensure
  storage.proxy.close
end