Ruby mogilefs-client 3.12.2
[ruby-mogilefs-client.git] / lib / mogilefs.rb
blobabc36804a31ee42e2e3c5df20417689b097a531f
1 # -*- encoding: binary -*-
3 # To read more about \MogileFS, see
4 # https://github.com/mogilefs/MogileFS-Server/wiki
6 # Client usage information is available in MogileFS::MogileFS.
7 module MogileFS
9   # :stopdoc:
10   if defined?(Process::CLOCK_MONOTONIC)
11     def self.now
12       Process.clock_gettime(Process::CLOCK_MONOTONIC)
13     end
14   else
15     def self.now
16       Time.now.to_f
17     end
18   end
19   # :startdoc:
21   # Standard error class for most MogileFS-specific errors
22   Error = Class.new(StandardError)
24   # Raised when a socket remains unreadable for too long.
25   UnreadableSocketError = Class.new(Error)
27   # Raised when a response is truncated while reading
28   # due to network/server # errors)
29   SizeMismatchError = Class.new(Error)
31   # Raised when checksum verification fails (only while reading deprecated
32   # "bigfiles" from the deprecated mogtool(1).
33   ChecksumMismatchError = Class.new(RuntimeError)
35   # Raised when a backend is in read-only mode
36   class ReadOnlyError < Error
37     def message # :nodoc:
38       'readonly mogilefs'
39     end
40   end
42   # Raised when an upload is impossible
43   EmptyPathError = Class.new(Error)
45   # Raised when we are given an unsupported protocol to upload to.
46   # Currently, the \MogileFS (2.XX) server only supports HTTP and
47   # this library is only capable of HTTP.
48   UnsupportedPathError = Class.new(Error)
50   # Raised when a request (HTTP or tracker) was truncated due to a network or
51   # server error.  It may be possible to retry idempotent requests from this.
52   RequestTruncatedError = Class.new(Error)
54   # Raised when a response from a server (HTTP or tracker) is not in a format
55   # that we expected (or truncated..
56   InvalidResponseError = Class.new(Error)
58   # Raised when all known backends have failed.
59   UnreachableBackendError = Class.new(Error)
61   # There was an error as a result of the use of the (experimental)
62   # pipelining code to the tracker backend
63   PipelineError = Class.new(Error)
65   # :stopdoc:
66   class << self
67     # somebody could use IO::Splice from the "io_splice" RubyGem, too
68     # don't consider this a stable API, though...
69     attr_accessor :io
70   end
72   # IO.copy_stream was buggy in Ruby 1.9.2 and earlier
73   if RUBY_VERSION >= "1.9.3"
74     @io = IO
75   else
76     require "mogilefs/copy_stream"
77     @io = MogileFS::CopyStream
78   end
80   begin
81     require 'net/http/persistent'
82     NHP = Net::HTTP::Persistent
83   rescue LoadError
84     require 'mogilefs/nhp_fake'
85     NHP = MogileFS::NhpFake
86   end
88   # autoload rarely-used things:
89   autoload :Mysql, 'mogilefs/mysql'
90   autoload :Pool, 'mogilefs/pool'
91   autoload :Admin, 'mogilefs/admin'
92   # :startdoc:
93 end
95 require 'mogilefs/util'
96 require 'mogilefs/socket'
97 require 'mogilefs/backend'
98 require 'mogilefs/http_file'
99 require 'mogilefs/http_reader'
100 require 'mogilefs/client'
101 require 'mogilefs/bigfile'
102 require 'mogilefs/mogilefs'
103 require 'mogilefs/version' # generated by ./GIT-VERSION-GEN