implement :connect_timeout option
[ruby-mogilefs-client.git] / lib / mogilefs / client.rb
blob1e3087469877bae7464c852b525f38faf2da9fbe
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   # :stopdoc:
15   attr_accessor :hosts if defined? $TESTING
16   # :startdoc
18   ##
19   # Creates a new Client.  See MogileFS::Backend#initialize for how to specify
20   # hosts.  If :readonly is set to true, the client will not modify anything
21   # on the server.
22   #
23   #   MogileFS::Client.new :hosts => ['kaa:6001', 'ziz:6001'], :readonly => true
25   def initialize(args)
26     @hosts = args[:hosts]
27     @readonly = args[:readonly] ? true : false
28     @timeout = args[:timeout]
29     @fail_timeout = args[:fail_timeout]
30     @connect_timeout = args[:connect_timeout]
32     reload
33   end
35   ##
36   # Creates a new MogileFS::Backend.
38   def reload
39     @backend = MogileFS::Backend.new(:hosts => @hosts,
40                                      :timeout => @timeout,
41                                      :fail_timeout => @fail_timeout,
42                                      :connect_timeout => @connect_timeout)
43   end
45   ##
46   # The last error reported by the backend.
48   def err
49     @backend.lasterr
50   end
52   ##
53   # The last error message reported by the backend.
55   def errstr
56     @backend.lasterrstr
57   end
59   ##
60   # Is this a read-only client?
62   def readonly?
63     @readonly
64   end
66 end