tribe_em 0.2.0 → 0.3.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/README.md +14 -13
- data/lib/tribe_em/actor_proxy.rb +1 -1
- data/lib/tribe_em/connection.rb +25 -10
- data/lib/tribe_em/version.rb +1 -1
- 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: 7c06effb38bcd4e0a392204e44b7cadf03c9b29b
|
4
|
+
data.tar.gz: 7ed3c4e2c315c9d9a1fe788544c5e6cb443f9b33
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 39275a0949dabb7e47b4f5bcfffe077e673ee15f740eb416d442a8d3516ebe2e27c8dd98198f7f66b5e51234cda8182bff7da8555d54775618fe8246b44c4b84
|
7
|
+
data.tar.gz: 1a7ff3940c9d0b044392812564fc99531a597281337e62d0d22cb8b593c05fdfd2480223ec21cd36c7fe07a58347510b73f7f0e9bca9b4f59e46bd95f5730954
|
data/README.md
CHANGED
@@ -22,29 +22,30 @@ Or install it yourself as:
|
|
22
22
|
You can test the below code using a utility such as telnet (telnet localhost 9000), entering some text, and then killing telnet.
|
23
23
|
|
24
24
|
# Create a custom connection actor class.
|
25
|
-
class
|
25
|
+
class EchoConn < Tribe::EM::Connection
|
26
26
|
private
|
27
|
-
|
28
|
-
def on_post_init(event)
|
29
|
-
puts "Actor (#{identifier}) connected to client using thread (#{Thread.current.object_id})."
|
27
|
+
def exception_handler(e)
|
30
28
|
super
|
29
|
+
puts concat_e("EchoConn (#{identifier}) died.", e)
|
31
30
|
end
|
32
31
|
|
33
|
-
def
|
34
|
-
puts "Actor (#{identifier})
|
35
|
-
write(event.data)
|
36
|
-
enqueue(:shutdown)
|
37
|
-
super
|
32
|
+
def post_init_handler
|
33
|
+
puts "Actor (#{identifier}) connected to client using thread (#{Thread.current.object_id})."
|
38
34
|
end
|
39
35
|
|
40
|
-
def
|
36
|
+
def receive_data_handler(data)
|
37
|
+
puts "Actor (#{identifier}) received data (#{data}) using thread (#{Thread.current.object_id})."
|
38
|
+
write(data)
|
39
|
+
shutdown!
|
40
|
+
end
|
41
|
+
|
42
|
+
def unbind_handler
|
41
43
|
puts "Actor (#{identifier}) disconnected from client using thread (#{Thread.current.object_id})."
|
42
|
-
super
|
43
44
|
end
|
44
45
|
end
|
45
|
-
|
46
|
+
|
46
47
|
# Create your server actor.
|
47
|
-
server = Tribe::EM::TcpServer.new('localhost', 9000,
|
48
|
+
server = Tribe::EM::TcpServer.new('localhost', 9000, EchoConn)
|
48
49
|
|
49
50
|
## Customization
|
50
51
|
|
data/lib/tribe_em/actor_proxy.rb
CHANGED
data/lib/tribe_em/connection.rb
CHANGED
@@ -9,44 +9,59 @@ module Tribe
|
|
9
9
|
private
|
10
10
|
|
11
11
|
def initialize(options = {})
|
12
|
-
@
|
12
|
+
@_actor_proxy = options[:actor_proxy] || raise('You must provide an actor proxy.')
|
13
13
|
|
14
14
|
super
|
15
15
|
end
|
16
16
|
|
17
|
-
|
17
|
+
def write(data)
|
18
|
+
@_actor_proxy.write(data)
|
19
|
+
end
|
20
|
+
|
21
|
+
def close(after_writing = false)
|
22
|
+
@_actor_proxy.close(after_writing)
|
23
|
+
end
|
24
|
+
|
25
|
+
#
|
26
|
+
# Command handlers.
|
27
|
+
#
|
28
|
+
|
18
29
|
def on_post_init(event)
|
30
|
+
post_init_handler
|
19
31
|
end
|
20
32
|
|
21
|
-
# Override and call super as necessary.
|
22
33
|
def on_receive_data(event)
|
34
|
+
receive_data_handler(event.data)
|
23
35
|
end
|
24
36
|
|
25
|
-
# Override and call super as necessary.
|
26
37
|
def on_unbind(event)
|
27
38
|
shutdown!
|
39
|
+
unbind_handler
|
28
40
|
end
|
29
41
|
|
30
|
-
#
|
42
|
+
#
|
43
|
+
# System handlers.
|
44
|
+
#
|
45
|
+
|
31
46
|
def exception_handler(e)
|
32
47
|
super
|
33
48
|
|
34
49
|
close
|
35
50
|
end
|
36
51
|
|
37
|
-
# Override and call super as necessary.
|
38
52
|
def shutdown_handler(event)
|
39
53
|
super
|
40
54
|
|
41
55
|
close(true)
|
42
56
|
end
|
43
57
|
|
44
|
-
def
|
45
|
-
@actor_proxy.write(data)
|
58
|
+
def post_init_handler
|
46
59
|
end
|
47
60
|
|
48
|
-
def
|
49
|
-
|
61
|
+
def receive_data_handler(data)
|
62
|
+
end
|
63
|
+
|
64
|
+
def unbind_handler
|
50
65
|
end
|
51
66
|
end
|
52
67
|
end
|
data/lib/tribe_em/version.rb
CHANGED