foxbat 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/em/connection.rb +4 -0
- data/lib/eventmachine.rb +6 -1
- data/lib/foxbat/netty_connection.rb +6 -1
- data/lib/foxbat/pipeline.rb +7 -3
- data/lib/foxbat/server.rb +7 -4
- data/lib/foxbat/version.rb +1 -1
- metadata +1 -1
data/lib/em/connection.rb
CHANGED
data/lib/eventmachine.rb
CHANGED
@@ -18,6 +18,7 @@ module EventMachine
|
|
18
18
|
def self.kqueue; end
|
19
19
|
|
20
20
|
def self.run(blk=nil, tail=nil, &block)
|
21
|
+
@alive = true
|
21
22
|
@@threadpool = Executors.newCachedThreadPool
|
22
23
|
|
23
24
|
block.call
|
@@ -27,12 +28,16 @@ module EventMachine
|
|
27
28
|
|
28
29
|
def self.stop
|
29
30
|
@@servers.each { |s| s.stop }
|
30
|
-
@@threadpool.
|
31
|
+
@@threadpool.shutdown
|
31
32
|
end
|
32
33
|
|
33
34
|
def self.executor
|
34
35
|
@@threadpool
|
35
36
|
end
|
36
37
|
|
38
|
+
def self.reactor_running?
|
39
|
+
@alive
|
40
|
+
end
|
41
|
+
|
37
42
|
end
|
38
43
|
|
@@ -6,8 +6,9 @@ module Foxbat
|
|
6
6
|
|
7
7
|
class NettyConnection < SimpleChannelUpstreamHandler
|
8
8
|
|
9
|
-
def initialize(connection)
|
9
|
+
def initialize(connection, group)
|
10
10
|
@connection = connection
|
11
|
+
@group = group
|
11
12
|
connection.netty_handler = self
|
12
13
|
super()
|
13
14
|
end
|
@@ -23,6 +24,10 @@ module Foxbat
|
|
23
24
|
end
|
24
25
|
|
25
26
|
private
|
27
|
+
|
28
|
+
def channelOpen(ctx, e)
|
29
|
+
@group.add(e.getChannel)
|
30
|
+
end
|
26
31
|
|
27
32
|
def channelConnected(ctx, e)
|
28
33
|
@pipeline = ctx.getPipeline
|
data/lib/foxbat/pipeline.rb
CHANGED
@@ -10,9 +10,10 @@ module Foxbat
|
|
10
10
|
class Pipeline
|
11
11
|
include ChannelPipelineFactory
|
12
12
|
|
13
|
-
def initialize(handler, options={}, ssl_context=nil, &block)
|
13
|
+
def initialize(handler, group, options={}, ssl_context=nil, &block)
|
14
14
|
@options = options
|
15
15
|
@handler = handler
|
16
|
+
@group = group
|
16
17
|
@block = block
|
17
18
|
@context = ssl_context
|
18
19
|
end
|
@@ -25,11 +26,14 @@ module Foxbat
|
|
25
26
|
end
|
26
27
|
h = @handler.new(@options)
|
27
28
|
@block.call(h) if @block
|
28
|
-
connection = NettyConnection.new(h)
|
29
|
+
connection = NettyConnection.new(h, @group)
|
29
30
|
pipeline.addLast("handler", connection)
|
30
31
|
pipeline
|
31
32
|
end
|
32
|
-
|
33
|
+
|
34
|
+
def releaseExternalResources
|
35
|
+
p 'cleaning up factory...'
|
36
|
+
end
|
33
37
|
end
|
34
38
|
|
35
39
|
end
|
data/lib/foxbat/server.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
import java.net.InetSocketAddress
|
2
|
+
import org.jboss.netty.channel.group.DefaultChannelGroup
|
2
3
|
import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory
|
3
4
|
import org.jboss.netty.bootstrap.ServerBootstrap
|
4
5
|
require_relative 'pipeline'
|
@@ -12,20 +13,22 @@ module Foxbat
|
|
12
13
|
if options[:secure]
|
13
14
|
@context = Security.setup_ssl_context(options[:keystore])
|
14
15
|
end
|
15
|
-
|
16
|
+
|
17
|
+
@group = DefaultChannelGroup.new
|
16
18
|
@address = InetSocketAddress.new(host, port)
|
17
|
-
@pipeline = Pipeline.new(klass, options, @context, &block)
|
19
|
+
@pipeline = Pipeline.new(klass, @group, options, @context, &block)
|
18
20
|
end
|
19
21
|
|
20
22
|
def start(threadpool)
|
21
23
|
@factory = NioServerSocketChannelFactory.new(threadpool, threadpool)
|
22
24
|
@bootstrap = ServerBootstrap.new(@factory)
|
23
25
|
@bootstrap.setPipelineFactory(@pipeline)
|
24
|
-
@bootstrap.bind(@address)
|
26
|
+
@server_channel = @bootstrap.bind(@address)
|
27
|
+
@group.add(@server_channel)
|
25
28
|
end
|
26
29
|
|
27
30
|
def stop
|
28
|
-
@
|
31
|
+
@group.close.awaitUninterruptibly
|
29
32
|
end
|
30
33
|
end
|
31
34
|
|
data/lib/foxbat/version.rb
CHANGED