Class: Foxbat::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/foxbat/server.rb

Direct Known Subclasses

HttpServer

Instance Method Summary collapse

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, options, &block)
  if options[:secure]
    @context = Security.setup_ssl_context(options[:keystore])
  end

  @group = DefaultChannelGroup.new
  @address = InetSocketAddress.new(host, port)
  @pipeline = Pipeline.new(klass, @group, false, options, @context, &block)
end

Instance Method Details

#connection_countObject



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

#stopObject



34
35
36
# File 'lib/foxbat/server.rb', line 34

def stop
  @group.close.awaitUninterruptibly
end