Class: DeepTest::Server
- Inherits:
-
Object
show all
- Defined in:
- lib/deep_test/server.rb
Defined Under Namespace
Classes: NoWorkUnitsAvailableError, NoWorkUnitsRemainingError, ResultOverdueError
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(options) ⇒ Server
Returns a new instance of Server.
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/deep_test/server.rb', line 21
def initialize(options)
@options = options
@work_queue = Queue.new
@result_queue = Queue.new
if Metrics::Gatherer.enabled?
require File.dirname(__FILE__) + "/metrics/queue_lock_wait_time_measurement"
@work_queue.extend Metrics::QueueLockWaitTimeMeasurement
@result_queue.extend Metrics::QueueLockWaitTimeMeasurement
Metrics::Gatherer.section("server queue lock wait times") do |s|
s.measurement("work queue total pop wait time", @work_queue.total_pop_time)
s.measurement("work queue total push wait time", @work_queue.total_push_time)
s.measurement("result queue total pop wait time", @result_queue.total_pop_time)
s.measurement("result queue total push wait time", @result_queue.total_push_time)
end
end
end
|
Class Method Details
.remote_reference(address, port) ⇒ Object
14
15
16
17
18
19
|
# File 'lib/deep_test/server.rb', line 14
def self.remote_reference(address, port)
DRb.start_service
blackboard = DRbObject.new_with_uri("druby://#{address}:#{port}")
DeepTest.logger.debug "Connecting to DeepTest server at #{blackboard.__drburi}"
blackboard
end
|
.start(options) ⇒ Object
3
4
5
6
7
8
|
# File 'lib/deep_test/server.rb', line 3
def self.start(options)
server = new(options)
DRb.start_service("druby://0.0.0.0:#{options.server_port}", server)
DeepTest.logger.info "Started DeepTest service at #{DRb.uri}"
server
end
|
.stop ⇒ Object
10
11
12
|
# File 'lib/deep_test/server.rb', line 10
def self.stop
DRb.stop_service
end
|
Instance Method Details
#done_with_work ⇒ Object
39
40
41
|
# File 'lib/deep_test/server.rb', line 39
def done_with_work
@done_with_work = true
end
|
#take_result ⇒ Object
43
44
45
46
47
|
# File 'lib/deep_test/server.rb', line 43
def take_result
Timeout.timeout(@options.timeout_in_seconds, ResultOverdueError) do
@result_queue.pop
end
end
|
#take_work ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/deep_test/server.rb', line 49
def take_work
raise NoWorkUnitsRemainingError if @done_with_work
@work_queue.pop(true)
rescue ThreadError => e
if e.message == "queue empty"
raise NoWorkUnitsAvailableError
else
raise
end
end
|
#write_result(result) ⇒ Object
61
62
63
64
|
# File 'lib/deep_test/server.rb', line 61
def write_result(result)
@result_queue.push result
nil
end
|
#write_work(work_unit) ⇒ Object
66
67
68
69
|
# File 'lib/deep_test/server.rb', line 66
def write_work(work_unit)
@work_queue.push work_unit
nil
end
|