Class: JstdRunner::Server

Inherits:
Object
  • Object
show all
Includes:
Monitorable
Defined in:
lib/jstd-runner/server.rb

Defined Under Namespace

Classes: StartupError, StopError

Constant Summary collapse

JAR =
File.expand_path("../JsTestDriver-1.3.3d.jar", __FILE__)
LAUNCH_TIMEOUT =

this is huge, but I’ve seen it happen

120

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Monitorable

#monitor

Constructor Details

#initialize(port, jar = nil) ⇒ Server

Returns a new instance of Server.



16
17
18
19
20
21
# File 'lib/jstd-runner/server.rb', line 16

def initialize(port, jar = nil)
  @host       = "127.0.0.1"
  @port       = Integer(port)
  @restarting = false
  @jar        = jar || JAR
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



14
15
16
# File 'lib/jstd-runner/server.rb', line 14

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



14
15
16
# File 'lib/jstd-runner/server.rb', line 14

def port
  @port
end

Instance Method Details

#restartObject



38
39
40
41
42
43
44
45
# File 'lib/jstd-runner/server.rb', line 38

def restart
  @restarting = true
  Log.info "restarting server"
  stop rescue nil
  @process = nil
  start
  @restarting = false
end

#running?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/jstd-runner/server.rb', line 56

def running?
  process.alive? && immediate_poller.connected?
end

#startObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/jstd-runner/server.rb', line 23

def start
  Log.info "starting JsTestDriver from #{@jar}"

  if immediate_poller.connected?
    raise StartupError, "JsTestDriver already running on #{@host}:#{@port}"
  end

  process.start

  unless long_poller.connected?
    process.stop rescue nil
    raise StartupError, "could not launch JsTestDriver server on #{@host}:#{@port} within #{LAUNCH_TIMEOUT} seconds"
  end
end

#stopObject



47
48
49
50
51
52
53
54
# File 'lib/jstd-runner/server.rb', line 47

def stop
  Log.info "stopping JsTestDriver"
  process.stop

  unless long_poller.closed?
    raise StopError, "could not stop JsTestDriver server on port #{@host}:#{@port} witin #{LAUNCH_TIMEOUT} seconds"
  end
end