OmniSciDB  04ee39c94c
ThriftOps.h
Go to the documentation of this file.
1 #ifndef THRIFTOPS_H
2 #define THRIFTOPS_H
3 
4 #include "ThriftService.h"
5 #include "ThriftWithRetry.h"
6 
7 namespace {
8 struct DoNothing {
9  template <typename... T>
10  void operator()(T&&... t) {}
11 };
12 } // namespace
13 
14 template <ThriftService THRIFT_SERVICE,
15  typename CONTEXT_TYPE,
16  typename ON_SUCCESS_LAMBDA = DoNothing,
17  typename ON_FAIL_LAMBDA = DoNothing>
18 bool thrift_op(CONTEXT_TYPE& context,
19  ON_SUCCESS_LAMBDA success_op = ON_SUCCESS_LAMBDA(),
20  ON_FAIL_LAMBDA fail_op = ON_FAIL_LAMBDA(),
21  int const try_count = 1) {
22  if (thrift_with_retry(THRIFT_SERVICE, context, nullptr, try_count)) {
23  success_op(context);
24  return true;
25  }
26 
27  fail_op(context);
28  return false;
29 }
30 
31 template <ThriftService THRIFT_SERVICE,
32  typename CONTEXT_TYPE,
33  typename ON_SUCCESS_LAMBDA = DoNothing,
34  typename ON_FAIL_LAMBDA = DoNothing>
35 bool thrift_op(CONTEXT_TYPE& context,
36  char const* arg,
37  ON_SUCCESS_LAMBDA success_op = ON_SUCCESS_LAMBDA(),
38  ON_FAIL_LAMBDA fail_op = ON_FAIL_LAMBDA(),
39  int const try_count = 1) {
40  if (thrift_with_retry(THRIFT_SERVICE, context, arg, try_count)) {
41  thrift_with_retry(kGET_SERVER_STATUS, context, nullptr);
42  success_op(context);
43  return true;
44  }
45 
46  fail_op(context);
47  return false;
48 }
49 
50 #endif
bool thrift_op(CONTEXT_TYPE &context, ON_SUCCESS_LAMBDA success_op=ON_SUCCESS_LAMBDA(), ON_FAIL_LAMBDA fail_op=ON_FAIL_LAMBDA(), int const try_count=1)
Definition: ThriftOps.h:18
bool thrift_with_retry(SERVICE_ENUM which_service, CLIENT_CONTEXT &context, char const *arg, const int try_count=1)
ThriftService
Definition: ThriftService.h:4