onedrb 0.1.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/onedrb.rb +332 -7
- data.tar.gz.sig +0 -0
- metadata +52 -32
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e484349df963bdb3ab1dafb85fa5697dc9460c330d1f863e8ed723ca941e8fcc
|
4
|
+
data.tar.gz: c58a17ce4eddc48d611115ae13d5dbd97fddd983c3e2ca537b478f4029f663d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96d256270dbc280f69f0e9873787c608132f9ebf45cf20bd06be1a69a2845080e2bd2177d8b35fdce8ca344d6e0edb50c5bf5e3893c6941600c6ec1a3de1fe09
|
7
|
+
data.tar.gz: 4c119540720a72be369dec14c3156fa9f96c849b93df6c49229c14d838cb93846058496d53621a64242b72176ecf8ce800f657339f11c8221affa4f3fc0e373d
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/onedrb.rb
CHANGED
@@ -6,6 +6,60 @@
|
|
6
6
|
|
7
7
|
require 'drb'
|
8
8
|
require 'c32'
|
9
|
+
require 'app-mgr'
|
10
|
+
|
11
|
+
|
12
|
+
# Note: The Server object can also use a default ServiceMgr object.
|
13
|
+
# Which allows multiple services (user-defined objects) to be
|
14
|
+
# hosted dynamically.
|
15
|
+
# OneDrb recommended port: 57844 (as this port is recognised by the RSC gem)
|
16
|
+
#
|
17
|
+
class ServiceMgr < AppMgr
|
18
|
+
|
19
|
+
def initialize(rsf: nil, debug: false)
|
20
|
+
super(rsf: rsf, type: 'service', debug: debug)
|
21
|
+
@services = @app
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
def call(service, methodname, *a)
|
26
|
+
|
27
|
+
return @services[service.to_sym][:running] unless methodname
|
28
|
+
proc1 = @services[service.to_sym][:running].method(methodname.to_sym)
|
29
|
+
a.last.is_a?(Hash) ? proc1.call(*a[0..-2], **a.last) : proc1.call(*a)
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
# OneDRb version 2; Allows multiple user-defined objects to be
|
35
|
+
# served from 1 DRb service
|
36
|
+
#
|
37
|
+
# not used by any client, but may be in future
|
38
|
+
#
|
39
|
+
#def odrb2?()
|
40
|
+
# true
|
41
|
+
#end
|
42
|
+
|
43
|
+
def services()
|
44
|
+
@services.map do |key, object|
|
45
|
+
next unless object[:running]
|
46
|
+
[key, object[:running].public_methods - Object.public_methods]
|
47
|
+
end.compact
|
48
|
+
end
|
49
|
+
|
50
|
+
def stop(service)
|
51
|
+
super(service).sub('app', 'service')
|
52
|
+
end
|
53
|
+
|
54
|
+
def unload(service)
|
55
|
+
super(service).sub('app', 'service')
|
56
|
+
end
|
57
|
+
|
58
|
+
def method_missing(sym, *args)
|
59
|
+
#puts 'servicemgr sym: ' + sym.inspect
|
60
|
+
#puts 'args: ' + args.inspect
|
61
|
+
end
|
62
|
+
end
|
9
63
|
|
10
64
|
|
11
65
|
class OneDrbError < Exception
|
@@ -17,21 +71,21 @@ module OneDrb
|
|
17
71
|
class Server
|
18
72
|
using ColouredText
|
19
73
|
|
20
|
-
def initialize(host: '127.0.0.1', port: (49152..65535).to_a.sample.to_s,
|
74
|
+
def initialize(host: '127.0.0.1', port: (49152..65535).to_a.sample.to_s,
|
21
75
|
obj: nil, log: nil)
|
22
76
|
|
23
77
|
log.info self.class.to_s + '/initialize: active' if log
|
24
|
-
|
78
|
+
|
25
79
|
@host, @port, @log = host, port, log
|
26
80
|
|
27
81
|
if obj then
|
28
|
-
@obj = obj
|
82
|
+
@obj = obj
|
29
83
|
else
|
30
84
|
msg = "No object supplied!".error
|
31
85
|
puts msg
|
32
86
|
raise OneDrbError, msg
|
33
87
|
end
|
34
|
-
|
88
|
+
|
35
89
|
log.info self.class.to_s +'/initialize: completed' if log
|
36
90
|
|
37
91
|
end
|
@@ -50,7 +104,7 @@ module OneDrb
|
|
50
104
|
|
51
105
|
class Client
|
52
106
|
using ColouredText
|
53
|
-
|
107
|
+
|
54
108
|
def initialize(host: '127.0.0.1', port: nil)
|
55
109
|
|
56
110
|
DRb.start_service
|
@@ -59,13 +113,284 @@ module OneDrb
|
|
59
113
|
|
60
114
|
puts ('client connecting to port ' + port).info
|
61
115
|
@obj = DRbObject.new_with_uri("druby://#{host}:#{port}")
|
116
|
+
parent = self
|
117
|
+
@obj&.services.each do |name, methods|
|
118
|
+
|
119
|
+
make_class(name, methods)
|
120
|
+
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|
124
|
+
|
125
|
+
# Makes a remote call in 1 line of code using a URI
|
126
|
+
# Only available when using the ServiceMgr as the server object;
|
127
|
+
#
|
128
|
+
# e.g. OneDrb::Client.call 'odrb://clara.home/fun/go?arg=James&age=49'
|
129
|
+
#
|
130
|
+
def self.call(s, port: nil)
|
131
|
+
|
132
|
+
r = s.match(/^odrb:\/\/([^\/]+)\/([^\/]+)\/([^\?]+)\??(.*)/).captures
|
133
|
+
|
134
|
+
rawhostname, service, methodname, rawargs = r
|
135
|
+
hostname, rawport = rawhostname.split(':',2)
|
136
|
+
port ||= rawport
|
137
|
+
|
138
|
+
rawargs2 = rawargs&.split('&').map {|x| x.split('=')}
|
139
|
+
|
140
|
+
a1, a2 = rawargs2.partition do |field, value|
|
141
|
+
field.downcase.to_sym == :arg
|
142
|
+
end
|
143
|
+
|
144
|
+
h = a2.map {|k,v| [k.to_sym, v]}.to_h
|
145
|
+
a = a1.map(&:last)
|
146
|
+
|
147
|
+
client = OneDrb::Client.new host: hostname, port: port
|
148
|
+
|
149
|
+
if h.any? then
|
150
|
+
|
151
|
+
if a.any? then
|
152
|
+
client.call service.to_sym, methodname.to_sym, *a, **h
|
153
|
+
else
|
154
|
+
client.call service.to_sym, methodname.to_sym, **h
|
155
|
+
end
|
156
|
+
|
157
|
+
elsif a.any?
|
158
|
+
|
159
|
+
client.call service.to_sym, methodname.to_sym, *a
|
160
|
+
|
161
|
+
else
|
162
|
+
|
163
|
+
client.call service.to_sym, methodname.to_sym
|
164
|
+
|
165
|
+
end
|
62
166
|
|
63
167
|
end
|
64
168
|
|
169
|
+
def remote()
|
170
|
+
@obj
|
171
|
+
end
|
172
|
+
|
173
|
+
def restart(service)
|
174
|
+
|
175
|
+
return unless @obj.respond_to? :services
|
176
|
+
|
177
|
+
@obj.restart(service)
|
178
|
+
found = @obj.services.assoc(service)
|
179
|
+
make_class(*found) if found.any?
|
180
|
+
end
|
181
|
+
|
65
182
|
def method_missing(sym, *args)
|
66
|
-
|
183
|
+
|
184
|
+
if args.last.is_a?(Hash) then
|
185
|
+
@obj.send(sym, *args[0..-2], **args.last)
|
186
|
+
else
|
187
|
+
@obj.send(sym, *args)
|
188
|
+
end
|
189
|
+
|
67
190
|
end
|
68
191
|
|
69
|
-
|
192
|
+
private
|
193
|
+
|
194
|
+
def make_class(name, methods)
|
195
|
+
|
196
|
+
class_name = name.capitalize
|
197
|
+
klass = Object.const_set(class_name,Class.new)
|
198
|
+
|
199
|
+
klass.class_eval do
|
200
|
+
methods.each do |method_name|
|
201
|
+
define_method method_name do |*args|
|
202
|
+
parent.call name, method_name, *args
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
define_singleton_method name do
|
208
|
+
klass.new
|
209
|
+
end
|
210
|
+
|
211
|
+
end
|
212
|
+
|
213
|
+
end
|
214
|
+
|
215
|
+
end
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
# Note: The Server object can also use a default ServiceMgr object.
|
220
|
+
# Which allows multiple services (user-defined objects) to be
|
221
|
+
# hosted dynamically.
|
222
|
+
|
223
|
+
|
224
|
+
class ServiceMgr
|
225
|
+
|
226
|
+
def initialize()
|
227
|
+
@services = {}
|
228
|
+
end
|
229
|
+
|
230
|
+
|
231
|
+
def call(service, methodname, *a)
|
232
|
+
|
233
|
+
proc1 = @services[service.to_sym].method(methodname.to_sym)
|
234
|
+
a.last.is_a?(Hash) ? proc1.call(*a[0..-2], **a.last) : proc1.call(*a)
|
235
|
+
|
236
|
+
end
|
237
|
+
|
238
|
+
def [](key)
|
239
|
+
@services[key]
|
240
|
+
end
|
241
|
+
|
242
|
+
def []=(key, value)
|
243
|
+
@services[key] = value
|
244
|
+
|
245
|
+
define_singleton_method key do
|
246
|
+
@services[key]
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
def services()
|
251
|
+
@services.map do |key, object|
|
252
|
+
[key, object.public_methods - Object.public_methods]
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
def method_missing(sym, *args)
|
257
|
+
puts 'servicemgr sym: ' + sym.inspect
|
258
|
+
puts 'args: ' + args.inspect
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
|
263
|
+
class OneDrbError < Exception
|
264
|
+
end
|
265
|
+
|
266
|
+
|
267
|
+
module OneDrb
|
268
|
+
|
269
|
+
class Server
|
270
|
+
using ColouredText
|
271
|
+
|
272
|
+
def initialize(host: '127.0.0.1', port: (49152..65535).to_a.sample.to_s,
|
273
|
+
obj: ServiceMgr.new, log: nil)
|
274
|
+
|
275
|
+
log.info self.class.to_s + '/initialize: active' if log
|
276
|
+
|
277
|
+
@host, @port, @log = host, port, log
|
278
|
+
|
279
|
+
if obj then
|
280
|
+
@obj = obj
|
281
|
+
else
|
282
|
+
msg = "No object supplied!".error
|
283
|
+
puts msg
|
284
|
+
raise OneDrbError, msg
|
285
|
+
end
|
286
|
+
|
287
|
+
log.info self.class.to_s +'/initialize: completed' if log
|
288
|
+
|
289
|
+
end
|
290
|
+
|
291
|
+
def start()
|
292
|
+
|
293
|
+
@log.info self.class.to_s +'/start: active' if @log
|
294
|
+
puts (self.class.to_s + " running on port " + @port).info
|
295
|
+
DRb.start_service "druby://#{@host}:#{@port}", @obj
|
296
|
+
DRb.thread.join
|
297
|
+
|
298
|
+
end
|
299
|
+
|
300
|
+
end
|
301
|
+
|
302
|
+
|
303
|
+
class Client
|
304
|
+
using ColouredText
|
305
|
+
|
306
|
+
def initialize(host: '127.0.0.1', port: nil)
|
307
|
+
|
308
|
+
DRb.start_service
|
309
|
+
|
310
|
+
puts 'no port supplied'.error unless port
|
311
|
+
|
312
|
+
puts ('client connecting to port ' + port).info
|
313
|
+
@obj = DRbObject.new_with_uri("druby://#{host}:#{port}")
|
314
|
+
parent = self
|
315
|
+
@obj&.services.each do |name, methods|
|
316
|
+
|
317
|
+
class_name = name.capitalize
|
318
|
+
klass = Object.const_set(class_name,Class.new)
|
319
|
+
|
320
|
+
klass.class_eval do
|
321
|
+
methods.each do |method_name|
|
322
|
+
define_method method_name do |*args|
|
323
|
+
parent.call name, method_name, *args
|
324
|
+
end
|
325
|
+
end
|
326
|
+
end
|
327
|
+
|
328
|
+
define_singleton_method name do
|
329
|
+
klass.new
|
330
|
+
end
|
331
|
+
|
332
|
+
end
|
333
|
+
|
334
|
+
end
|
335
|
+
|
336
|
+
# Makes a remote call in 1 line of code using a URI
|
337
|
+
# e.g. OneDrb::Client.call 'odrb://clara.home/fun/go?arg=James&age=49'
|
338
|
+
#
|
339
|
+
def self.call(s, port: nil)
|
340
|
+
|
341
|
+
r = s.match(/^odrb:\/\/([^\/]+)\/([^\/]+)\/([^\?]+)\??(.*)/).captures
|
342
|
+
|
343
|
+
rawhostname, service, methodname, rawargs = r
|
344
|
+
hostname, rawport = rawhostname.split(':',2)
|
345
|
+
port ||= rawport
|
346
|
+
|
347
|
+
rawargs2 = rawargs&.split('&').map {|x| x.split('=')}
|
348
|
+
|
349
|
+
a1, a2 = rawargs2.partition do |field, value|
|
350
|
+
field.downcase.to_sym == :arg
|
351
|
+
end
|
352
|
+
|
353
|
+
h = a2.map {|k,v| [k.to_sym, v]}.to_h
|
354
|
+
a = a1.map(&:last)
|
355
|
+
|
356
|
+
client = OneDrb::Client.new host: hostname, port: port
|
357
|
+
|
358
|
+
if h.any? then
|
359
|
+
|
360
|
+
if a.any? then
|
361
|
+
client.call service.to_sym, methodname.to_sym, *a, **h
|
362
|
+
else
|
363
|
+
client.call service.to_sym, methodname.to_sym, **h
|
364
|
+
end
|
365
|
+
|
366
|
+
elsif a.any?
|
367
|
+
|
368
|
+
client.call service.to_sym, methodname.to_sym, *a
|
369
|
+
|
370
|
+
else
|
371
|
+
|
372
|
+
client.call service.to_sym, methodname.to_sym
|
373
|
+
|
374
|
+
end
|
375
|
+
|
376
|
+
end
|
377
|
+
|
378
|
+
def remote()
|
379
|
+
@obj
|
380
|
+
end
|
381
|
+
|
382
|
+
def method_missing(sym, *args)
|
383
|
+
|
384
|
+
puts '@obj.class: ' + @obj.class.inspect
|
385
|
+
|
386
|
+
if args.last.is_a?(Hash) then
|
387
|
+
@obj.send(sym, *args[0..-2], **args.last)
|
388
|
+
else
|
389
|
+
@obj.send(sym, *args)
|
390
|
+
end
|
391
|
+
|
392
|
+
end
|
393
|
+
|
394
|
+
end
|
70
395
|
|
71
396
|
end
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: onedrb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -11,54 +11,74 @@ cert_chain:
|
|
11
11
|
- |
|
12
12
|
-----BEGIN CERTIFICATE-----
|
13
13
|
MIIEXjCCAsagAwIBAgIBATANBgkqhkiG9w0BAQsFADAsMSowKAYDVQQDDCFnZW1t
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
14
|
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
|
34
|
-
|
35
|
-
|
36
|
-
|
28
|
+
BgkqhkiG9w0BAQsFAAOCAYEANcUl8rOFNRz6Pk3OarkDKv+0VAZtc+YR6rfFj7Ws
|
29
|
+
OH9f1eIEmyyDQBTN17VYXLvI3FlewJcbkr5u9DV62W80cbzkC27nSU6kicaAh7C3
|
30
|
+
cqgGd084jS7DF8+7RhVO5QBFKwmYCCr5yseUmIW5KtPcR0ey36X3PWHPQfHap1h5
|
31
|
+
vp6PdlpxEON8RhJ2UVUIPFFTr3Y8TYu0ya7Q0E7oPqor6tuJGtRsT3HMEGT5/KPd
|
32
|
+
ccHI65ygp/STtdROe5WVPmU+PafUoCRtGUHR6m5Petdsy7xDsPRW7HfGb95BFj6t
|
33
|
+
m/Wdnbmg9hmU6coqbogGGnS+4SvRuRlBRI6NeGB5/p6/zj7snat1hdAp9kPyakBm
|
34
|
+
jjhW5l95yuhsvvVMD684GS3sVVSbOTCtbZpvYDn9IoG0mutmqFU6Y2jMBHO/aZd9
|
35
|
+
lK7OtCGPauDHVuIWDW0EnHb+MMBt6F5SqC+PSy9iOzs4zAWkJMFp86MOEK2yrfnO
|
36
|
+
/ghrVtneK08DqmYOaive8I6P
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date:
|
38
|
+
date: 2022-04-24 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: c32
|
42
42
|
requirement: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
|
-
- - ">="
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: 0.2.0
|
47
44
|
- - "~>"
|
48
45
|
- !ruby/object:Gem::Version
|
49
|
-
version: '0.
|
46
|
+
version: '0.3'
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 0.3.0
|
50
50
|
type: :runtime
|
51
51
|
prerelease: false
|
52
52
|
version_requirements: !ruby/object:Gem::Requirement
|
53
53
|
requirements:
|
54
|
+
- - "~>"
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0.3'
|
54
57
|
- - ">="
|
55
58
|
- !ruby/object:Gem::Version
|
56
|
-
version: 0.
|
59
|
+
version: 0.3.0
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: app-mgr
|
62
|
+
requirement: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
57
64
|
- - "~>"
|
58
65
|
- !ruby/object:Gem::Version
|
59
|
-
version: '0.
|
66
|
+
version: '0.4'
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 0.4.0
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - "~>"
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0.4'
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: 0.4.0
|
60
80
|
description:
|
61
|
-
email:
|
81
|
+
email: digital.robertson@gmail.com
|
62
82
|
executables: []
|
63
83
|
extensions: []
|
64
84
|
extra_rdoc_files: []
|
@@ -83,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
103
|
- !ruby/object:Gem::Version
|
84
104
|
version: '0'
|
85
105
|
requirements: []
|
86
|
-
rubygems_version: 3.
|
106
|
+
rubygems_version: 3.2.22
|
87
107
|
signing_key:
|
88
108
|
specification_version: 4
|
89
109
|
summary: Makes it convenient to make an object remotely accessible.
|
metadata.gz.sig
CHANGED
Binary file
|