Google Cloud Bigtable C++ Client  1.1.0
A C++ Client Library for Google Cloud Bigtable
data_client.cc
Go to the documentation of this file.
1 // Copyright 2017 Google Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "google/cloud/bigtable/data_client.h"
16 #include "google/cloud/bigtable/internal/common_client.h"
17 
18 namespace btproto = google::bigtable::v2;
19 
20 namespace google {
21 namespace cloud {
22 namespace bigtable {
23 inline namespace BIGTABLE_CLIENT_NS {
24 namespace internal {
25 /**
26  * Implement a simple DataClient.
27  *
28  * This implementation does not support multiple threads, or refresh
29  * authorization tokens. In other words, it is extremely bare bones.
30  */
31 class DefaultDataClient : public DataClient {
32  private:
33  // Introduce an early `private:` section because this type is used to define
34  // the public interface, it should not be part of the public interface.
35  struct DataTraits {
36  static std::string const& Endpoint(bigtable::ClientOptions& options) {
37  return options.data_endpoint();
38  }
39  };
40 
41  using Impl = bigtable::internal::CommonClient<DataTraits, btproto::Bigtable>;
42 
43  public:
44  DefaultDataClient(std::string project, std::string instance,
45  ClientOptions options)
46  : project_(std::move(project)),
47  instance_(std::move(instance)),
48  impl_(std::move(options)) {}
49 
50  DefaultDataClient(std::string project, std::string instance)
51  : DefaultDataClient(std::move(project), std::move(instance),
52  ClientOptions()) {}
53 
54  std::string const& project_id() const override;
55  std::string const& instance_id() const override;
56 
57  std::shared_ptr<grpc::Channel> Channel() override { return impl_.Channel(); }
58  void reset() override { impl_.reset(); }
59 
60  grpc::Status MutateRow(grpc::ClientContext* context,
61  btproto::MutateRowRequest const& request,
62  btproto::MutateRowResponse* response) override {
63  return impl_.Stub()->MutateRow(context, request, response);
64  }
65 
66  std::unique_ptr<
67  grpc::ClientAsyncResponseReaderInterface<btproto::MutateRowResponse>>
68  AsyncMutateRow(grpc::ClientContext* context,
69  btproto::MutateRowRequest const& request,
70  grpc::CompletionQueue* cq) override {
71  return impl_.Stub()->AsyncMutateRow(context, request, cq);
72  }
73 
74  grpc::Status CheckAndMutateRow(
75  grpc::ClientContext* context,
76  btproto::CheckAndMutateRowRequest const& request,
77  btproto::CheckAndMutateRowResponse* response) override {
78  return impl_.Stub()->CheckAndMutateRow(context, request, response);
79  }
80 
81  std::unique_ptr<grpc::ClientAsyncResponseReaderInterface<
82  google::bigtable::v2::CheckAndMutateRowResponse>>
83  AsyncCheckAndMutateRow(
84  grpc::ClientContext* context,
85  const google::bigtable::v2::CheckAndMutateRowRequest& request,
86  grpc::CompletionQueue* cq) override {
87  return impl_.Stub()->AsyncCheckAndMutateRow(context, request, cq);
88  }
89 
90  grpc::Status ReadModifyWriteRow(
91  grpc::ClientContext* context,
92  btproto::ReadModifyWriteRowRequest const& request,
93  btproto::ReadModifyWriteRowResponse* response) override {
94  return impl_.Stub()->ReadModifyWriteRow(context, request, response);
95  }
96 
97  std::unique_ptr<grpc::ClientAsyncResponseReaderInterface<
98  google::bigtable::v2::ReadModifyWriteRowResponse>>
99  AsyncReadModifyWriteRow(
100  grpc::ClientContext* context,
101  google::bigtable::v2::ReadModifyWriteRowRequest const& request,
102  grpc::CompletionQueue* cq) override {
103  return impl_.Stub()->AsyncReadModifyWriteRow(context, request, cq);
104  }
105 
106  std::unique_ptr<grpc::ClientReaderInterface<btproto::ReadRowsResponse>>
107  ReadRows(grpc::ClientContext* context,
108  btproto::ReadRowsRequest const& request) override {
109  return impl_.Stub()->ReadRows(context, request);
110  }
111 
112  std::unique_ptr<grpc::ClientAsyncReaderInterface<btproto::ReadRowsResponse>>
113  AsyncReadRows(grpc::ClientContext* context,
114  const google::bigtable::v2::ReadRowsRequest& request,
115  grpc::CompletionQueue* cq, void* tag) override {
116  return impl_.Stub()->AsyncReadRows(context, request, cq, tag);
117  }
118 
119  std::unique_ptr<::grpc::ClientAsyncReaderInterface<
120  ::google::bigtable::v2::ReadRowsResponse>>
121  PrepareAsyncReadRows(::grpc::ClientContext* context,
122  const ::google::bigtable::v2::ReadRowsRequest& request,
123  ::grpc::CompletionQueue* cq) override {
124  return impl_.Stub()->PrepareAsyncReadRows(context, request, cq);
125  }
126 
127  std::unique_ptr<grpc::ClientReaderInterface<btproto::SampleRowKeysResponse>>
128  SampleRowKeys(grpc::ClientContext* context,
129  btproto::SampleRowKeysRequest const& request) override {
130  return impl_.Stub()->SampleRowKeys(context, request);
131  }
132  std::unique_ptr<::grpc::ClientAsyncReaderInterface<
133  ::google::bigtable::v2::SampleRowKeysResponse>>
134  AsyncSampleRowKeys(
135  ::grpc::ClientContext* context,
136  const ::google::bigtable::v2::SampleRowKeysRequest& request,
137  ::grpc::CompletionQueue* cq, void* tag) override {
138  return impl_.Stub()->AsyncSampleRowKeys(context, request, cq, tag);
139  }
140 
141  std::unique_ptr<grpc::ClientReaderInterface<btproto::MutateRowsResponse>>
142  MutateRows(grpc::ClientContext* context,
143  btproto::MutateRowsRequest const& request) override {
144  return impl_.Stub()->MutateRows(context, request);
145  }
146  std::unique_ptr<::grpc::ClientAsyncReaderInterface<
147  ::google::bigtable::v2::MutateRowsResponse>>
148  AsyncMutateRows(::grpc::ClientContext* context,
149  const ::google::bigtable::v2::MutateRowsRequest& request,
150  ::grpc::CompletionQueue* cq, void* tag) override {
151  return impl_.Stub()->AsyncMutateRows(context, request, cq, tag);
152  }
153  std::unique_ptr<::grpc::ClientAsyncReaderInterface<
154  ::google::bigtable::v2::MutateRowsResponse>>
155  PrepareAsyncMutateRows(
156  ::grpc::ClientContext* context,
157  const ::google::bigtable::v2::MutateRowsRequest& request,
158  ::grpc::CompletionQueue* cq) override {
159  return impl_.Stub()->PrepareAsyncMutateRows(context, request, cq);
160  }
161 
162  private:
163  std::string project_;
164  std::string instance_;
165  Impl impl_;
166 };
167 
168 std::string const& DefaultDataClient::project_id() const { return project_; }
169 
170 std::string const& DefaultDataClient::instance_id() const { return instance_; }
171 } // namespace internal
172 
173 std::shared_ptr<DataClient> CreateDefaultDataClient(std::string project_id,
174  std::string instance_id,
175  ClientOptions options) {
176  return std::make_shared<internal::DefaultDataClient>(
177  std::move(project_id), std::move(instance_id), std::move(options));
178 }
179 
180 } // namespace BIGTABLE_CLIENT_NS
181 } // namespace bigtable
182 } // namespace cloud
183 } // namespace google
virtual std::unique_ptr<::grpc::ClientAsyncReaderInterface< ::google::bigtable::v2::MutateRowsResponse > > PrepareAsyncMutateRows(::grpc::ClientContext *context, const ::google::bigtable::v2::MutateRowsRequest &request, ::grpc::CompletionQueue *cq)=0
std::shared_ptr< DataClient > CreateDefaultDataClient(std::string project_id, std::string instance_id, ClientOptions options)
Create the default implementation of ClientInterface.
Definition: data_client.cc:173
#define BIGTABLE_CLIENT_NS
Definition: version.h:22
std::string const & data_endpoint() const
Return the current endpoint for data RPCs.
Configuration options for the Bigtable Client.
Contains all the Cloud Bigtable C++ client APIs.