pb_actor 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pb_actor.rb +4 -0
- data/lib/pb_actor/basic_proxy.rb +8 -3
- data/lib/pb_actor/message.rb +2 -2
- data/lib/pb_actor/proxy.rb +7 -0
- data/lib/pb_actor/version.rb +1 -1
- data/spec/pb_actor_spec.rb +2 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 171981023e291918c5a970e7f33062035e0c8542
|
4
|
+
data.tar.gz: d687fbe4a94c60505e4c765f56067d33f20cd752
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4222d61838e6118b282efcba9449531d8000b9d79ccc1769b536f4667d5f9965178de18298e673a52679b4930ff4425c6d384eebd0fab49d8db922263fc522fd
|
7
|
+
data.tar.gz: 3014b7618e9cdaab4b9ee3670a3c9d2aab50bddd601ce3fb9df40fe28c3404480a24e61058e9526be26cd2023dfeeecfd417ce463e2f2b8c66f38149a0bec6f7
|
data/lib/pb_actor.rb
CHANGED
data/lib/pb_actor/basic_proxy.rb
CHANGED
@@ -4,17 +4,22 @@ module PbActor
|
|
4
4
|
class BasicProxy
|
5
5
|
def initialize origin, pid, wr, rd
|
6
6
|
@origin, @pid, @wr, @rd = origin, pid, wr, rd
|
7
|
+
@alive = true
|
7
8
|
end
|
8
9
|
|
9
10
|
def alive?
|
10
|
-
!Process.waitpid @pid, Process::WNOHANG
|
11
|
+
if !@alive || (!Process.waitpid @pid, Process::WNOHANG)
|
12
|
+
@alive
|
13
|
+
else
|
14
|
+
@alive = false
|
15
|
+
end
|
11
16
|
rescue Errno::ECHILD => e
|
12
|
-
false
|
17
|
+
@alive = false
|
13
18
|
end
|
14
19
|
|
15
20
|
def method_missing method, *args, &blk
|
16
21
|
raise ArgumentError, 'actor not support block' if blk
|
17
|
-
raise DeadActorError,
|
22
|
+
raise DeadActorError, PbActor.dead_actor_msg unless alive?
|
18
23
|
end
|
19
24
|
|
20
25
|
def to_s
|
data/lib/pb_actor/message.rb
CHANGED
@@ -4,13 +4,13 @@ module PbActor
|
|
4
4
|
def send msg, wr
|
5
5
|
Marshal.dump(msg, wr)
|
6
6
|
rescue Errno::EPIPE => e
|
7
|
-
raise DeadActorError,
|
7
|
+
raise DeadActorError, PbActor.dead_actor_msg
|
8
8
|
end
|
9
9
|
|
10
10
|
def recv rd
|
11
11
|
Marshal.load rd
|
12
12
|
rescue EOFError => e
|
13
|
-
raise DeadActorError,
|
13
|
+
raise DeadActorError, PbActor.dead_actor_msg
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
data/lib/pb_actor/proxy.rb
CHANGED
@@ -39,6 +39,7 @@ module PbActor
|
|
39
39
|
[cr, cw].each &:close
|
40
40
|
@rd = pr
|
41
41
|
@wr = pw
|
42
|
+
@alive = true
|
42
43
|
end
|
43
44
|
|
44
45
|
def method_missing method, *args, &blk
|
@@ -55,15 +56,21 @@ module PbActor
|
|
55
56
|
end
|
56
57
|
|
57
58
|
def terminate
|
59
|
+
raise DeadActorError, PbActor.dead_actor_msg unless alive?
|
58
60
|
Message.send [:terminate], @wr
|
59
61
|
Process.wait @pid
|
60
62
|
nil
|
63
|
+
rescue Errno::ECHILD => e
|
64
|
+
raise DeadActorError, PbActor.dead_actor_msg
|
61
65
|
end
|
62
66
|
|
63
67
|
def terminate!
|
68
|
+
raise DeadActorError, PbActor.dead_actor_msg unless alive?
|
64
69
|
Process.kill "KILL", @pid
|
65
70
|
Process.wait @pid
|
66
71
|
nil
|
72
|
+
rescue Errno::ECHILD, Errno::ESRCH => e
|
73
|
+
raise DeadActorError, PbActor.dead_actor_msg
|
67
74
|
end
|
68
75
|
end
|
69
76
|
end
|
data/lib/pb_actor/version.rb
CHANGED
data/spec/pb_actor_spec.rb
CHANGED
@@ -62,6 +62,7 @@ describe PbActor do
|
|
62
62
|
@test.terminate
|
63
63
|
@test.alive?.should == false
|
64
64
|
expect{@test.foo}.to raise_error(PbActor::DeadActorError)
|
65
|
+
expect{@test.terminate}.to raise_error(PbActor::DeadActorError)
|
65
66
|
end
|
66
67
|
|
67
68
|
it 'terminate! should work' do
|
@@ -71,6 +72,7 @@ describe PbActor do
|
|
71
72
|
@test.alive? == false
|
72
73
|
end
|
73
74
|
@test.alive?.should == false
|
75
|
+
expect{@test.terminate!}.to raise_error(PbActor::DeadActorError)
|
74
76
|
end
|
75
77
|
|
76
78
|
it 'to_s should correct' do
|