Branching mogilefs-client to version 1.2.1
[ruby-mogilefs-client.git] / lib / mogilefs / client.rb
blob75d35d2a7659672c24550cc5449d770c53c6bb1a
1 require 'mogilefs/backend'
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.
8 class MogileFS::Client
10   ##
11   # The backend connection for this client
13   attr_reader :backend
15   attr_accessor :hosts if defined? $TESTING
17   ##
18   # Creates a new Client.  See MogileFS::Backend#initialize for how to specify
19   # hosts.  If :readonly is set to true, the client will not modify anything
20   # on the server.
21   #
22   #   MogileFS::Client.new :hosts => ['kaa:6001', 'ziz:6001'], :readonly => true
24   def initialize(args)
25     @hosts = args[:hosts]
26     @readonly = args[:readonly] ? true : false
27     @timeout = args[:timeout]
29     reload
30   end
32   ##
33   # Creates a new MogileFS::Backend.
35   def reload
36     @backend = MogileFS::Backend.new :hosts => @hosts, :timeout => @timeout
37   end
39   ##
40   # The last error reported by the backend.
41   #--
42   # TODO use Exceptions
44   def err
45     @backend.lasterr
46   end
48   ##
49   # The last error message reported by the backend.
50   #--
51   # TODO use Exceptions
53   def errstr
54     @backend.lasterrstr
55   end
57   ##
58   # Is this a read-only client?
60   def readonly?
61     return @readonly
62   end
64 end