elrpc 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/elrpc.rb +22 -2
- data/lib/elrpc/version.rb +1 -1
- data/test/_errors.rb +3 -0
- data/test/test-epc.rb +15 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f891bac71044cc7a7eb77f745da3318981f68f17
|
4
|
+
data.tar.gz: 0ad1e5a241187431b3c428e547df86f77e7a6ff5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd8e7eb9fddef97c449441f183a3c4db452416ac748f2ab6389838530b72149ba930f8e56c6c9a2a9249c06a253e7cec9049a41fddebce08173298c523649e83
|
7
|
+
data.tar.gz: fb851ee98b9597cdc4df267cac633918ecce636a4304a2f24448894f544e800977ad9d0d39372a3a4cbc3335a03f595be82f8c03cd67ff625149c4b553ae72a9
|
data/lib/elrpc.rb
CHANGED
@@ -106,6 +106,10 @@ module Elrpc
|
|
106
106
|
@client = Elrpc.start_client(@port)
|
107
107
|
return self
|
108
108
|
end
|
109
|
+
|
110
|
+
def alive?
|
111
|
+
@client.alive?
|
112
|
+
end
|
109
113
|
|
110
114
|
def register_method(method)
|
111
115
|
@client.register_method(method)
|
@@ -317,6 +321,10 @@ module Elrpc
|
|
317
321
|
@logger.debug ":ready for I/O stream."
|
318
322
|
end
|
319
323
|
|
324
|
+
def alive?
|
325
|
+
return @socket_state == :socket_opened
|
326
|
+
end
|
327
|
+
|
320
328
|
# 自分にメソッドを登録する
|
321
329
|
def register_method(method)
|
322
330
|
@methods[method.name] = method
|
@@ -330,6 +338,7 @@ module Elrpc
|
|
330
338
|
# 相手のメソッドを呼ぶ
|
331
339
|
# block(err, value)
|
332
340
|
def call_method_async(name, *args, &block)
|
341
|
+
return _raise_connection_error(block) if @socket_state != :socket_opened
|
333
342
|
uid = Elrpc.gen_uid
|
334
343
|
msg = CallMessage.new(uid, name, args, block)
|
335
344
|
# ここは競合しないのでロックしない
|
@@ -338,6 +347,13 @@ module Elrpc
|
|
338
347
|
uid
|
339
348
|
end
|
340
349
|
|
350
|
+
def _raise_connection_error(block)
|
351
|
+
job = lambda do
|
352
|
+
block.call(EPCStackError.new("ConnectionClosed","Connection closed",""))
|
353
|
+
end
|
354
|
+
@worker_pool.invoke(job)
|
355
|
+
end
|
356
|
+
|
341
357
|
# 相手のメソッドを呼ぶ(同期版)
|
342
358
|
def call_method(name, *args)
|
343
359
|
mutex = Mutex.new
|
@@ -363,6 +379,7 @@ module Elrpc
|
|
363
379
|
# 接続相手のメソッド一覧を返す
|
364
380
|
# [[name, argdoc, docstring], ...]
|
365
381
|
def query_methods_async(&block)
|
382
|
+
return _raise_connection_error(block) if @socket_state != :socket_opened
|
366
383
|
uid = Elrpc.gen_uid
|
367
384
|
msg = MethodsMessage.new(uid, block)
|
368
385
|
@session[uid] = msg
|
@@ -403,7 +420,7 @@ module Elrpc
|
|
403
420
|
@sender_thread.join(4) unless Thread.current == @sender_thread
|
404
421
|
@receiver_thread.join(4) unless Thread.current == @receiver_thread
|
405
422
|
_clear_waiting_sessions
|
406
|
-
@socket_state = :
|
423
|
+
@socket_state = :socket_not_connected
|
407
424
|
end
|
408
425
|
_wakeup
|
409
426
|
@logger.debug "RPCService.stop: completed"
|
@@ -430,7 +447,7 @@ module Elrpc
|
|
430
447
|
def _clear_waiting_sessions
|
431
448
|
@session_lock.synchronize do
|
432
449
|
@session.keys.each do |uid|
|
433
|
-
_session_return(uid, "EPC Connection closed", nil)
|
450
|
+
_session_return(uid, EPCStackError.new("ConnectionClosed","EPC Connection closed",""), nil)
|
434
451
|
end
|
435
452
|
end
|
436
453
|
end
|
@@ -520,6 +537,7 @@ module Elrpc
|
|
520
537
|
lenstr = @socket.read(6)
|
521
538
|
if lenstr.nil? then
|
522
539
|
@logger.debug "[rcvloop] Socket closed!"
|
540
|
+
@socket_state = :socket_not_connected
|
523
541
|
break
|
524
542
|
end
|
525
543
|
len = lenstr.to_i(16)
|
@@ -527,6 +545,7 @@ module Elrpc
|
|
527
545
|
body = @socket.read(len) # 1 means LF
|
528
546
|
if body.nil? then
|
529
547
|
@logger.debug "[rcvloop] Socket closed!"
|
548
|
+
@socket_state = :socket_not_connected
|
530
549
|
break
|
531
550
|
end
|
532
551
|
body.force_encoding("utf-8")
|
@@ -584,6 +603,7 @@ module Elrpc
|
|
584
603
|
uid = nil
|
585
604
|
end # loop
|
586
605
|
@logger.debug "[receiver-thread] loop exit : #{@socket_state}"
|
606
|
+
_clear_waiting_sessions
|
587
607
|
_wakeup
|
588
608
|
@logger.debug "[receiver-thread exit]--------------"
|
589
609
|
end
|
data/lib/elrpc/version.rb
CHANGED
data/test/_errors.rb
CHANGED
data/test/test-epc.rb
CHANGED
@@ -55,6 +55,7 @@ class TestEPC < Test::Unit::TestCase
|
|
55
55
|
thread = Thread.start { loop { puts io.readline } }
|
56
56
|
client = Elrpc.start_client(port)
|
57
57
|
client.logger.level = Logger::ERROR
|
58
|
+
#client.logger.level = Logger::DEBUG
|
58
59
|
begin
|
59
60
|
yield client
|
60
61
|
rescue => e
|
@@ -118,7 +119,7 @@ class TestEPC < Test::Unit::TestCase
|
|
118
119
|
end
|
119
120
|
end
|
120
121
|
end
|
121
|
-
|
122
|
+
|
122
123
|
sub_test_case "04 Errors" do
|
123
124
|
|
124
125
|
test "Error sync" do
|
@@ -126,7 +127,7 @@ class TestEPC < Test::Unit::TestCase
|
|
126
127
|
assert_raise_message /divided by 0/ do
|
127
128
|
ret = client.call_method("num_error")
|
128
129
|
end
|
129
|
-
assert_raise_message /Raise
|
130
|
+
assert_raise_message /Raise/ do
|
130
131
|
ret = client.call_method("raise_error")
|
131
132
|
end
|
132
133
|
ret = client.call_method("echo", "recover!!")
|
@@ -160,6 +161,18 @@ class TestEPC < Test::Unit::TestCase
|
|
160
161
|
end
|
161
162
|
end
|
162
163
|
|
164
|
+
test "EPC Down" do
|
165
|
+
with_epc "_errors.rb" do |client|
|
166
|
+
assert_raise_kind_of Elrpc::EPCStackError do
|
167
|
+
client.call_method("killme")
|
168
|
+
end
|
169
|
+
assert_raise_kind_of Elrpc::EPCStackError do
|
170
|
+
client.call_method("echo", "die?" )
|
171
|
+
end
|
172
|
+
assert_equal false, client.alive?
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
163
176
|
end
|
164
177
|
|
165
178
|
sub_test_case "05 Query" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elrpc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- SAKURAI Masashi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: elparser
|