pkg.mk: use --local option for gem installation
[ruby-mogilefs-client.git] / lib / mogilefs.rb
blobe2a621fdf2965266328644de5551d540d7bcf19c
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   # :stopdoc:
9   if defined?(Process::CLOCK_MONOTONIC)
10     def self.now
11       Process.clock_gettime(Process::CLOCK_MONOTONIC)
12     end
13   else
14     def self.now
15       Time.now.to_f
16     end
17   end
18   # :startdoc:
20   # Standard error class for most MogileFS-specific errors
21   Error = Class.new(StandardError)
23   # Raised when a socket remains unreadable for too long.
24   UnreadableSocketError = Class.new(Error)
26   # Raised when a response is truncated while reading
27   # due to network/server # errors)
28   SizeMismatchError = Class.new(Error)
30   # Raised when checksum verification fails (only while reading deprecated
31   # "bigfiles" from the deprecated mogtool(1).
32   ChecksumMismatchError = Class.new(RuntimeError)
34   # Raised when a backend is in read-only mode
35   class ReadOnlyError < Error
36     def message # :nodoc:
37       'readonly mogilefs'
38     end
39   end
41   # Raised when an upload is impossible
42   EmptyPathError = Class.new(Error)
44   # Raised when we are given an unsupported protocol to upload to.
45   # Currently, the \MogileFS (2.XX) server only supports HTTP and
46   # this library is only capable of HTTP.
47   UnsupportedPathError = Class.new(Error)
49   # Raised when a request (HTTP or tracker) was truncated due to a network or
50   # server error.  It may be possible to retry idempotent requests from this.
51   RequestTruncatedError = Class.new(Error)
53   # Raised when a response from a server (HTTP or tracker) is not in a format
54   # that we expected (or truncated..
55   InvalidResponseError = Class.new(Error)
57   # Raised when all known backends have failed.
58   UnreachableBackendError = Class.new(Error)
60   # There was an error as a result of the use of the (experimental)
61   # pipelining code to the tracker backend
62   PipelineError = Class.new(Error)
64   # :stopdoc:
65   class << self
66     # somebody could use IO::Splice from the "io_splice" RubyGem, too
67     # don't consider this a stable API, though...
68     attr_accessor :io
69   end
71   # IO.copy_stream was buggy in Ruby 1.9.2 and earlier
72   if RUBY_VERSION >= "1.9.3"
73     @io = IO
74   else
75     require "mogilefs/copy_stream"
76     @io = MogileFS::CopyStream
77   end
79   begin
80     require 'net/http/persistent'
81     NHP = Net::HTTP::Persistent
82   rescue LoadError
83     require 'mogilefs/nhp_fake'
84     NHP = MogileFS::NhpFake
85   end
87   # autoload rarely-used things:
88   autoload :Mysql, 'mogilefs/mysql'
89   autoload :Pool, 'mogilefs/pool'
90   autoload :Admin, 'mogilefs/admin'
91   # :startdoc:
92 end
94 require 'mogilefs/util'
95 require 'mogilefs/socket'
96 require 'mogilefs/backend'
97 require 'mogilefs/http_file'
98 require 'mogilefs/http_reader'
99 require 'mogilefs/client'
100 require 'mogilefs/bigfile'
101 require 'mogilefs/mogilefs'
102 require 'mogilefs/version' # generated by ./GIT-VERSION-GEN