Class: Pandemic::ServerSide::Request
- Inherits:
-
Object
- Object
- Pandemic::ServerSide::Request
show all
- Includes:
- Util
- Defined in:
- lib/pandemic/server_side/request.rb
Constant Summary
collapse
- @@request_count =
MutexCounter.new
- @@late_responses =
MutexCounter.new
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Util
#host_port, #logger, #with_mutex
Constructor Details
#initialize(body) ⇒ Request
Returns a new instance of Request.
20
21
22
23
24
25
26
27
|
# File 'lib/pandemic/server_side/request.rb', line 20
def initialize(body)
@request_number = @@request_count.inc
@body = body
@responses = []
@responses_mutex = Monitor.new
@waiter = @responses_mutex.new_cond
@complete = false
end
|
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
8
9
10
|
# File 'lib/pandemic/server_side/request.rb', line 8
def body
@body
end
|
#data ⇒ Object
Returns the value of attribute data.
10
11
12
|
# File 'lib/pandemic/server_side/request.rb', line 10
def data
@data
end
|
#max_responses ⇒ Object
Returns the value of attribute max_responses.
9
10
11
|
# File 'lib/pandemic/server_side/request.rb', line 9
def max_responses
@max_responses
end
|
Class Method Details
.total_late_responses ⇒ Object
16
17
18
|
# File 'lib/pandemic/server_side/request.rb', line 16
def self.total_late_responses
@@late_responses.real_total
end
|
.total_request_count ⇒ Object
12
13
14
|
# File 'lib/pandemic/server_side/request.rb', line 12
def self.total_request_count
@@request_count.real_total
end
|
Instance Method Details
#add_response(response) ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/pandemic/server_side/request.rb', line 29
def add_response(response)
@responses_mutex.synchronize do
if @responses.frozen? @@late_responses.inc
return
end
@responses << response
if @max_responses && @responses.size >= @max_responses
wakeup_waiting_thread
@complete = true
end
end
end
|
#cancel! ⇒ Object
53
54
55
56
57
58
|
# File 'lib/pandemic/server_side/request.rb', line 53
def cancel!
@responses_mutex.synchronize do
wakeup_waiting_thread
end
end
|
#hash ⇒ Object
78
79
80
|
# File 'lib/pandemic/server_side/request.rb', line 78
def hash
@hash ||= Digest::MD5.hexdigest("#{@request_number} #{@body}")[0,10]
end
|
#responses ⇒ Object
49
50
51
|
# File 'lib/pandemic/server_side/request.rb', line 49
def responses
@responses end
|
#wait_for_responses ⇒ Object
#wakeup_waiting_thread ⇒ Object
45
46
47
|
# File 'lib/pandemic/server_side/request.rb', line 45
def wakeup_waiting_thread
@waiter.signal if @waiter
end
|