nobject 1.1.18 → 1.2.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
- data/lib/nobject/local.rb +52 -28
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 17e292f75e9f260c1c4d1183f5ad12749fa74b98f5de313ee89cb8c9bfe99935
|
4
|
+
data.tar.gz: a83497c75a0280157b671fd84005c0ea0410d25e5fec4b535b6db26389c110c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b3a073baec24f5cf52d1e6100e6104c646efe0f6de803dd02f2833979de36b9ae7d3bbedc10cab942515e636f7b41f359e5617c6d0404159316116b41d71cea
|
7
|
+
data.tar.gz: 22f333104e7546330883519361c80c4b287bb3a8402d647ebee0dc39ea42e6523b8c876ee8d6286eee609d9b85710b4b3ea2d6b96a4aab52ee152149e648e1ff
|
data/lib/nobject/local.rb
CHANGED
@@ -5,6 +5,8 @@ module Nobject
|
|
5
5
|
# it to a Nobject::Serve4r, which will then send method calls to a matching
|
6
6
|
# Nobject::Remote object
|
7
7
|
class Local
|
8
|
+
MAX_RETRIES = 3
|
9
|
+
|
8
10
|
# host: the hostname of the server to push obj to
|
9
11
|
# port: the port number of the server to push obj to
|
10
12
|
# obj: the obj to store over the network
|
@@ -29,36 +31,57 @@ module Nobject
|
|
29
31
|
msg = { method: method, args: args }
|
30
32
|
msg_bytes = Marshal.dump(msg)
|
31
33
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
34
|
+
retries = 0
|
35
|
+
loop do
|
36
|
+
raise MethodInvocationRetriesExceeded.new("Exceeded retry limit (#{MAX_RETRIES})") if retries == MAX_RETRIES
|
37
|
+
|
38
|
+
begin
|
39
|
+
@socket.send([msg_bytes.length].pack('Q>'), 0)
|
40
|
+
File.open('/tmp/nobject.log', 'a') {|f| f.puts " LMS:##{@msg_counter += 1} sz#{msg_bytes.length} m:#{method}"; f.flush }
|
41
|
+
@socket.send(msg_bytes, 0)
|
42
|
+
@socket.flush
|
43
|
+
rescue Exception
|
44
|
+
raise Local::MethodRequestFailure.new("did not receive response from call to `#{method}' over the network")
|
45
|
+
end
|
46
|
+
|
47
|
+
return_data = begin
|
48
|
+
msg_size = @socket.recv(8).unpack('Q>').first
|
49
|
+
raw_bytes = @socket.recv(msg_size)
|
50
|
+
File.open('/tmp/nobject.log', 'a') {|f| f.puts " LMGotit :##{@msg_counter += 1} sz#{msg_size} bytes:#{raw_bytes.length} m:#{method}"; f.flush }
|
51
|
+
if msg_size != raw_bytes.length
|
52
|
+
retries += 1
|
53
|
+
print "\a" # TODO: consider removing this after the
|
54
|
+
# retry logic seems solid, it's extra,
|
55
|
+
# literal noise :)
|
56
|
+
redo
|
57
|
+
end
|
40
58
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
#{e.
|
53
|
-
|
54
|
-
|
55
|
-
|
59
|
+
Marshal.load(raw_bytes)
|
60
|
+
rescue Exception => e
|
61
|
+
# TODO: consider removing this rescue block:
|
62
|
+
# this rescue may be unreachable now, since the only
|
63
|
+
# time it used to happen was when:
|
64
|
+
# msg_size != raw_bytes.length
|
65
|
+
#
|
66
|
+
# ... which is now handled by the retry logic above
|
67
|
+
error_msg = <<~MSG
|
68
|
+
did not receive response from call to `#{method}' over the network
|
69
|
+
would have been msg_id #{@msg_counter} OR #{@msg_counter + 1} when trying to receive #{msg_size} bytes
|
70
|
+
caused by #{e.class.name}
|
71
|
+
exception backtrace:
|
72
|
+
#{e.backtrace.join("\n ")}
|
73
|
+
MSG
|
74
|
+
raise Local::MethodResponseFailure.new(error_msg)
|
75
|
+
end
|
56
76
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
77
|
+
break (
|
78
|
+
case return_data.first
|
79
|
+
when :ok then return_data.last
|
80
|
+
when :raise then raise return_data.last
|
81
|
+
else
|
82
|
+
raise Local::UnknownReturnDataType.new("unknown data type '#{return_data.first}' within Nobject::Local (Nobject::Local::UnknownReturnDataType)")
|
83
|
+
end
|
84
|
+
)
|
62
85
|
end
|
63
86
|
end
|
64
87
|
|
@@ -77,4 +100,5 @@ module Nobject
|
|
77
100
|
class Local::InvalidMethod < RuntimeError; end
|
78
101
|
class Local::MethodRequestFailure < RuntimeError; end
|
79
102
|
class Local::MethodResponseFailure < RuntimeError; end
|
103
|
+
class Local::MethodInvocationRetriesExceeded < RuntimeError; end
|
80
104
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nobject
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Lunt
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-05-
|
10
|
+
date: 2025-05-02 00:00:00.000000000 Z
|
11
11
|
dependencies: []
|
12
12
|
description: network-hosted objects that you can call methods on as if they were local
|
13
13
|
email: jefflunt@gmail.com
|