Class: Foxbat::Server
- Inherits:
-
Object
- Object
- Foxbat::Server
- Defined in:
- lib/foxbat/server.rb
Direct Known Subclasses
Instance Method Summary collapse
- #connection_count ⇒ Object
-
#initialize(host, port, klass, options, &block) ⇒ Server
constructor
A new instance of Server.
- #start(threadpool) ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(host, port, klass, options, &block) ⇒ Server
Returns a new instance of Server.
10 11 12 13 14 15 16 17 18 |
# File 'lib/foxbat/server.rb', line 10 def initialize(host, port, klass, , &block) if [:secure] @context = Security.setup_ssl_context([:keystore]) end @group = DefaultChannelGroup.new @address = InetSocketAddress.new(host, port) @pipeline = Pipeline.new(klass, @group, false, , @context, &block) end |
Instance Method Details
#connection_count ⇒ Object
30 31 32 |
# File 'lib/foxbat/server.rb', line 30 def connection_count @group.size - 1 # -1 to exclude the server's channel end |
#start(threadpool) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/foxbat/server.rb', line 20 def start(threadpool) sp = java.util.concurrent.Executors.newSingleThreadExecutor factory = NioServerSocketChannelFactory.new(sp, threadpool) @bootstrap = ServerBootstrap.new(factory) @bootstrap.setPipelineFactory(@pipeline) @bootstrap.setOption("child.tcpNoDelay", true) server_channel = @bootstrap.bind(@address) @group.add(server_channel) end |
#stop ⇒ Object
34 35 36 |
# File 'lib/foxbat/server.rb', line 34 def stop @group.close.awaitUninterruptibly end |