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