ruby_skynet 0.3.0 → 0.4.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +2 -2
- data/Gemfile.lock +19 -20
- data/README.md +1 -1
- data/Rakefile +6 -3
- data/examples/echo_client.rb +9 -0
- data/examples/echo_server.rb +28 -0
- data/lib/ruby_skynet/connection.rb +1 -0
- data/lib/ruby_skynet/doozer/client.rb +1 -1
- data/lib/ruby_skynet/server.rb +70 -80
- data/lib/ruby_skynet/service.rb +1 -1
- data/lib/ruby_skynet/version.rb +1 -1
- data/test/ruby_skynet_service_test.rb +2 -2
- data/test/simple_server.rb +23 -22
- data/test.sh +7 -0
- metadata +39 -43
- data/nbproject/private/config.properties +0 -0
- data/nbproject/private/private.properties +0 -1
- data/nbproject/private/private.xml +0 -4
- data/nbproject/private/rake-d.txt +0 -4
- data/nbproject/project.properties +0 -6
- data/nbproject/project.xml +0 -15
- data/test.log +0 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 729668f7d983cdc9801d603ace66a025d0038cf2
|
4
|
+
data.tar.gz: 9f9ac2b233d3c607d01f316476bf193010cc8a86
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d68231094851f6c74ee3eb1f0eaf17442ca7fb9d7788c7247c09561b61344b68cd68fb495468f66e8ee517171566b8e099431e0ba0a844f6be35c2df0ba92072
|
7
|
+
data.tar.gz: c57624d3a943a3c8751b738f7c4a447b145d9127d4b08bd040ac700c1bbde88ca9c12aa379a0e84c2034cf785d2e8f30ff117242a6171e0730dd957eb9e07f6d
|
data/Gemfile
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
source
|
1
|
+
source 'http://rubygems.org'
|
2
2
|
|
3
3
|
group :test do
|
4
4
|
gem "shoulda"
|
@@ -18,4 +18,4 @@ gem "bson"
|
|
18
18
|
gem "bson_ext", :platform => :ruby
|
19
19
|
# Celluloid::IO is used to create SkyNet services in Ruby
|
20
20
|
# multi_json?
|
21
|
-
gem "celluloid-io"
|
21
|
+
gem "celluloid-io", '0.13.0.pre2'
|
data/Gemfile.lock
CHANGED
@@ -1,54 +1,53 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
-
activesupport (3.2.
|
4
|
+
activesupport (3.2.12)
|
5
5
|
i18n (~> 0.6)
|
6
6
|
multi_json (~> 1.0)
|
7
|
+
atomic (1.0.1)
|
8
|
+
atomic (1.0.1-java)
|
7
9
|
bourne (1.1.2)
|
8
10
|
mocha (= 0.10.5)
|
9
|
-
bson (1.8.
|
10
|
-
|
11
|
-
|
12
|
-
bson (~> 1.8.0)
|
13
|
-
celluloid (0.12.3)
|
14
|
-
facter (>= 1.6.12)
|
11
|
+
bson (1.8.3)
|
12
|
+
bson (1.8.3-java)
|
13
|
+
celluloid (0.13.0.pre2)
|
15
14
|
timers (>= 1.0.0)
|
16
|
-
celluloid-io (0.
|
17
|
-
celluloid (
|
15
|
+
celluloid-io (0.13.0.pre2)
|
16
|
+
celluloid (>= 0.13.0.pre)
|
18
17
|
nio4r (>= 0.4.0)
|
19
|
-
facter (1.6.16)
|
20
18
|
gene_pool (1.3.0)
|
21
|
-
i18n (0.6.
|
19
|
+
i18n (0.6.4)
|
22
20
|
metaclass (0.0.1)
|
23
21
|
mocha (0.10.5)
|
24
22
|
metaclass (~> 0.0.1)
|
25
|
-
multi_json (1.
|
26
|
-
nio4r (0.4.3)
|
27
|
-
rake (10.0.
|
23
|
+
multi_json (1.7.0)
|
24
|
+
nio4r (0.4.3-java)
|
25
|
+
rake (10.0.3)
|
28
26
|
resilient_socket (0.4.0)
|
29
27
|
semantic_logger
|
30
28
|
ruby_protobuf (0.4.11)
|
31
|
-
semantic_logger (0.
|
29
|
+
semantic_logger (2.0.0)
|
32
30
|
sync_attr
|
33
31
|
thread_safe
|
34
32
|
shoulda (3.3.2)
|
35
33
|
shoulda-context (~> 1.0.1)
|
36
34
|
shoulda-matchers (~> 1.4.1)
|
37
|
-
shoulda-context (1.0.
|
35
|
+
shoulda-context (1.0.2)
|
38
36
|
shoulda-matchers (1.4.2)
|
39
37
|
activesupport (>= 3.0.0)
|
40
38
|
bourne (~> 1.1.2)
|
41
39
|
sync_attr (0.1.1)
|
42
|
-
thread_safe (0.0
|
43
|
-
|
40
|
+
thread_safe (0.1.0)
|
41
|
+
atomic
|
42
|
+
timers (1.1.0)
|
44
43
|
|
45
44
|
PLATFORMS
|
46
|
-
|
45
|
+
java
|
47
46
|
|
48
47
|
DEPENDENCIES
|
49
48
|
bson
|
50
49
|
bson_ext
|
51
|
-
celluloid-io
|
50
|
+
celluloid-io (= 0.13.0.pre2)
|
52
51
|
gene_pool
|
53
52
|
multi_json
|
54
53
|
rake
|
data/README.md
CHANGED
@@ -25,7 +25,7 @@ require 'rubygems'
|
|
25
25
|
require 'ruby_skynet'
|
26
26
|
|
27
27
|
RubySkynet::Server.port = 2000
|
28
|
-
RubySkynet::Server.hostname = '
|
28
|
+
RubySkynet::Server.hostname = '127.0.0.1'
|
29
29
|
|
30
30
|
# Just echo back any parameters received when the echo method is called
|
31
31
|
class EchoService
|
data/Rakefile
CHANGED
@@ -2,6 +2,7 @@ lib = File.expand_path('../lib/', __FILE__)
|
|
2
2
|
$:.unshift lib unless $:.include?(lib)
|
3
3
|
|
4
4
|
require 'rubygems'
|
5
|
+
require 'rubygems/package'
|
5
6
|
require 'rake/clean'
|
6
7
|
require 'rake/testtask'
|
7
8
|
require 'date'
|
@@ -20,15 +21,17 @@ task :gem do |t|
|
|
20
21
|
spec.date = Date.today.to_s
|
21
22
|
spec.summary = "Skynet Ruby Client"
|
22
23
|
spec.description = "Ruby Client for invoking Skynet services"
|
23
|
-
spec.files = FileList["./**/*"].exclude(
|
24
|
+
spec.files = FileList["./**/*"].exclude(/\.gem$/, /\.log$/,/nbproject/).map{|f| f.sub(/^\.\//, '')}
|
25
|
+
spec.license = "Apache License V2.0"
|
24
26
|
spec.has_rdoc = true
|
25
27
|
spec.add_dependency 'semantic_logger'
|
26
28
|
spec.add_dependency 'resilient_socket'
|
27
|
-
spec.add_dependency 'multi_json'
|
29
|
+
spec.add_dependency 'multi_json', '>= 1.6.1'
|
28
30
|
spec.add_dependency 'bson'
|
29
31
|
spec.add_dependency 'ruby_protobuf'
|
32
|
+
spec.add_dependency 'celluloid-io', '>= 0.13.0.pre2'
|
30
33
|
end
|
31
|
-
Gem::
|
34
|
+
Gem::Package.build gemspec
|
32
35
|
end
|
33
36
|
|
34
37
|
desc "Run Test Suite"
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'ruby_skynet'
|
3
|
+
require 'sync_attr'
|
4
|
+
|
5
|
+
SemanticLogger::Logger.default_level = :trace
|
6
|
+
SemanticLogger::Logger.appenders << SemanticLogger::Appender::File.new('skynet.log')
|
7
|
+
|
8
|
+
client = RubySkynet::Client.new('EchoService')
|
9
|
+
p client.call('echo', :hello => 'world')
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'ruby_skynet'
|
3
|
+
|
4
|
+
# Log trace information to a log file
|
5
|
+
SemanticLogger::Logger.default_level = :trace
|
6
|
+
SemanticLogger::Logger.appenders << SemanticLogger::Appender::File.new('skynet.log')
|
7
|
+
|
8
|
+
# Specify Port and Hostname to listen for requests on
|
9
|
+
RubySkynet::Server.port = 2000
|
10
|
+
RubySkynet::Server.hostname = '127.0.0.1'
|
11
|
+
|
12
|
+
# Just echo back any parameters received when the echo method is called
|
13
|
+
class EchoService
|
14
|
+
include RubySkynet::Service
|
15
|
+
|
16
|
+
# Methods implemented by this service
|
17
|
+
# Must take a Hash as input
|
18
|
+
# Must Return a Hash response or nil for no response
|
19
|
+
def echo(params)
|
20
|
+
params
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# Start the server
|
25
|
+
RubySkynet::Server.start
|
26
|
+
|
27
|
+
puts "Press enter to shutdown server"
|
28
|
+
gets
|
@@ -183,7 +183,7 @@ module RubySkynet
|
|
183
183
|
# Network error on read must be sent back to caller since we do not
|
184
184
|
# know if the modification was made
|
185
185
|
response = read(timeout) unless retry_read
|
186
|
-
raise ResponseError.new("#{Response::Err.name_by_value(response.err_code)}: #{response.err_detail}") if response.err_code != 0
|
186
|
+
raise ResponseError.new("#{Response::Err.name_by_value(response.err_code)} (#{response.err_code}): #{response.err_detail}") if response.err_code != 0
|
187
187
|
response
|
188
188
|
end
|
189
189
|
|
data/lib/ruby_skynet/server.rb
CHANGED
@@ -20,6 +20,19 @@ module RubySkynet
|
|
20
20
|
@@region = 'Development'
|
21
21
|
@@server = nil
|
22
22
|
|
23
|
+
def self.start
|
24
|
+
@@server ||= supervise(hostname, port)
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.stop
|
28
|
+
@@server.terminate if @@server
|
29
|
+
@@server = nil
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.running?
|
33
|
+
(@@server != nil) && @@server.running?
|
34
|
+
end
|
35
|
+
|
23
36
|
# Region under which to register Skynet services
|
24
37
|
# Default: 'Development'
|
25
38
|
def self.region
|
@@ -73,21 +86,17 @@ module RubySkynet
|
|
73
86
|
@@services.delete(klass.service_name)
|
74
87
|
end
|
75
88
|
|
76
|
-
#
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
@@server.start
|
85
|
-
end
|
89
|
+
# Start the server so that it can start taking RPC calls
|
90
|
+
# Returns false if the server is already running
|
91
|
+
def initialize(host, port)
|
92
|
+
# Since we included Celluloid::IO, we're actually making a
|
93
|
+
# Celluloid::IO::TCPServer here
|
94
|
+
# TODO If port is in use, try the next port in sequence
|
95
|
+
@server = TCPServer.new(host, port)
|
96
|
+
async.run
|
86
97
|
|
87
|
-
|
88
|
-
|
89
|
-
@@server.terminate
|
90
|
-
@@server = nil
|
98
|
+
# Register services hosted by this server
|
99
|
+
self.class.services.each_pair {|key, klass| self.class.register_service_in_doozer(klass)}
|
91
100
|
end
|
92
101
|
|
93
102
|
def finalize
|
@@ -103,80 +112,18 @@ module RubySkynet
|
|
103
112
|
logger.info "Skynet Services De-registered in Doozer"
|
104
113
|
end
|
105
114
|
|
106
|
-
# Returns whether the server is running
|
107
|
-
def running?
|
108
|
-
(@server != nil) && !@server.closed?
|
109
|
-
end
|
110
|
-
|
111
|
-
############################################################################
|
112
|
-
protected
|
113
|
-
|
114
|
-
attr_accessor :server
|
115
|
-
|
116
|
-
# Register the supplied service in doozer
|
117
|
-
def self.register_service_in_doozer(klass)
|
118
|
-
config = {
|
119
|
-
"Config" => {
|
120
|
-
"UUID" => "#{Server.hostname}:#{Server.port}-#{$$}-#{klass.name}-#{klass.object_id}",
|
121
|
-
"Name" => klass.service_name,
|
122
|
-
"Version" => klass.service_version.to_s,
|
123
|
-
"Region" => Server.region,
|
124
|
-
"ServiceAddr" => {
|
125
|
-
"IPAddress" => Server.hostname,
|
126
|
-
"Port" => Server.port,
|
127
|
-
"MaxPort" => Server.port + 999
|
128
|
-
},
|
129
|
-
},
|
130
|
-
"Registered" => true
|
131
|
-
}
|
132
|
-
RubySkynet::Registry.doozer_pool.with_connection do |doozer|
|
133
|
-
doozer[klass.service_key] = MultiJson.encode(config)
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
# Start the server so that it can start taking RPC calls
|
138
|
-
# Returns false if the server is already running
|
139
|
-
def start
|
140
|
-
return false if running?
|
141
|
-
|
142
|
-
# Since we included Celluloid::IO, we're actually making a
|
143
|
-
# Celluloid::IO::TCPServer here
|
144
|
-
# TODO If port is in use, try the next port in sequence
|
145
|
-
# TODO make port to listen on configurable
|
146
|
-
@server = TCPServer.new('0.0.0.0', self.class.port)
|
147
|
-
run!
|
148
|
-
|
149
|
-
# Register services hosted by this server
|
150
|
-
self.class.services.each_pair {|key, klass| self.class.register_service_in_doozer(klass)}
|
151
|
-
true
|
152
|
-
end
|
153
|
-
|
154
115
|
def run
|
155
116
|
logger.info("Starting listener on #{self.class.hostname}:#{self.class.port}")
|
156
117
|
loop do
|
157
118
|
logger.debug "Waiting for a client to connect"
|
158
119
|
begin
|
159
|
-
handle_connection
|
120
|
+
async.handle_connection(@server.accept)
|
160
121
|
rescue Exception => exc
|
161
122
|
logger.error "Exception while processing connection request", exc
|
162
123
|
end
|
163
124
|
end
|
164
125
|
end
|
165
126
|
|
166
|
-
# Called for each message received from the client
|
167
|
-
# Returns a Hash that is sent back to the caller
|
168
|
-
def on_message(service_name, method, params)
|
169
|
-
logger.benchmark_debug "Called: #{service_name}##{method}" do
|
170
|
-
logger.trace "Method Call: #{method} with parameters:", params
|
171
|
-
klass = Server.services[service_name]
|
172
|
-
raise "Invalid Skynet RPC call, service: #{service_name} is not available at this server" unless klass
|
173
|
-
service = klass.new
|
174
|
-
raise "Invalid Skynet RPC call, method: #{method} does not exist for service: #{service_name}" unless service.respond_to?(method)
|
175
|
-
# TODO Use pool of services, or Celluloid here
|
176
|
-
service.send(method, params)
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
127
|
# Called for each client connection
|
181
128
|
def handle_connection(client)
|
182
129
|
logger.debug "Client connected, waiting for data from client"
|
@@ -186,7 +133,7 @@ module RubySkynet
|
|
186
133
|
'registered' => true,
|
187
134
|
'clientid' => BSON::ObjectId.new.to_s
|
188
135
|
}
|
189
|
-
client.write(BSON.serialize(handshake))
|
136
|
+
client.write(BSON.serialize(handshake).to_s)
|
190
137
|
Common.read_bson_document(client)
|
191
138
|
|
192
139
|
while(header = Common.read_bson_document(client)) do
|
@@ -216,11 +163,11 @@ module RubySkynet
|
|
216
163
|
if reply
|
217
164
|
logger.debug "Sending Header"
|
218
165
|
# For this test we just send back the received header
|
219
|
-
client.write(BSON.serialize(header))
|
166
|
+
client.write(BSON.serialize(header).to_s)
|
220
167
|
|
221
168
|
logger.debug "Sending Reply"
|
222
169
|
logger.trace 'Reply', reply
|
223
|
-
client.write(BSON.serialize({'out' => BSON.serialize(reply).to_s}))
|
170
|
+
client.write(BSON.serialize({'out' => BSON.serialize(reply).to_s}).to_s)
|
224
171
|
else
|
225
172
|
logger.debug "Closing client since no reply is being sent back"
|
226
173
|
break
|
@@ -231,5 +178,48 @@ module RubySkynet
|
|
231
178
|
logger.debug "Disconnected from the client"
|
232
179
|
end
|
233
180
|
|
181
|
+
# Returns whether the server is running
|
182
|
+
def running?
|
183
|
+
(@server != nil) && !@server.closed?
|
184
|
+
end
|
185
|
+
|
186
|
+
############################################################################
|
187
|
+
protected
|
188
|
+
|
189
|
+
# Register the supplied service in doozer
|
190
|
+
def self.register_service_in_doozer(klass)
|
191
|
+
config = {
|
192
|
+
"Config" => {
|
193
|
+
"UUID" => "#{Server.hostname}:#{Server.port}-#{$$}-#{klass.name}-#{klass.object_id}",
|
194
|
+
"Name" => klass.service_name,
|
195
|
+
"Version" => klass.service_version.to_s,
|
196
|
+
"Region" => Server.region,
|
197
|
+
"ServiceAddr" => {
|
198
|
+
"IPAddress" => Server.hostname,
|
199
|
+
"Port" => Server.port,
|
200
|
+
"MaxPort" => Server.port + 999
|
201
|
+
},
|
202
|
+
},
|
203
|
+
"Registered" => true
|
204
|
+
}
|
205
|
+
RubySkynet::Registry.doozer_pool.with_connection do |doozer|
|
206
|
+
doozer[klass.service_key] = MultiJson.encode(config)
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
# Called for each message received from the client
|
211
|
+
# Returns a Hash that is sent back to the caller
|
212
|
+
def on_message(service_name, method, params)
|
213
|
+
logger.benchmark_debug "Called: #{service_name}##{method}" do
|
214
|
+
logger.trace "Method Call: #{method} with parameters:", params
|
215
|
+
klass = Server.services[service_name]
|
216
|
+
raise "Invalid Skynet RPC call, service: #{service_name} is not available at this server" unless klass
|
217
|
+
service = klass.new
|
218
|
+
raise "Invalid Skynet RPC call, method: #{method} does not exist for service: #{service_name}" unless service.respond_to?(method)
|
219
|
+
# TODO Use pool of services, or Celluloid here
|
220
|
+
service.send(method, params)
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
234
224
|
end
|
235
225
|
end
|
data/lib/ruby_skynet/service.rb
CHANGED
@@ -21,7 +21,7 @@ module RubySkynet
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
# Register the service with the Server
|
24
|
-
# The server will publish the server to Doozer when
|
24
|
+
# The server will publish the server to Doozer when the server is running
|
25
25
|
Server.register_service(base)
|
26
26
|
end
|
27
27
|
|
data/lib/ruby_skynet/version.rb
CHANGED
@@ -14,7 +14,7 @@ end
|
|
14
14
|
|
15
15
|
RubySkynet::Server.port = 2100
|
16
16
|
RubySkynet::Server.region = 'Test'
|
17
|
-
RubySkynet::Server.hostname = '
|
17
|
+
RubySkynet::Server.hostname = '127.0.0.1'
|
18
18
|
|
19
19
|
class TestService
|
20
20
|
include RubySkynet::Service
|
@@ -36,7 +36,7 @@ class RubySkynetServiceTest < Test::Unit::TestCase
|
|
36
36
|
@service_name = 'TestService'
|
37
37
|
@version = 1
|
38
38
|
@region = 'Test'
|
39
|
-
@doozer_key = "/services/#{@service_name}/#{@version}/#{@region}/
|
39
|
+
@doozer_key = "/services/#{@service_name}/#{@version}/#{@region}/127.0.0.1/2100"
|
40
40
|
end
|
41
41
|
|
42
42
|
teardown do
|
data/test/simple_server.rb
CHANGED
@@ -7,22 +7,6 @@ require 'celluloid/io'
|
|
7
7
|
# This a simple stand-alone server that does not use the Skynet code so that
|
8
8
|
# the Skynet code can be tested
|
9
9
|
|
10
|
-
# Read the bson document, returning nil if the IO is closed
|
11
|
-
# before receiving any data or a complete BSON document
|
12
|
-
def read_bson_document(io)
|
13
|
-
bytebuf = BSON::ByteBuffer.new
|
14
|
-
# Read 4 byte size of following BSON document
|
15
|
-
bytes = io.read(4)
|
16
|
-
return unless bytes
|
17
|
-
# Read BSON document
|
18
|
-
sz = bytes.unpack("V")[0]
|
19
|
-
bytebuf.append!(bytes)
|
20
|
-
bytes = io.read(sz-4)
|
21
|
-
return unless bytes
|
22
|
-
bytebuf.append!(bytes)
|
23
|
-
return BSON.deserialize(bytebuf)
|
24
|
-
end
|
25
|
-
|
26
10
|
# Simple single threaded server for testing purposes using a local socket
|
27
11
|
# Sends and receives BSON Messages
|
28
12
|
class SimpleServer
|
@@ -33,13 +17,13 @@ class SimpleServer
|
|
33
17
|
# Celluloid::IO::TCPServer here
|
34
18
|
@server = TCPServer.new('127.0.0.1', port)
|
35
19
|
@logger = SemanticLogger::Logger.new(self.class)
|
36
|
-
run
|
20
|
+
async.run
|
37
21
|
end
|
38
22
|
|
39
23
|
def run
|
40
24
|
loop do
|
41
25
|
@logger.debug "Waiting for a client to connect"
|
42
|
-
handle_connection
|
26
|
+
async.handle_connection(@server.accept)
|
43
27
|
end
|
44
28
|
end
|
45
29
|
|
@@ -76,7 +60,7 @@ class SimpleServer
|
|
76
60
|
'registered' => true,
|
77
61
|
'clientid' => '123'
|
78
62
|
}
|
79
|
-
client.write(BSON.serialize(handshake))
|
63
|
+
client.write(BSON.serialize(handshake).to_s)
|
80
64
|
read_bson_document(client)
|
81
65
|
|
82
66
|
while(header = read_bson_document(client)) do
|
@@ -91,17 +75,17 @@ class SimpleServer
|
|
91
75
|
if reply = on_message(request['method'], BSON.deserialize(request['in']))
|
92
76
|
@logger.debug "Sending Header"
|
93
77
|
# For this test we just send back the received header
|
94
|
-
client.write(BSON.serialize(header))
|
78
|
+
client.write(BSON.serialize(header).to_s)
|
95
79
|
|
96
80
|
@logger.debug "Sending Reply"
|
97
81
|
@logger.trace 'Reply', reply
|
98
|
-
client.write(BSON.serialize({'out' => BSON.serialize(reply).to_s}))
|
82
|
+
client.write(BSON.serialize({'out' => BSON.serialize(reply).to_s}).to_s)
|
99
83
|
else
|
100
84
|
@logger.debug "Closing client since no reply is being sent back"
|
101
85
|
@server.close
|
102
86
|
client.close
|
103
87
|
@logger.debug "Server closed"
|
104
|
-
run
|
88
|
+
async.run
|
105
89
|
@logger.debug "Server Restarted"
|
106
90
|
break
|
107
91
|
end
|
@@ -110,6 +94,23 @@ class SimpleServer
|
|
110
94
|
client.close
|
111
95
|
@logger.debug "Disconnected from the client"
|
112
96
|
end
|
97
|
+
|
98
|
+
# Read the bson document, returning nil if the IO is closed
|
99
|
+
# before receiving any data or a complete BSON document
|
100
|
+
def read_bson_document(io)
|
101
|
+
bytebuf = BSON::ByteBuffer.new
|
102
|
+
# Read 4 byte size of following BSON document
|
103
|
+
bytes = io.read(4)
|
104
|
+
return unless bytes
|
105
|
+
# Read BSON document
|
106
|
+
sz = bytes.unpack("V")[0]
|
107
|
+
bytebuf.append!(bytes)
|
108
|
+
bytes = io.read(sz-4)
|
109
|
+
return unless bytes
|
110
|
+
bytebuf.append!(bytes)
|
111
|
+
return BSON.deserialize(bytebuf)
|
112
|
+
end
|
113
|
+
|
113
114
|
end
|
114
115
|
|
115
116
|
if $0 == __FILE__
|
data/test.sh
ADDED
metadata
CHANGED
@@ -1,96 +1,99 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_skynet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.4.0.pre
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Reid Morrison
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2013-03-18 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: semantic_logger
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '>='
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: resilient_socket
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - '>='
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - '>='
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: multi_json
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - '>='
|
52
46
|
- !ruby/object:Gem::Version
|
53
|
-
version:
|
47
|
+
version: 1.6.1
|
54
48
|
type: :runtime
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - '>='
|
60
53
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
54
|
+
version: 1.6.1
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: bson
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- -
|
59
|
+
- - '>='
|
68
60
|
- !ruby/object:Gem::Version
|
69
61
|
version: '0'
|
70
62
|
type: :runtime
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- -
|
66
|
+
- - '>='
|
76
67
|
- !ruby/object:Gem::Version
|
77
68
|
version: '0'
|
78
69
|
- !ruby/object:Gem::Dependency
|
79
70
|
name: ruby_protobuf
|
80
71
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
72
|
requirements:
|
83
|
-
- -
|
73
|
+
- - '>='
|
84
74
|
- !ruby/object:Gem::Version
|
85
75
|
version: '0'
|
86
76
|
type: :runtime
|
87
77
|
prerelease: false
|
88
78
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
79
|
requirements:
|
91
|
-
- -
|
80
|
+
- - '>='
|
92
81
|
- !ruby/object:Gem::Version
|
93
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: celluloid-io
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.13.0.pre2
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.13.0.pre2
|
94
97
|
description: Ruby Client for invoking Skynet services
|
95
98
|
email:
|
96
99
|
- reidmo@gmail.com
|
@@ -103,6 +106,8 @@ files:
|
|
103
106
|
- LICENSE.txt
|
104
107
|
- README.md
|
105
108
|
- Rakefile
|
109
|
+
- examples/echo_client.rb
|
110
|
+
- examples/echo_server.rb
|
106
111
|
- lib/ruby_skynet.rb
|
107
112
|
- lib/ruby_skynet/client.rb
|
108
113
|
- lib/ruby_skynet/common.rb
|
@@ -115,42 +120,33 @@ files:
|
|
115
120
|
- lib/ruby_skynet/server.rb
|
116
121
|
- lib/ruby_skynet/service.rb
|
117
122
|
- lib/ruby_skynet/version.rb
|
118
|
-
-
|
119
|
-
- nbproject/private/private.properties
|
120
|
-
- nbproject/private/private.xml
|
121
|
-
- nbproject/private/rake-d.txt
|
122
|
-
- nbproject/project.properties
|
123
|
-
- nbproject/project.xml
|
124
|
-
- test.log
|
123
|
+
- test.sh
|
125
124
|
- test/doozer_client_test.rb
|
126
125
|
- test/ruby_skynet_client_test.rb
|
127
126
|
- test/ruby_skynet_service_test.rb
|
128
127
|
- test/simple_server.rb
|
129
128
|
homepage: https://github.com/ClarityServices/ruby_skynet
|
130
|
-
licenses:
|
129
|
+
licenses:
|
130
|
+
- Apache License V2.0
|
131
|
+
metadata: {}
|
131
132
|
post_install_message:
|
132
133
|
rdoc_options: []
|
133
134
|
require_paths:
|
134
135
|
- lib
|
135
136
|
required_ruby_version: !ruby/object:Gem::Requirement
|
136
|
-
none: false
|
137
137
|
requirements:
|
138
|
-
- -
|
138
|
+
- - '>='
|
139
139
|
- !ruby/object:Gem::Version
|
140
140
|
version: '0'
|
141
|
-
segments:
|
142
|
-
- 0
|
143
|
-
hash: 434624136862152057
|
144
141
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
|
-
none: false
|
146
142
|
requirements:
|
147
|
-
- -
|
143
|
+
- - '>'
|
148
144
|
- !ruby/object:Gem::Version
|
149
|
-
version:
|
145
|
+
version: 1.3.1
|
150
146
|
requirements: []
|
151
147
|
rubyforge_project:
|
152
|
-
rubygems_version:
|
148
|
+
rubygems_version: 2.0.2
|
153
149
|
signing_key:
|
154
|
-
specification_version:
|
150
|
+
specification_version: 4
|
155
151
|
summary: Skynet Ruby Client
|
156
152
|
test_files: []
|
File without changes
|
@@ -1 +0,0 @@
|
|
1
|
-
platform.active=Ruby_0
|
data/nbproject/project.xml
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
-
<project xmlns="http://www.netbeans.org/ns/project/1">
|
3
|
-
<type>org.netbeans.modules.ruby.rubyproject</type>
|
4
|
-
<configuration>
|
5
|
-
<data xmlns="http://www.netbeans.org/ns/ruby-project/1">
|
6
|
-
<name>ruby_skynet</name>
|
7
|
-
<source-roots>
|
8
|
-
<root id="src.lib.dir" name="Source Files"/>
|
9
|
-
</source-roots>
|
10
|
-
<test-roots>
|
11
|
-
<root id="test.test.dir"/>
|
12
|
-
</test-roots>
|
13
|
-
</data>
|
14
|
-
</configuration>
|
15
|
-
</project>
|
data/test.log
DELETED
Binary file
|