Class: Fastdfs::Client::Tracker

Inherits:
Object
  • Object
show all
Extended by:
Hook
Defined in:
lib/fastdfs-client/tracker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Hook

add_hook, after, before, ensure_hijacked, hooks, method_added

Constructor Details

#initialize(host, port, options = {}) ⇒ Tracker

Returns a new instance of Tracker.



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

def initialize(host, port, options = {})
  @socket = Socket.new(host, port, options[:socket])
  @cmd = CMD::STORE_WITHOUT_GROUP_ONE
end

Instance Attribute Details

#cmdObject

Returns the value of attribute cmd.



12
13
14
# File 'lib/fastdfs-client/tracker.rb', line 12

def cmd
  @cmd
end

#optionsObject

Returns the value of attribute options.



12
13
14
# File 'lib/fastdfs-client/tracker.rb', line 12

def options
  @options
end

#socketObject

Returns the value of attribute socket.



12
13
14
# File 'lib/fastdfs-client/tracker.rb', line 12

def socket
  @socket
end

Instance Method Details

#get_storageObject



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/fastdfs-client/tracker.rb', line 19

def get_storage
  header = ProtoCommon.header_bytes(@cmd, 0)
  @socket.write(@cmd, header)
  @socket.receive 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, options)
  end


end