emogilefs 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +15 -0
- data/Rakefile +52 -0
- data/VERSION +1 -0
- data/lib/emogilefs.rb +119 -0
- metadata +62 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Andrew Rudenko
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
= emogilefs
|
2
|
+
|
3
|
+
MogileFS client patch for async requests to backend (not read or write data)
|
4
|
+
|
5
|
+
require 'emogilefs'
|
6
|
+
|
7
|
+
# init mogilefs_client
|
8
|
+
|
9
|
+
mogilefs_client.async(:get_hosts) do |data|
|
10
|
+
bla bla
|
11
|
+
end
|
12
|
+
|
13
|
+
== Copyright
|
14
|
+
|
15
|
+
Copyright (c) 2009 Andrew Rudenko. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "emogilefs"
|
8
|
+
gem.summary = %Q{MogileFS client patch for async requests to backend (not read or write data)}
|
9
|
+
gem.description = %Q{MogileFS client patch for async requests to backend (not read or write data)}
|
10
|
+
gem.email = "ceo@prepor.ru"
|
11
|
+
gem.homepage = "http://github.com/prepor/emogilefs"
|
12
|
+
gem.authors = ["Andrew Rudenko"]
|
13
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
14
|
+
end
|
15
|
+
Jeweler::GemcutterTasks.new
|
16
|
+
rescue LoadError
|
17
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
18
|
+
end
|
19
|
+
|
20
|
+
require 'rake/testtask'
|
21
|
+
Rake::TestTask.new(:test) do |test|
|
22
|
+
test.libs << 'lib' << 'test'
|
23
|
+
test.pattern = 'test/**/test_*.rb'
|
24
|
+
test.verbose = true
|
25
|
+
end
|
26
|
+
|
27
|
+
begin
|
28
|
+
require 'rcov/rcovtask'
|
29
|
+
Rcov::RcovTask.new do |test|
|
30
|
+
test.libs << 'test'
|
31
|
+
test.pattern = 'test/**/test_*.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
rescue LoadError
|
35
|
+
task :rcov do
|
36
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
task :test => :check_dependencies
|
41
|
+
|
42
|
+
task :default => :test
|
43
|
+
|
44
|
+
require 'rake/rdoctask'
|
45
|
+
Rake::RDocTask.new do |rdoc|
|
46
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
47
|
+
|
48
|
+
rdoc.rdoc_dir = 'rdoc'
|
49
|
+
rdoc.title = "emogilefs #{version}"
|
50
|
+
rdoc.rdoc_files.include('README*')
|
51
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
52
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/lib/emogilefs.rb
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
module EMogileFS
|
2
|
+
|
3
|
+
@@connections = {}
|
4
|
+
|
5
|
+
class << self
|
6
|
+
def <<(request)
|
7
|
+
connection(request.client).new_task request
|
8
|
+
end
|
9
|
+
def connection(client)
|
10
|
+
@@connections[client] ||= EM.attach client.send(:socket), EMogileFS, client
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
attr_accessor :client, :current_task
|
15
|
+
|
16
|
+
def initialize(client)
|
17
|
+
@queue = Queue.new
|
18
|
+
@current_task = nil
|
19
|
+
self.client = client
|
20
|
+
super
|
21
|
+
end
|
22
|
+
|
23
|
+
def new_task(request)
|
24
|
+
@queue << request
|
25
|
+
handle_task
|
26
|
+
end
|
27
|
+
|
28
|
+
def task_completed
|
29
|
+
@current_task = nil
|
30
|
+
end
|
31
|
+
|
32
|
+
def handle_task
|
33
|
+
|
34
|
+
if @queue.size > 0 && @current_task.nil?
|
35
|
+
@current_task = @queue.pop
|
36
|
+
@current_task.perform
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def receive_data(data)
|
41
|
+
begin
|
42
|
+
raise MogileFS::Backend::ConnectionLost unless data
|
43
|
+
if current_task && current_task.callback
|
44
|
+
begin
|
45
|
+
parsed = client.send :parse_response, data
|
46
|
+
current_task.callback.call parsed
|
47
|
+
rescue MogileFS::Backend::ChannelNotFoundError => e
|
48
|
+
puts 'not found'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
ensure
|
52
|
+
task_completed
|
53
|
+
handle_task
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def unbind
|
58
|
+
detach
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
class EMogileFS::Request
|
64
|
+
attr_accessor :request, :client, :socket, :options
|
65
|
+
def initialize(client, request)
|
66
|
+
self.client, self.request = client, request
|
67
|
+
self.socket = client.send :socket
|
68
|
+
EMogileFS << self
|
69
|
+
end
|
70
|
+
|
71
|
+
def callback(options = {}, &block)
|
72
|
+
if block
|
73
|
+
@options = options
|
74
|
+
@callback = block
|
75
|
+
else
|
76
|
+
@callback
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def perform
|
81
|
+
begin
|
82
|
+
bytes_sent = socket.send request, 0
|
83
|
+
rescue SystemCallError
|
84
|
+
client.send :shutdown
|
85
|
+
raise MogileFS::UnreachableBackendError
|
86
|
+
end
|
87
|
+
|
88
|
+
unless bytes_sent == request.length then
|
89
|
+
raise MogileFS::RequestTruncatedError,
|
90
|
+
"request truncated (sent #{bytes_sent} expected #{request.length})"
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
class MogileFS::MogileFS
|
97
|
+
def async(method, *args, &block)
|
98
|
+
Thread.current[:mogile_async] = true
|
99
|
+
req = self.send method, *args
|
100
|
+
req.callback(&block)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
class MogileFS::Backend
|
104
|
+
alias do_request_without_async do_request
|
105
|
+
|
106
|
+
def do_request(*args)
|
107
|
+
if Thread.current[:mogile_async]
|
108
|
+
Thread.current[:mogile_async] = false
|
109
|
+
do_request_with_async(*args)
|
110
|
+
else
|
111
|
+
do_request_without_async(*args)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def do_request_with_async(cmd, args)
|
116
|
+
request = make_request cmd, args
|
117
|
+
EMogileFS::Request.new(self, request)
|
118
|
+
end
|
119
|
+
end
|
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: emogilefs
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrew Rudenko
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-12-04 00:00:00 +03:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: MogileFS client patch for async requests to backend (not read or write data)
|
17
|
+
email: ceo@prepor.ru
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- LICENSE
|
24
|
+
- README.rdoc
|
25
|
+
files:
|
26
|
+
- .document
|
27
|
+
- .gitignore
|
28
|
+
- LICENSE
|
29
|
+
- README.rdoc
|
30
|
+
- Rakefile
|
31
|
+
- VERSION
|
32
|
+
- lib/emogilefs.rb
|
33
|
+
has_rdoc: true
|
34
|
+
homepage: http://github.com/prepor/emogilefs
|
35
|
+
licenses: []
|
36
|
+
|
37
|
+
post_install_message:
|
38
|
+
rdoc_options:
|
39
|
+
- --charset=UTF-8
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "0"
|
47
|
+
version:
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: "0"
|
53
|
+
version:
|
54
|
+
requirements: []
|
55
|
+
|
56
|
+
rubyforge_project:
|
57
|
+
rubygems_version: 1.3.5
|
58
|
+
signing_key:
|
59
|
+
specification_version: 3
|
60
|
+
summary: MogileFS client patch for async requests to backend (not read or write data)
|
61
|
+
test_files: []
|
62
|
+
|