pipe_rpc 2.4.0 → 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pipe_rpc/_pipe_rpc.rb +14 -0
- data/lib/pipe_rpc/basic_interface.rb +28 -4
- data/lib/pipe_rpc/client.rb +12 -3
- data/lib/pipe_rpc/client_request_error_response.rb +1 -1
- data/lib/pipe_rpc/client_wrapper.rb +29 -0
- data/lib/pipe_rpc/gateway.rb +10 -6
- data/lib/pipe_rpc/hub.rb +4 -4
- data/lib/pipe_rpc/hub_servers.rb +1 -1
- data/lib/pipe_rpc/hub_transport_mapper.rb +6 -5
- data/lib/pipe_rpc/servable.rb +32 -0
- data/lib/pipe_rpc/server.rb +15 -5
- data/lib/pipe_rpc/subject_server.rb +39 -0
- data/lib/pipe_rpc/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0b220bb6af80445f30658013667fa408749b8c4
|
4
|
+
data.tar.gz: 3df1bab18503474475c842ae78db2e9c6bcec98a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c114586ee4dd7873b17ec13a083cc57cdc1d00cc496bed4a857d2f82b60969646bbafdaad3e12095f4e5537054118970db2ec4944a0dd1821ee06d48af25464b
|
7
|
+
data.tar.gz: 83e3feddd8530083ff24eeb73fc05cdd6cf1c594bb4faf5ad7d216141145fe662b7b4b91da61d3de4c87d9a2f404d32b0a1eba06b5de419b6b28bd9b4284b154
|
data/lib/pipe_rpc/_pipe_rpc.rb
CHANGED
@@ -15,4 +15,18 @@ Module.class_eval do
|
|
15
15
|
private_methods = (respond_to? :private_instance_methods) ? private_instance_methods : []
|
16
16
|
instance_methods + private_methods
|
17
17
|
end
|
18
|
+
|
19
|
+
if const_defined? :MRUBY_VERSION
|
20
|
+
alias_method :simple_const_get, :const_get
|
21
|
+
|
22
|
+
def const_get(constant_path, *args)
|
23
|
+
if constant_path.is_a? String
|
24
|
+
constant_path.split('::').inject(self) do |mod, constant|
|
25
|
+
mod.simple_const_get(constant.to_sym, *args)
|
26
|
+
end
|
27
|
+
else
|
28
|
+
simple_const_get(constant_path, *args)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
18
32
|
end
|
@@ -1,7 +1,29 @@
|
|
1
1
|
module PipeRpc
|
2
2
|
class BasicInterface < BasicObject
|
3
|
-
|
4
|
-
|
3
|
+
class << self
|
4
|
+
def const_missing(name)
|
5
|
+
::Object.const_get(name)
|
6
|
+
end
|
7
|
+
|
8
|
+
def instance_eval_for(object, *args, &block)
|
9
|
+
BasicInterface.add_instance_eval
|
10
|
+
object.instance_eval(*args, &block)
|
11
|
+
ensure
|
12
|
+
BasicInterface.remove_instance_eval
|
13
|
+
end
|
14
|
+
|
15
|
+
def remove_instance_eval
|
16
|
+
class_eval do
|
17
|
+
def instance_eval(*args)
|
18
|
+
caller = (Kernel.respond_to? :caller) ? [Kernel.caller(1)] : nil
|
19
|
+
Kernel.raise ::NoMethodError, "undefined method `instance_eval'", *caller
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def add_instance_eval
|
25
|
+
__send__(:remove_method, :instance_eval)
|
26
|
+
end
|
5
27
|
end
|
6
28
|
|
7
29
|
wanted_methods = [:initialize, :__id__, :object_id, :__send__, :respond_to?, :method_missing]
|
@@ -9,9 +31,11 @@ module PipeRpc
|
|
9
31
|
|
10
32
|
existing_methods = BasicObject.all_instance_methods
|
11
33
|
|
12
|
-
# Remove unwanted methods
|
34
|
+
# Remove unwanted methods (while treating #instance_eval specially so we
|
35
|
+
# can selectively use it)
|
13
36
|
unwanted_methods = existing_methods - wanted_methods
|
14
|
-
unwanted_methods.each { |m| undef_method m }
|
37
|
+
(unwanted_methods - [:instance_eval]).each { |m| undef_method m }
|
38
|
+
remove_instance_eval
|
15
39
|
|
16
40
|
# Add non-existing methods by including sorted out Kernel module
|
17
41
|
include Kernel.dup_including *(wanted_methods - existing_methods)
|
data/lib/pipe_rpc/client.rb
CHANGED
@@ -2,6 +2,8 @@ module PipeRpc
|
|
2
2
|
class Client < BasicInterface
|
3
3
|
TRANSPORT_PREFIX = "__rpc_client__"
|
4
4
|
|
5
|
+
undef_method :instance_eval
|
6
|
+
|
5
7
|
def initialize(server_id = :default, hub)
|
6
8
|
Kernel.raise ClientInitializationError.new("server id #{server_id.inspect} no symbol") unless server_id.is_a? Symbol
|
7
9
|
@__rpc_server_id__ = server_id
|
@@ -11,8 +13,8 @@ module PipeRpc
|
|
11
13
|
|
12
14
|
attr_reader :__rpc_server_class_name__, :__rpc_server_id__
|
13
15
|
|
14
|
-
def respond_to?(
|
15
|
-
super or method_missing(:respond_to?,
|
16
|
+
def respond_to?(*args)
|
17
|
+
super or method_missing(:respond_to?, *args)
|
16
18
|
end
|
17
19
|
|
18
20
|
def method_missing(method, *args)
|
@@ -20,8 +22,15 @@ module PipeRpc
|
|
20
22
|
@hub.requests.evaluate(request)
|
21
23
|
end
|
22
24
|
|
23
|
-
def to_rpc_transport(
|
25
|
+
def to_rpc_transport(gateway)
|
24
26
|
"#{TRANSPORT_PREFIX}#{@__rpc_server_id__}"
|
25
27
|
end
|
26
28
|
end
|
29
|
+
|
30
|
+
class << Client
|
31
|
+
def from_rpc_transport(gateway, transport)
|
32
|
+
client = gateway.clients[transport.sub(Server::TRANSPORT_PREFIX, '').to_sym]
|
33
|
+
ClientWrapper.from_rpc_transport(gateway, client)
|
34
|
+
end
|
35
|
+
end
|
27
36
|
end
|
@@ -21,7 +21,7 @@ module PipeRpc
|
|
21
21
|
private
|
22
22
|
|
23
23
|
def no_method_error
|
24
|
-
NoMethodError.new("undefined method `#{@data.fetch(:method)}' for
|
24
|
+
NoMethodError.new("undefined method `#{@data.fetch(:method)}' for #{@request.server}")
|
25
25
|
end
|
26
26
|
|
27
27
|
def argument_error
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module PipeRpc
|
2
|
+
module ClientWrappers; end
|
3
|
+
|
4
|
+
class ClientWrapper < BasicInterface
|
5
|
+
def initialize(gateway, client)
|
6
|
+
@client = client
|
7
|
+
@gateway = gateway
|
8
|
+
end
|
9
|
+
|
10
|
+
def inspect
|
11
|
+
__rpc_server_id__
|
12
|
+
end
|
13
|
+
alias to_s inspect
|
14
|
+
|
15
|
+
def method_missing(method, *args)
|
16
|
+
@client.__send__(method, *args)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class << ClientWrapper
|
21
|
+
def from_rpc_transport(gateway, client)
|
22
|
+
if gateway.client_wrapper_class_namespace.const_defined?(client.__rpc_server_class_name__, false)
|
23
|
+
gateway.client_wrapper_class_namespace.const_get(client.__rpc_server_class_name__, false).new(gateway, client)
|
24
|
+
else
|
25
|
+
client
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/pipe_rpc/gateway.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
module PipeRpc
|
2
2
|
class Gateway
|
3
|
-
def initialize(
|
4
|
-
@hub = Hub.new(
|
3
|
+
def initialize(channels)
|
4
|
+
@hub = Hub.new(self, channels)
|
5
|
+
@client_wrapper_class_namespace = ClientWrappers
|
6
|
+
@subject_server_class_namespace = SubjectServers
|
5
7
|
end
|
6
8
|
|
9
|
+
attr_accessor :client_wrapper_class_namespace, :subject_server_class_namespace
|
10
|
+
|
7
11
|
def channel
|
8
12
|
@hub.channel
|
9
13
|
end
|
@@ -20,6 +24,10 @@ module PipeRpc
|
|
20
24
|
@hub.requests.wait_for_results_through(iteration)
|
21
25
|
end
|
22
26
|
|
27
|
+
def handle_message
|
28
|
+
@hub.handle_message
|
29
|
+
end
|
30
|
+
|
23
31
|
def on_sent(&on_sent)
|
24
32
|
@hub.socket.on_sent(&on_sent)
|
25
33
|
end
|
@@ -39,9 +47,5 @@ module PipeRpc
|
|
39
47
|
def close(reason = 'manually closed')
|
40
48
|
@hub.socket.close(reason)
|
41
49
|
end
|
42
|
-
|
43
|
-
def handle_message
|
44
|
-
@hub.handle_message
|
45
|
-
end
|
46
50
|
end
|
47
51
|
end
|
data/lib/pipe_rpc/hub.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
module PipeRpc
|
2
2
|
class Hub
|
3
|
-
def initialize(
|
4
|
-
@channel =
|
5
|
-
@socket = Socket.new(self,
|
3
|
+
def initialize(gateway, channels)
|
4
|
+
@channel = channels[:input]
|
5
|
+
@socket = Socket.new(self, channels)
|
6
6
|
@requests = Requests.new(self)
|
7
7
|
@servers = Servers.new
|
8
8
|
@clients = Clients.new(self)
|
9
|
-
@transport_mapper = TransportMapper.new(
|
9
|
+
@transport_mapper = TransportMapper.new(gateway)
|
10
10
|
end
|
11
11
|
|
12
12
|
attr_reader :channel, :servers, :clients, :requests, :socket, :transport_mapper
|
data/lib/pipe_rpc/hub_servers.rb
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
module PipeRpc
|
2
2
|
class Mapper; end
|
3
|
+
|
3
4
|
class Hub::TransportMapper < Mapper
|
4
|
-
def initialize(
|
5
|
-
@
|
5
|
+
def initialize(gateway)
|
6
|
+
@gateway = gateway
|
6
7
|
end
|
7
8
|
|
8
9
|
def to_transport(object)
|
9
10
|
map(object) do |value|
|
10
11
|
if value.respond_to? :to_rpc_transport
|
11
|
-
value.to_rpc_transport(@
|
12
|
+
value.to_rpc_transport(@gateway)
|
12
13
|
else
|
13
14
|
value
|
14
15
|
end
|
@@ -18,9 +19,9 @@ module PipeRpc
|
|
18
19
|
def from_transport(object)
|
19
20
|
map(object) do |value|
|
20
21
|
if (value.is_a? String) and (value.start_with? Client::TRANSPORT_PREFIX)
|
21
|
-
|
22
|
+
Server.from_rpc_transport(@gateway, value)
|
22
23
|
elsif (value.is_a? String) and (value.start_with? Server::TRANSPORT_PREFIX)
|
23
|
-
|
24
|
+
Client.from_rpc_transport(@gateway, value)
|
24
25
|
else
|
25
26
|
value
|
26
27
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module PipeRpc
|
2
|
+
module Servable
|
3
|
+
def self.included(klass)
|
4
|
+
klass.extend ClassMethods
|
5
|
+
end
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
def rpc_server_class_name
|
9
|
+
to_s
|
10
|
+
end
|
11
|
+
|
12
|
+
def __rpc_server_class_name__
|
13
|
+
"#{rpc_server_class_name}".tap do |class_name|
|
14
|
+
class_name << 'Class' if is_a? Class
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def __rpc_server_class_name__
|
20
|
+
self.class.rpc_server_class_name
|
21
|
+
end
|
22
|
+
|
23
|
+
def rpc_server_instance_id
|
24
|
+
__id__
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_rpc_transport(gateway)
|
28
|
+
server_class = gateway.subject_server_class_namespace.const_get(__rpc_server_class_name__, false)
|
29
|
+
server_class.new(self).to_rpc_transport(gateway)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/pipe_rpc/server.rb
CHANGED
@@ -9,19 +9,29 @@ module PipeRpc
|
|
9
9
|
__class__.to_s
|
10
10
|
end
|
11
11
|
|
12
|
+
def __rpc_server_instance_id__
|
13
|
+
__id__.to_s
|
14
|
+
end
|
15
|
+
|
12
16
|
def __rpc_server_id__
|
13
|
-
|
17
|
+
@__rpc_server_id__ ||= [__rpc_server_class_name__, *__rpc_server_instance_id__].join('#').to_sym
|
18
|
+
end
|
19
|
+
|
20
|
+
def inspect
|
21
|
+
__rpc_server_id__
|
14
22
|
end
|
23
|
+
alias to_s inspect
|
15
24
|
|
16
|
-
def to_rpc_transport(
|
17
|
-
|
25
|
+
def to_rpc_transport(gateway)
|
26
|
+
gateway.servers.add(self) unless gateway.servers.registered? __rpc_server_id__
|
18
27
|
"#{TRANSPORT_PREFIX}#{__rpc_server_id__}"
|
19
28
|
end
|
20
29
|
end
|
21
30
|
|
22
31
|
class << Server
|
23
|
-
def
|
24
|
-
|
32
|
+
def from_rpc_transport(gateway, transport)
|
33
|
+
server = gateway.servers[transport.sub(Client::TRANSPORT_PREFIX, '').to_sym]
|
34
|
+
SubjectServer.from_rpc_transport(gateway, server)
|
25
35
|
end
|
26
36
|
end
|
27
37
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module PipeRpc
|
2
|
+
module SubjectServers; end
|
3
|
+
|
4
|
+
class SubjectServer < Server
|
5
|
+
def initialize(server_subject)
|
6
|
+
@server_subject = server_subject
|
7
|
+
end
|
8
|
+
|
9
|
+
def __rpc_server_class_name__
|
10
|
+
if @server_subject.respond_to? :__rpc_server_class_name__
|
11
|
+
@server_subject.__rpc_server_class_name__
|
12
|
+
elsif @server_subject.is_a? Module
|
13
|
+
@server_subject.to_s
|
14
|
+
else
|
15
|
+
@server_subject.class.to_s
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def __rpc_server_instance_id__
|
20
|
+
if @server_subject.respond_to? :rpc_server_instance_id
|
21
|
+
@server_subject.rpc_server_instance_id
|
22
|
+
elsif @server_subject.is_a? Module
|
23
|
+
nil
|
24
|
+
else
|
25
|
+
@server_subject.__id__.to_s
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class << SubjectServer
|
31
|
+
def from_rpc_transport(gateway, server)
|
32
|
+
if self === server
|
33
|
+
instance_eval_for(server, '@server_subject')
|
34
|
+
else
|
35
|
+
server
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/pipe_rpc/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pipe_rpc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christopher Aue
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-10-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: msgpack
|
@@ -106,6 +106,7 @@ files:
|
|
106
106
|
- lib/pipe_rpc/client_request_response.rb
|
107
107
|
- lib/pipe_rpc/client_request_result.rb
|
108
108
|
- lib/pipe_rpc/client_request_result_response.rb
|
109
|
+
- lib/pipe_rpc/client_wrapper.rb
|
109
110
|
- lib/pipe_rpc/error.rb
|
110
111
|
- lib/pipe_rpc/error_response.rb
|
111
112
|
- lib/pipe_rpc/gateway.rb
|
@@ -124,7 +125,9 @@ files:
|
|
124
125
|
- lib/pipe_rpc/mapper.rb
|
125
126
|
- lib/pipe_rpc/request.rb
|
126
127
|
- lib/pipe_rpc/result_response.rb
|
128
|
+
- lib/pipe_rpc/servable.rb
|
127
129
|
- lib/pipe_rpc/server.rb
|
130
|
+
- lib/pipe_rpc/subject_server.rb
|
128
131
|
- lib/pipe_rpc/version.rb
|
129
132
|
- pipe_rpc.gemspec
|
130
133
|
homepage: https://github.com/christopheraue/ruby-pipe_rpc
|