nobject 1.1.18 → 1.2.1

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/nobject/local.rb +50 -28
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 735417071860a888e86bb652a14f147bdca25d66add3b2cb6d09509e4f6c05ad
4
- data.tar.gz: d5462edfd3224e520907f0b7c3323ff00bb3654cf4103c3170c8f0e5074f3c51
3
+ metadata.gz: e47a1b1add27980c6649b852026a4393dd7b708a815bc1d395c8e918b3c2a375
4
+ data.tar.gz: 3caa113ae4fc833f1fdd6b0505b94a52b94f2ab60081b315132f9dabf1e5f008
5
5
  SHA512:
6
- metadata.gz: 8096bc14015f9604f9b594844cf3c96b2a1452a89c93ef0334d921a6cc0d9ffc6caf5f6dc5e8f98065ae9ab2568a3a1297002e0724af279c3f97d9b4df6d2c4b
7
- data.tar.gz: ecbd98324b162bbb7b7bd2ed051411a06b5df8334717282e3ac9c8cf53f1a90f56840055865242580b16e368f4aa5eb89a1cd4b75f60a20c6a45f62d69fc1e59
6
+ metadata.gz: 611d074f8fed895c95644147edc3620fbd3e0fe23485e0abf45426a1a1895576f03f17eb7d7d1b4ffd230bc2256e23fff0e4f07fe5705cbedab0868f4c680d48
7
+ data.tar.gz: b80d4f3f3def8cadbfd17e2bc8bb7a71ae1f648f1b62414fe6b87044e6e80c3f8f1030961063691092e4ca6d6a95179e654b0ee35bbe8c56376637e641d4a61a
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,55 @@ module Nobject
29
31
  msg = { method: method, args: args }
30
32
  msg_bytes = Marshal.dump(msg)
31
33
 
32
- begin
33
- @socket.send([msg_bytes.length].pack('Q>'), 0)
34
- File.open('/tmp/nobject.log', 'a') {|f| f.puts " LMS:##{@msg_counter += 1} sz#{msg_bytes.length} m:#{method}"; f.flush }
35
- @socket.send(msg_bytes, 0)
36
- @socket.flush
37
- rescue Exception
38
- raise Local::MethodRequestFailure.new("did not receive response from call to `#{method}' over the network")
39
- end
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
+ File.open('/tmp/nobject.log', 'a') {|f| f.puts " LMGotitRETRY"; f.flush }
54
+ redo
55
+ end
40
56
 
41
- return_data = begin
42
- msg_size = @socket.recv(8).unpack('Q>').first
43
- raw_bytes = @socket.recv(msg_size)
44
- File.open('/tmp/nobject.log', 'a') {|f| f.puts " LMGotit :##{@msg_counter += 1} sz#{msg_size} bytes:#{raw_bytes.length} m:#{method}"; f.flush }
45
- Marshal.load(raw_bytes)
46
- rescue Exception => e
47
- error_msg = <<~MSG
48
- did not receive response from call to `#{method}' over the network
49
- would have been msg_id #{@msg_counter} OR #{@msg_counter + 1} when trying to receive #{msg_size} bytes
50
- caused by #{e.class.name}
51
- exception backtrace:
52
- #{e.backtrace.join("\n ")}
53
- MSG
54
- raise Local::MethodResponseFailure.new(error_msg)
55
- end
57
+ Marshal.load(raw_bytes)
58
+ rescue Exception => e
59
+ # TODO: consider removing this rescue block:
60
+ # this rescue may be unreachable now, since the only
61
+ # time it used to happen was when:
62
+ # msg_size != raw_bytes.length
63
+ #
64
+ # ... which is now handled by the retry logic above
65
+ error_msg = <<~MSG
66
+ did not receive response from call to `#{method}' over the network
67
+ would have been msg_id #{@msg_counter} OR #{@msg_counter + 1} when trying to receive #{msg_size} bytes
68
+ caused by #{e.class.name}
69
+ exception backtrace:
70
+ #{e.backtrace.join("\n ")}
71
+ MSG
72
+ raise Local::MethodResponseFailure.new(error_msg)
73
+ end
56
74
 
57
- case return_data.first
58
- when :ok then return_data.last
59
- when :raise then raise return_data.last
60
- else
61
- raise Local::UnknownReturnDataType.new("unknown data type '#{return_data.first}' within Nobject::Local (Nobject::Local::UnknownReturnDataType)")
75
+ break (
76
+ case return_data.first
77
+ when :ok then return_data.last
78
+ when :raise then raise return_data.last
79
+ else
80
+ raise Local::UnknownReturnDataType.new("unknown data type '#{return_data.first}' within Nobject::Local (Nobject::Local::UnknownReturnDataType)")
81
+ end
82
+ )
62
83
  end
63
84
  end
64
85
 
@@ -77,4 +98,5 @@ module Nobject
77
98
  class Local::InvalidMethod < RuntimeError; end
78
99
  class Local::MethodRequestFailure < RuntimeError; end
79
100
  class Local::MethodResponseFailure < RuntimeError; end
101
+ class Local::MethodInvocationRetriesExceeded < RuntimeError; end
80
102
  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.1.18
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Lunt
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-05-01 00:00:00.000000000 Z
10
+ date: 2025-05-08 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