SWC-DB  v0.5.12 C++ documentations
SWC-DB© (Super Wide Column Database) - High Performance Scalable Database (https://github.com/kashirin-alex/swc-db)
CellsUpdate.h
Go to the documentation of this file.
1 /*
2  * SWC-DB© Copyright since 2019 Alex Kashirin <kashirin.alex@gmail.com>
3  * License details at <https://github.com/kashirin-alex/swc-db/#license>
4  */
5 
6 #ifndef swcdb_db_protocol_bkr_req_Committer_CellsUpdate_h
7 #define swcdb_db_protocol_bkr_req_Committer_CellsUpdate_h
8 
9 
13 
14 
15 namespace SWC { namespace Comm { namespace Protocol {
16 namespace Bkr { namespace Req {
17 
18 
19 template<typename DataT>
21  public:
22 
23  typedef std::shared_ptr<CellsUpdate> Ptr;
24  DataT data;
25 
26  template<typename... DataArgsT>
28  static Ptr make(
29  const Params::CellsUpdateReq& params,
30  StaticBuffer& snd_buf,
31  const uint32_t timeout,
32  DataArgsT&&... args) {
33  return Ptr(new CellsUpdate(
34  Buffers::make(params, snd_buf, 0, CELLS_UPDATE, timeout),
35  args...
36  ));
37  }
38 
39  template<typename... DataArgsT>
41  static Ptr make(
42  const Params::CellsUpdateReq& params,
43  const DynamicBuffer& buffer,
44  const uint32_t timeout,
45  DataArgsT&&... args) {
46  StaticBuffer snd_buf(buffer.base, buffer.fill(), false);
47  return make(params, snd_buf, timeout, args...);
48  }
49 
50  template<typename... DataArgsT>
52  static void request(
53  const Params::CellsUpdateReq& params,
54  StaticBuffer& snd_buf,
55  const uint32_t timeout,
56  DataArgsT&&... args) {
57  make(params, snd_buf, timeout, args...)->run();
58  }
59 
60  template<typename... DataArgsT>
62  static void request(
63  const Params::CellsUpdateReq& params,
64  const DynamicBuffer& buffer,
65  const uint32_t timeout,
66  DataArgsT&&... args) {
67  make(params, buffer, timeout, args...)->run();
68  }
69 
70  CellsUpdate(CellsUpdate&&) = delete;
71  CellsUpdate(const CellsUpdate&) = delete;
73  CellsUpdate& operator=(const CellsUpdate&) = delete;
74 
75  virtual ~CellsUpdate() noexcept { }
76 
77  bool run() override {
78  return data.get_clients()->brokers.put(req(), _bkr_idx);
79  }
80 
81  bool valid() override {
82  return data.valid() && !data.get_clients()->stopping();
83  }
84 
85  void handle_no_conn() override {
86  if(data.valid() && !_bkr_idx.turn_around(data.get_clients()->brokers)) {
87  run();
88  } else {
90  }
91  }
92 
93  void handle(ConnHandlerPtr, const Event::Ptr& ev) override {
94  data.callback(
95  req(),
96  Params::CellsUpdateRsp(ev->error, ev->data.base, ev->data.size)
97  );
98  }
99 
100  protected:
101 
102  template<typename... DataArgsT>
104  CellsUpdate(Buffers::Ptr&& a_cbp, DataArgsT&&... args)
105  : client::ConnQueue::ReqBase(std::move(a_cbp)),
106  data(args...), _bkr_idx() {
107  }
108 
109  private:
111 
112 };
113 
114 
115 
131 typedef Common::Req::function<
132  std::function<void(
133  void*,
136  )>
138 
139 
140 
141 }}}}}
142 
143 
144 
145 #endif // swcdb_db_protocol_bkr_req_Committer_CellsUpdate_h
SWC::Comm::Protocol::Bkr::Req::CellsUpdate::CellsUpdate
CellsUpdate(const CellsUpdate &)=delete
SWC::Comm::client::ConnQueueReqBase::req
SWC_CAN_INLINE Ptr req() noexcept
Definition: ClientConnQueue.h:39
SWC::client::Brokers::BrokerIdx
Definition: Brokers.h:23
SWC::Comm::Buffers::Ptr
std::shared_ptr< Buffers > Ptr
Definition: Buffers.h:23
SWC::Comm::Protocol::Bkr::Params::CellsUpdateReq
Definition: CellsUpdate.h:17
SWC::Comm::Protocol::Bkr::Req::CellsUpdate::request
static SWC_CAN_INLINE void request(const Params::CellsUpdateReq &params, const DynamicBuffer &buffer, const uint32_t timeout, DataArgsT &&... args)
Definition: CellsUpdate.h:62
SWC::Comm::Protocol::Bkr::Req::Functional_CellsUpdate
Common::Req::function< std::function< void(void *, const client::ConnQueue::ReqBase::Ptr &, const Params::CellsUpdateRsp &)>> Functional_CellsUpdate
Definition: CellsUpdate.h:137
SWC::Comm::Protocol::Bkr::Req::CellsUpdate::handle
void handle(ConnHandlerPtr, const Event::Ptr &ev) override
Definition: CellsUpdate.h:93
SWC::client::Query::ReqBase
Comm::client::ConnQueue::ReqBase ReqBase
Definition: Profiling.h:21
SWC::Comm::client::ConnQueueReqBase
Definition: ClientConnQueue.h:22
SWC::Comm::Protocol::Bkr::Req::CellsUpdate::handle_no_conn
void handle_no_conn() override
Definition: CellsUpdate.h:85
SWC::Comm::Protocol::Bkr::Req::CellsUpdate::CellsUpdate
SWC_CAN_INLINE CellsUpdate(Buffers::Ptr &&a_cbp, DataArgsT &&... args)
Definition: CellsUpdate.h:104
SWC::Comm::Protocol::Bkr::Req::CellsUpdate::CellsUpdate
CellsUpdate(CellsUpdate &&)=delete
handler_data.h
SWC::Comm::Protocol::Bkr::Req::CellsUpdate::run
bool run() override
Definition: CellsUpdate.h:77
SWC::Comm::Protocol::Bkr::Req::CellsUpdate::data
DataT data
Definition: CellsUpdate.h:24
SWC::Comm::Protocol::Bkr::Req::CellsUpdate
Definition: CellsUpdate.h:20
SWC_CAN_INLINE
#define SWC_CAN_INLINE
Definition: Compat.h:102
SWC::Comm::Protocol::Bkr::Req::CellsUpdate::request
static SWC_CAN_INLINE void request(const Params::CellsUpdateReq &params, StaticBuffer &snd_buf, const uint32_t timeout, DataArgsT &&... args)
Definition: CellsUpdate.h:52
SWC::Core::Buffer::base
value_type * base
Definition: Buffer.h:131
SWC
The SWC-DB C++ namespace 'SWC'.
Definition: main.cc:12
SWC::Comm::Protocol::Bkr::Req::CellsUpdate::_bkr_idx
SWC::client::Brokers::BrokerIdx _bkr_idx
Definition: CellsUpdate.h:110
CellsUpdate.h
SWC::Core::BufferDyn< StaticBuffer >
SWC::Core::Buffer
Definition: Buffer.h:18
Commands.h
SWC::Comm::Protocol::Bkr::Req::CellsUpdate::make
static SWC_CAN_INLINE Ptr make(const Params::CellsUpdateReq &params, const DynamicBuffer &buffer, const uint32_t timeout, DataArgsT &&... args)
Definition: CellsUpdate.h:41
SWC::Comm::Protocol::Bkr::Params::CellsUpdateRsp
Definition: CellsUpdate.h:44
SWC::Error::COMM_NOT_CONNECTED
@ COMM_NOT_CONNECTED
Definition: Error.h:64
SWC::Comm::ConnHandlerPtr
std::shared_ptr< ConnHandler > ConnHandlerPtr
Definition: AppContext.h:17
SWC::client::Brokers::BrokerIdx::turn_around
bool turn_around(Brokers &brks) noexcept
Definition: Brokers.cc:152
SWC::Comm::Protocol::Bkr::CELLS_UPDATE
@ CELLS_UPDATE
Definition: Commands.h:105
SWC::Comm::Protocol::Common::Req::function
Definition: handler_data.h:19
SWC::Core::BufferDyn::fill
constexpr SWC_CAN_INLINE size_t fill() const noexcept
Definition: Buffer.h:192
SWC::Comm::Protocol::Bkr::Req::CellsUpdate::make
static SWC_CAN_INLINE Ptr make(const Params::CellsUpdateReq &params, StaticBuffer &snd_buf, const uint32_t timeout, DataArgsT &&... args)
Definition: CellsUpdate.h:28
SWC::Comm::Buffers::make
static SWC_CAN_INLINE Ptr make(uint32_t reserve=0)
Definition: Buffers.h:27
SWC::Comm::Protocol::Bkr::Req::CellsUpdate::operator=
CellsUpdate & operator=(const CellsUpdate &)=delete
SWC::Comm::Protocol::Bkr::Req::CellsUpdate::valid
bool valid() override
Definition: CellsUpdate.h:81
SWC::Comm::Protocol::Bkr::Req::CellsUpdate::operator=
CellsUpdate & operator=(CellsUpdate &&)=delete
SWC::Comm::Event::Ptr
std::shared_ptr< Event > Ptr
Definition: Event.h:33
SWC::Comm::client::ConnQueueReqBase::Ptr
std::shared_ptr< ConnQueueReqBase > Ptr
Definition: ClientConnQueue.h:25
SWC::Comm::Protocol::Bkr::Req::CellsUpdate::Ptr
std::shared_ptr< CellsUpdate > Ptr
Definition: CellsUpdate.h:23
SWC::Comm::Protocol::Bkr::Req::CellsUpdate::~CellsUpdate
virtual ~CellsUpdate() noexcept
Definition: CellsUpdate.h:75