Class: Gt06Server::Server

Inherits:
Object
  • Object
show all
Includes:
Celluloid::IO
Defined in:
lib/gt06_server/server.rb

Defined Under Namespace

Classes: RunError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, port, handler, options: {}) ⇒ Server

Returns a new instance of Server.



32
33
34
35
36
37
38
39
40
# File 'lib/gt06_server/server.rb', line 32

def initialize(host, port, handler, options: {})
  @logger   = options.fetch(:logger, Logger.new(STDOUT))
  @host     = host
  @port     = port
  @sessions = Concurrent::Map.new

  sessions_sweeper_run(@sessions, options)
  async.run handler
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



12
13
14
# File 'lib/gt06_server/server.rb', line 12

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



12
13
14
# File 'lib/gt06_server/server.rb', line 12

def port
  @port
end

#sessionsObject (readonly)

Returns the value of attribute sessions.



12
13
14
# File 'lib/gt06_server/server.rb', line 12

def sessions
  @sessions
end

Class Method Details

.run(host, port, options: {}, &block) ⇒ Object

Parameters:

  • host (String)
  • port (Integer)
  • options (Hash) (defaults to: {})


21
22
23
24
25
26
27
28
29
30
# File 'lib/gt06_server/server.rb', line 21

def self.run(host, port, options: {}, &block)
  if Celluloid::Actor['Gt06Server']&.alive?
    raise RunError, 'Attempt to run more than one the Gt06Server'
  end

  Gt06Server::Server.supervise(
    as:   'Gt06Server',
    args: [host, port, block, options: { logger: Logger.new(STDOUT) }.merge(options)]
  )
end