sumac 0.0.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 +7 -0
- data/LICENSE +201 -0
- data/README.md +2 -0
- data/lib/core_extensions.rb +207 -0
- data/lib/sumac.rb +94 -0
- data/lib/sumac/adapter.rb +5 -0
- data/lib/sumac/adapter/closed.rb +7 -0
- data/lib/sumac/argument_error.rb +5 -0
- data/lib/sumac/call_dispatcher.rb +70 -0
- data/lib/sumac/call_processor.rb +93 -0
- data/lib/sumac/closed_error.rb +5 -0
- data/lib/sumac/closer.rb +53 -0
- data/lib/sumac/connection.rb +94 -0
- data/lib/sumac/exposed_object.rb +131 -0
- data/lib/sumac/exposed_object_child.rb +158 -0
- data/lib/sumac/forgoten.rb +5 -0
- data/lib/sumac/handshake.rb +48 -0
- data/lib/sumac/id_allocator.rb +99 -0
- data/lib/sumac/local_reference.rb +16 -0
- data/lib/sumac/local_references.rb +80 -0
- data/lib/sumac/message.rb +19 -0
- data/lib/sumac/message/exchange.rb +30 -0
- data/lib/sumac/message/exchange/base.rb +15 -0
- data/lib/sumac/message/exchange/call_request.rb +96 -0
- data/lib/sumac/message/exchange/call_response.rb +83 -0
- data/lib/sumac/message/exchange/compatibility_notification.rb +53 -0
- data/lib/sumac/message/exchange/forget_notification.rb +77 -0
- data/lib/sumac/message/exchange/id.rb +30 -0
- data/lib/sumac/message/exchange/initialization_notification.rb +52 -0
- data/lib/sumac/message/exchange/notification.rb +9 -0
- data/lib/sumac/message/exchange/shutdown_notification.rb +27 -0
- data/lib/sumac/message/object.rb +72 -0
- data/lib/sumac/message/object/array.rb +57 -0
- data/lib/sumac/message/object/base.rb +21 -0
- data/lib/sumac/message/object/boolean.rb +45 -0
- data/lib/sumac/message/object/exception.rb +66 -0
- data/lib/sumac/message/object/exposed.rb +79 -0
- data/lib/sumac/message/object/exposed_child.rb +86 -0
- data/lib/sumac/message/object/float.rb +45 -0
- data/lib/sumac/message/object/hash_table.rb +75 -0
- data/lib/sumac/message/object/integer.rb +45 -0
- data/lib/sumac/message/object/native_exception.rb +56 -0
- data/lib/sumac/message/object/null.rb +44 -0
- data/lib/sumac/message/object/string.rb +45 -0
- data/lib/sumac/message_error.rb +5 -0
- data/lib/sumac/messenger.rb +65 -0
- data/lib/sumac/native_error.rb +17 -0
- data/lib/sumac/no_method_error.rb +9 -0
- data/lib/sumac/reference.rb +68 -0
- data/lib/sumac/remote_entry.rb +42 -0
- data/lib/sumac/remote_object.rb +39 -0
- data/lib/sumac/remote_object_child.rb +38 -0
- data/lib/sumac/remote_reference.rb +16 -0
- data/lib/sumac/remote_references.rb +70 -0
- data/lib/sumac/scheduler.rb +56 -0
- data/lib/sumac/shutdown.rb +32 -0
- data/lib/sumac/stale_object_error.rb +5 -0
- data/lib/sumac/unexposable_object_error.rb +9 -0
- data/lib/sumac/worker_pool.rb +35 -0
- data/test/test_id_allocator.rb +25 -0
- metadata +145 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
class Sumac
|
|
2
|
+
class Message
|
|
3
|
+
class Exchange
|
|
4
|
+
class CallRequest < Base
|
|
5
|
+
include ID
|
|
6
|
+
|
|
7
|
+
def initialize(connection)
|
|
8
|
+
super
|
|
9
|
+
@exposed_object = nil
|
|
10
|
+
@child = nil
|
|
11
|
+
@method_name = nil
|
|
12
|
+
@arguments = nil
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def parse_json_structure(json_structure)
|
|
16
|
+
raise MessageError unless json_structure.is_a?(Hash) &&
|
|
17
|
+
json_structure['message_type'] == 'exchange' &&
|
|
18
|
+
json_structure['exchange_type'] == 'call_request'
|
|
19
|
+
raise MessageError unless json_structure['id'].is_a?(Integer)
|
|
20
|
+
@id = json_structure['id']
|
|
21
|
+
exposed_object = Object.from_json_structure(@connection, json_structure['exposed_object'])
|
|
22
|
+
raise MessageError unless exposed_object.is_a?(Object::Exposed) || exposed_object.is_a?(Object::ExposedChild)
|
|
23
|
+
@exposed_object = exposed_object
|
|
24
|
+
raise MessageError unless json_structure['method_name'].is_a?(String)
|
|
25
|
+
@method_name = json_structure['method_name']
|
|
26
|
+
raise MessageError unless json_structure['arguments'].is_a?(Array)
|
|
27
|
+
@arguments = json_structure['arguments'].map do |argument_json_structure|
|
|
28
|
+
Object.from_json_structure(@connection, argument_json_structure)
|
|
29
|
+
end
|
|
30
|
+
nil
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def to_json_structure
|
|
34
|
+
raise unless setup?
|
|
35
|
+
{
|
|
36
|
+
'message_type' => 'exchange',
|
|
37
|
+
'exchange_type' => 'call_request',
|
|
38
|
+
'id' => @id,
|
|
39
|
+
'exposed_object' => @exposed_object.to_json_structure,
|
|
40
|
+
'method_name' => @method_name,
|
|
41
|
+
'arguments' => @arguments.map(&:to_json_structure)
|
|
42
|
+
}
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def exposed_object
|
|
46
|
+
raise MessageError unless setup?
|
|
47
|
+
@exposed_object.to_native_object
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def exposed_object=(new_exposed_object)
|
|
51
|
+
unless new_exposed_object.is_a?(RemoteObject) || new_exposed_object.is_a?(RemoteObjectChild) ||
|
|
52
|
+
new_exposed_object.respond_to?(:__sumac_exposed_object__)
|
|
53
|
+
raise MessageError
|
|
54
|
+
end
|
|
55
|
+
@exposed_object = Object.from_native_object(@connection, new_exposed_object)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def method_name
|
|
59
|
+
raise MessageError unless setup?
|
|
60
|
+
@method_name
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def method_name=(new_method_name)
|
|
64
|
+
raise MessageError unless new_method_name.is_a?(String)
|
|
65
|
+
@method_name = new_method_name
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def arguments
|
|
69
|
+
raise MessageError unless setup?
|
|
70
|
+
@arguments.map(&:to_native_object)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def arguments=(new_arguments)
|
|
74
|
+
raise MessageError unless new_arguments.is_a?(Array)
|
|
75
|
+
@arguments = new_arguments.map do |native_argument|
|
|
76
|
+
Object.from_native_object(@connection, native_argument)
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def invert_orgin
|
|
81
|
+
raise MessageError unless setup?
|
|
82
|
+
@exposed_object.invert_orgin
|
|
83
|
+
@arguments.each { |argument| argument.invert_orgin if argument.respond_to?(:invert_orgin) }
|
|
84
|
+
nil
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
private
|
|
88
|
+
|
|
89
|
+
def setup?
|
|
90
|
+
super && @exposed_object != nil && @method_name != nil && @arguments != nil
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
class Sumac
|
|
2
|
+
class Message
|
|
3
|
+
class Exchange
|
|
4
|
+
class CallResponse < Base
|
|
5
|
+
include ID
|
|
6
|
+
|
|
7
|
+
def initialize(connection)
|
|
8
|
+
super
|
|
9
|
+
@return_value = nil
|
|
10
|
+
@exception = nil
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def parse_json_structure(json_structure)
|
|
14
|
+
raise MessageError unless json_structure.is_a?(Hash) &&
|
|
15
|
+
json_structure['message_type'] == 'exchange' &&
|
|
16
|
+
json_structure['exchange_type'] == 'call_response'
|
|
17
|
+
raise MessageError unless json_structure['id'].is_a?(Integer)
|
|
18
|
+
@id = json_structure['id']
|
|
19
|
+
case
|
|
20
|
+
when json_structure['return_value'] && !json_structure['exception']
|
|
21
|
+
@return_value = Object.from_json_structure(@connection, json_structure['return_value'])
|
|
22
|
+
when !json_structure['return_value'] && json_structure['exception']
|
|
23
|
+
@exception = Object.from_json_structure(@connection, json_structure['exception'])
|
|
24
|
+
raise MessageError unless @exception.class.one_of?(Object::Exception, Object::NativeException)
|
|
25
|
+
else
|
|
26
|
+
raise MessageError
|
|
27
|
+
end
|
|
28
|
+
nil
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def to_json_structure
|
|
32
|
+
raise MessageError unless setup?
|
|
33
|
+
json_structure =
|
|
34
|
+
{
|
|
35
|
+
'message_type' => 'exchange',
|
|
36
|
+
'exchange_type' => 'call_response',
|
|
37
|
+
'id' => @id
|
|
38
|
+
}
|
|
39
|
+
if @return_value
|
|
40
|
+
json_structure['return_value'] = @return_value.to_json_structure
|
|
41
|
+
else
|
|
42
|
+
json_structure['exception'] = @exception.to_json_structure
|
|
43
|
+
end
|
|
44
|
+
json_structure
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def return_value
|
|
48
|
+
raise MessageError unless setup?
|
|
49
|
+
@return_value == nil ? nil : @return_value.to_native_object
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def return_value=(new_return_value)
|
|
53
|
+
raise unless @exception == nil
|
|
54
|
+
@return_value = Object.from_native_object(@connection, new_return_value)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def exception
|
|
58
|
+
raise MessageError unless setup?
|
|
59
|
+
@exception == nil ? nil : @exception.to_native_object
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def exception=(new_exception_value)
|
|
63
|
+
raise unless @return_value == nil
|
|
64
|
+
@exception = Object.from_native_object(@connection, new_exception_value)
|
|
65
|
+
raise MessageError unless @exception.class.one_of?(Object::Exception, Object::NativeException)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def invert_orgin
|
|
69
|
+
raise MessageError unless setup?
|
|
70
|
+
@return_value.invert_orgin if @return_value.respond_to?(:invert_orgin)
|
|
71
|
+
nil
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
private
|
|
75
|
+
|
|
76
|
+
def setup?
|
|
77
|
+
super && ((@return_value != nil) ^ (@exception != nil))
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
class Sumac
|
|
2
|
+
class Message
|
|
3
|
+
class Exchange
|
|
4
|
+
class CompatibilityNotification < Notification
|
|
5
|
+
|
|
6
|
+
def initialize(connection)
|
|
7
|
+
super
|
|
8
|
+
@protocol_version = nil
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def parse_json_structure(json_structure)
|
|
12
|
+
raise MessageError unless json_structure.is_a?(Hash) &&
|
|
13
|
+
json_structure['message_type'] == 'exchange' &&
|
|
14
|
+
json_structure['exchange_type'] == 'compatibility_notification'
|
|
15
|
+
raise MessageError unless json_structure['protocol_version'].is_a?(Integer)
|
|
16
|
+
@protocol_version = json_structure['protocol_version']
|
|
17
|
+
nil
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def to_json_structure
|
|
21
|
+
raise MessageError unless setup?
|
|
22
|
+
{
|
|
23
|
+
'message_type' => 'exchange',
|
|
24
|
+
'exchange_type' => 'compatibility_notification',
|
|
25
|
+
'protocol_version' => @protocol_version
|
|
26
|
+
}
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def protocol_version
|
|
30
|
+
raise MessageError unless setup?
|
|
31
|
+
@protocol_version
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def protocol_version=(new_protocol_version)
|
|
35
|
+
raise MessageError unless new_protocol_version.is_a?(Integer)
|
|
36
|
+
@protocol_version = new_protocol_version
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def invert_orgin
|
|
40
|
+
raise MessageError unless setup?
|
|
41
|
+
nil
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
private
|
|
45
|
+
|
|
46
|
+
def setup?
|
|
47
|
+
@protocol_version != nil
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
class Sumac
|
|
2
|
+
class Message
|
|
3
|
+
class Exchange
|
|
4
|
+
class ForgetNotification < Notification
|
|
5
|
+
|
|
6
|
+
def initialize(connection)
|
|
7
|
+
super
|
|
8
|
+
@orgin = nil
|
|
9
|
+
@id = nil
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def parse_json_structure(json_structure)
|
|
13
|
+
raise MessageError unless json_structure.is_a?(Hash) &&
|
|
14
|
+
json_structure['message_type'] == 'exchange' &&
|
|
15
|
+
json_structure['exchange_type'] == 'forget_notification'
|
|
16
|
+
raise MessageError unless json_structure['orgin'] == 'local' || json_structure['orgin'] == 'remote'
|
|
17
|
+
@orgin = json_structure['orgin']
|
|
18
|
+
raise MessageError unless json_structure['id'].is_a?(::Integer)
|
|
19
|
+
@id = json_structure['id']
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def to_json_structure
|
|
23
|
+
raise MessageError unless setup?
|
|
24
|
+
{
|
|
25
|
+
'message_type' => 'exchange',
|
|
26
|
+
'exchange_type' => 'forget_notification',
|
|
27
|
+
'orgin' => @orgin,
|
|
28
|
+
'id' => @id
|
|
29
|
+
}
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def reference
|
|
33
|
+
raise MessageError unless setup?
|
|
34
|
+
case @orgin
|
|
35
|
+
when 'local'
|
|
36
|
+
reference = @connection.local_references.from_id(@id)
|
|
37
|
+
raise MessageError unless reference
|
|
38
|
+
reference
|
|
39
|
+
when 'remote'
|
|
40
|
+
@connection.remote_references.from_id(@id)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def reference=(new_reference)
|
|
45
|
+
case new_reference
|
|
46
|
+
when LocalReference
|
|
47
|
+
@orgin = 'local'
|
|
48
|
+
when RemoteReference
|
|
49
|
+
@orgin = 'remote'
|
|
50
|
+
else
|
|
51
|
+
raise MessageError
|
|
52
|
+
end
|
|
53
|
+
@id = new_reference.exposed_id
|
|
54
|
+
nil
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def invert_orgin
|
|
58
|
+
raise MessageError unless setup?
|
|
59
|
+
case @orgin
|
|
60
|
+
when 'local'
|
|
61
|
+
@orgin = 'remote'
|
|
62
|
+
when 'remote'
|
|
63
|
+
@orgin = 'local'
|
|
64
|
+
end
|
|
65
|
+
nil
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
private
|
|
69
|
+
|
|
70
|
+
def setup?
|
|
71
|
+
@orgin != nil && @id != nil
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
class Sumac
|
|
2
|
+
class Message
|
|
3
|
+
class Exchange
|
|
4
|
+
module ID
|
|
5
|
+
|
|
6
|
+
def initialize(connection)
|
|
7
|
+
super
|
|
8
|
+
@id = nil
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def id
|
|
12
|
+
raise MessageError unless setup?
|
|
13
|
+
@id
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def id=(new_id)
|
|
17
|
+
raise MessageErro unless new_id.is_a?(Integer)
|
|
18
|
+
@id = new_id
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
def setup?
|
|
24
|
+
@id != nil
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
class Sumac
|
|
2
|
+
class Message
|
|
3
|
+
class Exchange
|
|
4
|
+
class InitializationNotification < Notification
|
|
5
|
+
|
|
6
|
+
def initialize(connection)
|
|
7
|
+
super
|
|
8
|
+
@entry = nil
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def parse_json_structure(json_structure)
|
|
12
|
+
raise MessageError unless json_structure.is_a?(Hash) &&
|
|
13
|
+
json_structure['message_type'] == 'exchange' &&
|
|
14
|
+
json_structure['exchange_type'] == 'initialization_notification'
|
|
15
|
+
@entry = Object.from_json_structure(@connection, json_structure['entry'])
|
|
16
|
+
nil
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def to_json_structure
|
|
20
|
+
raise MessageError unless setup?
|
|
21
|
+
{
|
|
22
|
+
'message_type' => 'exchange',
|
|
23
|
+
'exchange_type' => 'initialization_notification',
|
|
24
|
+
'entry' => @entry.to_json_structure
|
|
25
|
+
}
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def entry
|
|
29
|
+
raise MessageError unless setup?
|
|
30
|
+
@entry.to_native_object
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def entry=(new_entry_object)
|
|
34
|
+
@entry = Object.from_native_object(@connection, new_entry_object)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def invert_orgin
|
|
38
|
+
raise MessageError unless setup?
|
|
39
|
+
@entry.invert_orgin if @entry.respond_to?(:invert_orgin)
|
|
40
|
+
nil
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
private
|
|
44
|
+
|
|
45
|
+
def setup?
|
|
46
|
+
@entry != nil
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
class Sumac
|
|
2
|
+
class Message
|
|
3
|
+
class Exchange
|
|
4
|
+
class ShutdownNotification < Notification
|
|
5
|
+
|
|
6
|
+
def parse_json_structure(json_structure)
|
|
7
|
+
raise MessageError unless json_structure.is_a?(Hash) &&
|
|
8
|
+
json_structure['message_type'] == 'exchange' &&
|
|
9
|
+
json_structure['exchange_type'] == 'shutdown_notification'
|
|
10
|
+
nil
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def to_json_structure
|
|
14
|
+
{
|
|
15
|
+
'message_type' => 'exchange',
|
|
16
|
+
'exchange_type' => 'shutdown_notification'
|
|
17
|
+
}
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def invert_orgin
|
|
21
|
+
nil
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|