Class: Midori::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/em-midori/runner.rb

Overview

Abstract runner class to control instance of Midori Server

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api, configure = Midori::Configure) ⇒ Runner

Returns a new instance of Runner.


6
7
8
9
10
11
12
# File 'lib/em-midori/runner.rb', line 6

def initialize(api, configure = Midori::Configure)
  @logger = configure.logger
  @bind = configure.bind
  @port = configure.port

  @api = api
end

Instance Attribute Details

#bindObject (readonly)

Returns the value of attribute bind


4
5
6
# File 'lib/em-midori/runner.rb', line 4

def bind
  @bind
end

#portObject (readonly)

Returns the value of attribute port


4
5
6
# File 'lib/em-midori/runner.rb', line 4

def port
  @port
end

Instance Method Details

#running?Boolean

Get Midori server whether running

Returns:

  • (Boolean)
    true

    running

  • (Boolean)
    false

    not running


17
18
19
# File 'lib/em-midori/runner.rb', line 17

def running?
  !!@server_signature
end

#startObject

Note:

This is an async method, but no callback

Start the Midori server


23
24
25
26
27
28
29
30
31
32
33
# File 'lib/em-midori/runner.rb', line 23

def start
  return if running?

  EventMachine.set_simultaneous_accept_count(40) unless RUBY_PLATFORM == 'java'
  EventMachine.run do
    @logger.info "Midori #{Midori::VERSION} is now running on #{bind}:#{port}".blue
    @server_signature = EventMachine.start_server bind, port, Midori::Server, @api, @logger
  end

  nil
end

#stopBoolean

Note:

This is an async method, but no callback

Stop the Midori server

Returns:

  • (Boolean)
    true

    stop successfully

  • (Boolean)
    false

    nothing to stop


39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/em-midori/runner.rb', line 39

def stop
  if running?
    @logger.info 'Goodbye Midori'.blue
    EventMachine.stop_server(@server_signature)
    @server_signature = nil
    EM.stop
    true
  else
    @logger.error 'Midori Server has NOT been started'.red
    false
  end
end