Class: Griffin::Engine::Single

Inherits:
Object
  • Object
show all
Defined in:
lib/griffin/engine/single.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server, config) ⇒ Single

Returns a new instance of Single.



21
22
23
24
25
26
# File 'lib/griffin/engine/single.rb', line 21

def initialize(server, config)
  @server = server
  @config = config
  @sock = TCPServer.new(@config[:bind], @config[:port])
  @sock.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
end

Class Method Details

.create(config) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/griffin/engine/single.rb', line 8

def self.create(config)
  serv = Griffin::Server.new(
    min_pool_size: config[:min_pool_size],
    max_pool_size: config[:max_pool_size],
    min_connection_size: config[:min_connection_size],
    max_connection_size: config[:max_connection_size],
    max_receive_message_size: config[:max_receive_message_size],
    max_send_message_size: config[:max_send_message_size],
    interceptors: config[:interceptors],
  )
  new(serv, config)
end

Instance Method Details

#install_handlerObject



40
41
42
43
44
45
46
47
48
# File 'lib/griffin/engine/single.rb', line 40

def install_handler
  trap('INT') do
    @server.shutdown
  end

  trap('TERM') do
    @server.shutdown
  end
end

#runObject



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/griffin/engine/single.rb', line 28

def run
  @config[:services].each do |s|
    @server.handle(s)
  end

  install_handler

  @server.before_run
  @sock.listen(Socket::SOMAXCONN)
  @server.run(@sock)
end