MCPcopy Create free account
hub / github.com/apache/brpc / CallMethod

Method CallMethod

src/brpc/redis_cluster.cpp:231–289  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

229}
230
231void RedisClusterChannel::CallMethod(
232 const google::protobuf::MethodDescriptor* /*method*/,
233 google::protobuf::RpcController* controller_base,
234 const google::protobuf::Message* request_base,
235 google::protobuf::Message* response_base,
236 google::protobuf::Closure* done) {
237 Controller* cntl = static_cast<Controller*>(controller_base);
238 if (cntl == NULL) {
239 LOG(ERROR) << "controller is NULL";
240 if (done) {
241 done->Run();
242 }
243 return;
244 }
245
246 if (request_base == NULL ||
247 request_base->GetDescriptor() != RedisRequest::descriptor()) {
248 cntl->SetFailed(EREQUEST, "request must be RedisRequest");
249 if (done) {
250 done->Run();
251 }
252 return;
253 }
254 if (response_base == NULL ||
255 response_base->GetDescriptor() != RedisResponse::descriptor()) {
256 cntl->SetFailed(ERESPONSE, "response must be RedisResponse");
257 if (done) {
258 done->Run();
259 }
260 return;
261 }
262
263 const RedisRequest* request = static_cast<const RedisRequest*>(request_base);
264 RedisResponse* response = static_cast<RedisResponse*>(response_base);
265
266 if (done == NULL) {
267 CallMethodImpl(cntl, *request, response);
268 return;
269 }
270
271 AsyncCall* ac = new (std::nothrow) AsyncCall;
272 if (ac == NULL) {
273 cntl->SetFailed(ENOMEM, "Fail to allocate async context");
274 done->Run();
275 return;
276 }
277 ac->self = this;
278 ac->cntl = cntl;
279 ac->request = request;
280 ac->response = response;
281 ac->done = done;
282
283 bthread_t tid;
284 if (bthread_start_background(&tid, NULL, RedisClusterChannel::RunAsyncCall, ac) != 0) {
285 delete ac;
286 CallMethodImpl(cntl, *request, response);
287 done->Run();
288 }

Callers 3

SendToEndpointMethod · 0.45

Calls 4

bthread_start_backgroundFunction · 0.85
RunMethod · 0.45
GetDescriptorMethod · 0.45
SetFailedMethod · 0.45

Tested by

no test coverage detected