Class: Couchbase::Protostellar::Client Private
- Inherits:
-
Object
- Object
- Couchbase::Protostellar::Client
- Defined in:
- lib/couchbase/protostellar/client.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Instance Method Summary collapse
- #close ⇒ Object private
-
#initialize(host:, credentials:, channel_args:, call_metadata:, timeouts:) ⇒ Client
constructor
private
A new instance of Client.
- #send_request(request) ⇒ Object private
Constructor Details
#initialize(host:, credentials:, channel_args:, call_metadata:, timeouts:) ⇒ Client
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Client.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/couchbase/protostellar/client.rb', line 34 def initialize(host:, credentials:, channel_args:, call_metadata:, timeouts:) @channel = GRPC::Core::Channel.new(host, channel_args, credentials) @call_metadata = @timeouts = timeouts @stubs = { routing: Generated::Routing::V1::RoutingService::Stub.new(host, credentials, channel_override: @channel), kv: Generated::KV::V1::KvService::Stub.new(host, credentials, channel_override: @channel), query: Generated::Query::V1::QueryService::Stub.new(host, credentials, channel_override: @channel), search: Generated::Search::V1::SearchService::Stub.new(host, credentials, channel_override: @channel), analytics: Generated::Analytics::V1::AnalyticsService::Stub.new(host, credentials, channel_override: @channel), view: Generated::View::V1::ViewService::Stub.new(host, credentials, channel_override: @channel), bucket_admin: Generated::Admin::Bucket::V1::BucketAdminService::Stub.new(host, credentials, channel_override: @channel), collection_admin: Generated::Admin::Collection::V1::CollectionAdminService::Stub.new(host, credentials, channel_override: @channel), query_admin: Generated::Admin::Query::V1::QueryAdminService::Stub.new(host, credentials, channel_override: @channel), search_admin: Generated::Admin::Search::V1::SearchAdminService::Stub.new(host, credentials, channel_override: @channel), } end |
Instance Method Details
#close ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
54 55 56 |
# File 'lib/couchbase/protostellar/client.rb', line 54 def close @channel.close end |
#send_request(request) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
58 59 60 61 62 63 64 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 |
# File 'lib/couchbase/protostellar/client.rb', line 58 def send_request(request) request.set_timeout_from_defaults(@timeouts) loop do resp = @stubs[request.service].public_send(request.rpc, request.proto_request, deadline: request.deadline, metadata: @call_metadata) return resp unless resp.respond_to?(:next) # Streaming RPC - wrap it in an enumerator that handles any mid-stream errors return Enumerator.new do |y| loop do y << resp.next rescue GRPC::BadStatus => e request_behaviour = ErrorHandling.handle_grpc_error(e, request) raise request_behaviour.error unless request_behaviour.error.nil? unless request_behaviour.retry_duration.nil? raise Couchbase::Error::RequestCanceled.new("Error encountered mid-stream", request.error_context) end next end end # Simple RPC - just return it rescue GRPC::BadStatus => e request_behaviour = ErrorHandling.handle_grpc_error(e, request) unless request_behaviour.error.nil? ^ request_behaviour.retry_duration.nil? raise Couchbase::Error::CouchbaseError, "Either the error or the retry duration can be set" end raise request_behaviour.error unless request_behaviour.error.nil? unless request_behaviour.retry_duration.nil? sleep(0.001 * request_behaviour.retry_duration) next end end end |