http_file: do not reopen opened file (on retry)
[ruby-mogilefs-client.git] / lib / mogilefs / client.rb
blob9a2f34b7fc126151dd20dfbe6bd853d519372dab
1 # -*- encoding: binary -*-
3 ##
4 # MogileFS::Client is the MogileFS client base class.  Concrete clients like
5 # MogileFS::MogileFS and MogileFS::Admin are implemented atop this one to do
6 # real work.
7 class MogileFS::Client
9   ##
10   # The backend connection for this client
12   attr_reader :backend
14   attr_accessor :hosts if defined? $TESTING
16   ##
17   # Creates a new Client.  See MogileFS::Backend#initialize for how to specify
18   # hosts.  If :readonly is set to true, the client will not modify anything
19   # on the server.
20   #
21   #   MogileFS::Client.new :hosts => ['kaa:6001', 'ziz:6001'], :readonly => true
23   def initialize(args)
24     @hosts = args[:hosts]
25     @readonly = args[:readonly] ? true : false
26     @timeout = args[:timeout]
28     reload
29   end
31   ##
32   # Creates a new MogileFS::Backend.
34   def reload
35     @backend = MogileFS::Backend.new :hosts => @hosts, :timeout => @timeout
36   end
38   ##
39   # The last error reported by the backend.
41   def err
42     @backend.lasterr
43   end
45   ##
46   # The last error message reported by the backend.
48   def errstr
49     @backend.lasterrstr
50   end
52   ##
53   # Is this a read-only client?
55   def readonly?
56     @readonly
57   end
59 end