Class: GRPC::RpcDesc
- Includes:
- Core::StatusCodes
- Defined in:
- lib/grpc/generic/rpc_desc.rb
Overview
RpcDesc is a Descriptor of an RPC method.
Defined Under Namespace
Classes: Stream
Instance Attribute Summary collapse
-
#input ⇒ Object
Returns the value of attribute input.
-
#marshal_method ⇒ Object
Returns the value of attribute marshal_method.
-
#name ⇒ Object
Returns the value of attribute name.
-
#output ⇒ Object
Returns the value of attribute output.
-
#unmarshal_method ⇒ Object
Returns the value of attribute unmarshal_method.
Instance Method Summary collapse
- #arity_error(mth, want, msg) ⇒ Object
- #assert_arity_matches(mth) ⇒ Object
- #bidi_streamer? ⇒ Boolean
- #client_streamer? ⇒ Boolean
-
#marshal_proc ⇒ Proc
{ |instance| marshalled(instance) }.
- #request_response? ⇒ Boolean
- #run_server_method(active_call, mth) ⇒ Object
- #send_status(active_client, code, details, **kw) ⇒ Object
- #server_streamer? ⇒ Boolean
-
#unmarshal_proc(target) ⇒ Proc
An unmarshal proc { |marshalled(instance)| instance }.
Instance Attribute Details
#input ⇒ Object
Returns the value of attribute input
35 36 37 |
# File 'lib/grpc/generic/rpc_desc.rb', line 35 def input @input end |
#marshal_method ⇒ Object
Returns the value of attribute marshal_method
35 36 37 |
# File 'lib/grpc/generic/rpc_desc.rb', line 35 def marshal_method @marshal_method end |
#name ⇒ Object
Returns the value of attribute name
35 36 37 |
# File 'lib/grpc/generic/rpc_desc.rb', line 35 def name @name end |
#output ⇒ Object
Returns the value of attribute output
35 36 37 |
# File 'lib/grpc/generic/rpc_desc.rb', line 35 def output @output end |
#unmarshal_method ⇒ Object
Returns the value of attribute unmarshal_method
35 36 37 |
# File 'lib/grpc/generic/rpc_desc.rb', line 35 def unmarshal_method @unmarshal_method end |
Instance Method Details
#arity_error(mth, want, msg) ⇒ Object
134 135 136 |
# File 'lib/grpc/generic/rpc_desc.rb', line 134 def arity_error(mth, want, msg) "##{mth.name}: bad arg count; got:#{mth.arity}, want:#{want}, #{msg}" end |
#assert_arity_matches(mth) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/grpc/generic/rpc_desc.rb', line 106 def assert_arity_matches(mth) if request_response? || server_streamer? if mth.arity != 2 fail arity_error(mth, 2, "should be #{mth.name}(req, call)") end else if mth.arity != 1 fail arity_error(mth, 1, "should be #{mth.name}(call)") end end end |
#bidi_streamer? ⇒ Boolean
130 131 132 |
# File 'lib/grpc/generic/rpc_desc.rb', line 130 def bidi_streamer? input.is_a?(Stream) && output.is_a?(Stream) end |
#client_streamer? ⇒ Boolean
122 123 124 |
# File 'lib/grpc/generic/rpc_desc.rb', line 122 def client_streamer? input.is_a?(Stream) && !output.is_a?(Stream) end |
#marshal_proc ⇒ Proc
Returns { |instance| marshalled(instance) }.
49 50 51 |
# File 'lib/grpc/generic/rpc_desc.rb', line 49 def marshal_proc proc { |o| o.class.method(marshal_method).call(o).to_s } end |
#request_response? ⇒ Boolean
118 119 120 |
# File 'lib/grpc/generic/rpc_desc.rb', line 118 def request_response? !input.is_a?(Stream) && !output.is_a?(Stream) end |
#run_server_method(active_call, mth) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/grpc/generic/rpc_desc.rb', line 65 def run_server_method(active_call, mth) # While a server method is running, it might be cancelled, its deadline # might be reached, the handler could throw an unknown error, or a # well-behaved handler could throw a StatusError. if request_response? req = active_call.remote_read resp = mth.call(req, active_call.single_req_view) active_call.remote_send(resp) elsif client_streamer? resp = mth.call(active_call.multi_req_view) active_call.remote_send(resp) elsif server_streamer? req = active_call.remote_read replys = mth.call(req, active_call.single_req_view) replys.each { |r| active_call.remote_send(r) } else # is a bidi_stream active_call.run_server_bidi(mth) end send_status(active_call, OK, 'OK', **active_call.) rescue BadStatus => e # this is raised by handlers that want GRPC to send an application error # code and detail message and some additional app-specific metadata. GRPC.logger.debug("app err:#{active_call}, status:#{e.code}:#{e.details}") send_status(active_call, e.code, e.details, **e.) rescue Core::CallError => e # This is raised by GRPC internals but should rarely, if ever happen. # Log it, but don't notify the other endpoint.. GRPC.logger.warn("failed call: #{active_call}\n#{e}") rescue Core::OutOfTime # This is raised when active_call#method.call exceeeds the deadline # event. Send a status of deadline exceeded GRPC.logger.warn("late call: #{active_call}") send_status(active_call, DEADLINE_EXCEEDED, 'late') rescue StandardError => e # This will usuaally be an unhandled error in the handling code. # Send back a UNKNOWN status to the client GRPC.logger.warn("failed handler: #{active_call}; sending status:UNKNOWN") GRPC.logger.warn(e) send_status(active_call, UNKNOWN, 'no reason given') end |
#send_status(active_client, code, details, **kw) ⇒ Object
138 139 140 141 142 143 144 145 |
# File 'lib/grpc/generic/rpc_desc.rb', line 138 def send_status(active_client, code, details, **kw) details = 'Not sure why' if details.nil? GRPC.logger.debug("Sending status #{code}:#{details}") active_client.send_status(code, details, code == OK, **kw) rescue StandardError => e GRPC.logger.warn("Could not send status #{code}:#{details}") GRPC.logger.warn(e) end |
#server_streamer? ⇒ Boolean
126 127 128 |
# File 'lib/grpc/generic/rpc_desc.rb', line 126 def server_streamer? !input.is_a?(Stream) && output.is_a?(Stream) end |
#unmarshal_proc(target) ⇒ Proc
Returns An unmarshal proc { |marshalled(instance)| instance }.
58 59 60 61 62 63 |
# File 'lib/grpc/generic/rpc_desc.rb', line 58 def unmarshal_proc(target) fail ArgumentError unless [:input, :output].include?(target) unmarshal_class = method(target).call unmarshal_class = unmarshal_class.type if unmarshal_class.is_a? Stream proc { |o| unmarshal_class.method(unmarshal_method).call(o) } end |