Class: Protocol::GRPC::Call
- Inherits:
-
Object
- Object
- Protocol::GRPC::Call
- Defined in:
- lib/protocol/grpc/call.rb
Overview
Represents context for a single RPC call.
Instance Attribute Summary collapse
-
#deadline ⇒ Object
readonly
Returns the value of attribute deadline.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
- #The HTTP response.(HTTPresponse.) ⇒ Object readonly
- #The underlying HTTP request.(underlyingHTTPrequest.) ⇒ Object readonly
Class Method Summary collapse
-
.for(request, response = nil) ⇒ Object
Create a new RPC call context for the given request and response.
Instance Method Summary collapse
-
#cancel! ⇒ Object
Mark this call as cancelled.
-
#cancelled? ⇒ Boolean
Check if the call was cancelled.
-
#deadline_exceeded? ⇒ Boolean
Check if the deadline has expired.
-
#initialize(request, response = nil, deadline: nil) ⇒ Call
constructor
Initialize a new RPC call context.
-
#metadata ⇒ Object
Extract metadata from request headers.
-
#peer ⇒ Object
Get peer information (client address).
- #The deadline for this call.=(deadline) ⇒ Object
-
#time_remaining ⇒ Object
Get the time remaining until the deadline.
-
#timeout ⇒ Object
Get the timeout requested by the client.
Constructor Details
#initialize(request, response = nil, deadline: nil) ⇒ Call
Initialize a new RPC call context.
30 31 32 33 34 35 |
# File 'lib/protocol/grpc/call.rb', line 30 def initialize(request, response = nil, deadline: nil) @request = request @response = response @deadline = deadline @cancelled = false end |
Instance Attribute Details
#deadline ⇒ Object (readonly)
Returns the value of attribute deadline.
44 45 46 |
# File 'lib/protocol/grpc/call.rb', line 44 def deadline @deadline end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
38 39 40 |
# File 'lib/protocol/grpc/call.rb', line 38 def request @request end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
41 42 43 |
# File 'lib/protocol/grpc/call.rb', line 41 def response @response end |
#The HTTP response.(HTTPresponse.) ⇒ Object (readonly)
41 |
# File 'lib/protocol/grpc/call.rb', line 41 attr_reader :response |
#The underlying HTTP request.(underlyingHTTPrequest.) ⇒ Object (readonly)
38 |
# File 'lib/protocol/grpc/call.rb', line 38 attr_reader :request |
Class Method Details
.for(request, response = nil) ⇒ Object
Create a new RPC call context for the given request and response.
Automatically computes a deadline from the grpc-timeout request header, if present.
18 19 20 21 22 23 24 |
# File 'lib/protocol/grpc/call.rb', line 18 def self.for(request, response = nil) if timeout = request.headers["grpc-timeout"] deadline = Async::Deadline.start(timeout.to_seconds) end return new(request, response, deadline: deadline) end |
Instance Method Details
#cancel! ⇒ Object
Mark this call as cancelled.
71 72 73 |
# File 'lib/protocol/grpc/call.rb', line 71 def cancel! @cancelled = true end |
#cancelled? ⇒ Boolean
Check if the call was cancelled.
77 78 79 |
# File 'lib/protocol/grpc/call.rb', line 77 def cancelled? @cancelled end |
#deadline_exceeded? ⇒ Boolean
Check if the deadline has expired.
60 61 62 |
# File 'lib/protocol/grpc/call.rb', line 60 def deadline_exceeded? @deadline&.expired? || false end |
#metadata ⇒ Object
Extract metadata from request headers.
48 49 50 |
# File 'lib/protocol/grpc/call.rb', line 48 def @metadata ||= Methods.(@request.headers) end |
#peer ⇒ Object
Get peer information (client address).
83 84 85 |
# File 'lib/protocol/grpc/call.rb', line 83 def peer @request.peer&.to_s end |
#The deadline for this call.=(deadline) ⇒ Object
44 |
# File 'lib/protocol/grpc/call.rb', line 44 attr_reader :deadline |
#time_remaining ⇒ Object
Get the time remaining until the deadline.
66 67 68 |
# File 'lib/protocol/grpc/call.rb', line 66 def time_remaining @deadline&.remaining end |
#timeout ⇒ Object
Get the timeout requested by the client.
54 55 56 |
# File 'lib/protocol/grpc/call.rb', line 54 def timeout @request.headers["grpc-timeout"]&.to_seconds end |