SWC-DB  v0.5.12 C++ documentations
SWC-DB© (Super Wide Column Database) - High Performance Scalable Database (https://github.com/kashirin-alex/swc-db)
ClientConnQueues.cc
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 
7 
8 namespace SWC { namespace Comm { namespace client {
9 
10 
12  stop();
13 }
14 
16  queues->remove(endpoints);
17 }
18 
19 bool Host::connect() {
20  struct Callback {
21  ConnQueuePtr ptr;
23  Callback(ConnQueuePtr&& a_ptr) noexcept : ptr(std::move(a_ptr)) { }
25  Callback(Callback&& other) noexcept : ptr(std::move(other.ptr)) { }
26  Callback(const Callback&) = delete;
27  Callback& operator=(Callback&&) = delete;
28  Callback& operator=(const Callback&) = delete;
29  ~Callback() noexcept { }
30  void operator()(const ConnHandlerPtr& conn) noexcept {
31  ptr->set(conn);
32  }
33  };
34  queues->service->get_connection<Callback>(
35  endpoints,
36  std::chrono::milliseconds(queues->cfg_conn_timeout->get()),
37  queues->cfg_conn_probes->get(),
38  shared_from_this()
39  );
40  return true;
41 }
42 
43 
44 
46 
47 void ConnQueues::print(std::ostream& out) {
48  out << "ConnQueues: ";
50  for(auto& host : *this) {
51  host->print(out);
52  out << '\n';
53  }
54 }
55 
58  for(auto& host : *this) {
59  if(has_endpoint(host->endpoints, endpoints))
60  return host;
61  }
62  return emplace_back(new Host(
63  shared_from_this(), endpoints, cfg_keepalive_ms, cfg_again_delay_ms));
64 }
65 
66 void ConnQueues::remove(const EndPoints& endpoints) {
67  Host::Ptr host;
68  {
70  for(auto it = cbegin(); it != cend(); ++it) {
71  if(has_endpoint((*it)->endpoints, endpoints)) {
72  host = std::move(*it);
73  erase(it);
74  break;
75  }
76  }
77  }
78  if(host)
79  host->stop();
80 }
81 
83  for(;;) {
84  Host::Ptr host;
85  {
87  auto it = cbegin();
88  if(it == cend())
89  break;
90  host = std::move(*it);
91  erase(it);
92  }
93  host->stop();
94  }
95  service->stop();
96 }
97 
98 
99 }}}
SWC::Core::Vector< Host::Ptr >::erase
SWC_CAN_INLINE iterator erase(size_type offset) noexcept(_NoExceptMoveAssign &&_NoExceptDestructor)
Definition: Vector.h:464
SWC::Comm::client::ConnQueues::service
const Serialized::Ptr service
Definition: ClientConnQueues.h:44
SWC::Comm::client::ConnQueues::remove
void remove(const EndPoints &endpoints)
Definition: ClientConnQueues.cc:66
SWC::Comm::client::Host
Definition: ClientConnQueues.h:17
SWC::Comm::client::ConnQueue::stop
void stop()
Definition: ClientConnQueue.cc:26
SWC::Comm::client::ConnQueue::set
void set(const ConnHandlerPtr &conn)
Definition: ClientConnQueue.cc:91
SWC::Core::MutexSptd::scope
Definition: MutexSptd.h:96
SWC::Comm::client::ConnQueues::~ConnQueues
~ConnQueues() noexcept
Definition: ClientConnQueues.cc:45
SWC::Comm::client::ConnQueues::stop
void stop()
Definition: ClientConnQueues.cc:82
SWC::Comm::has_endpoint
bool SWC_PURE_FUNC has_endpoint(const EndPoint &e1, const EndPoints &endpoints_in) noexcept
Definition: Resolver.cc:93
SWC::Comm::client::ConnQueues::get
Host::Ptr get(const EndPoints &endpoints)
Definition: ClientConnQueues.cc:56
SWC::Comm::client::Host::queues
const ConnQueuesPtr queues
Definition: ClientConnQueues.h:34
SWC::Comm::client::Host::Ptr
std::shared_ptr< Host > Ptr
Definition: ClientConnQueues.h:19
SWC_CAN_INLINE
#define SWC_CAN_INLINE
Definition: Compat.h:102
SWC
The SWC-DB C++ namespace 'SWC'.
Definition: main.cc:12
SWC::Comm::client::ConnQueues::cfg_again_delay_ms
const Config::Property::Value_int32_g::Ptr cfg_again_delay_ms
Definition: ClientConnQueues.h:48
SWC::Comm::client::ConnQueues::print
void print(std::ostream &out)
Definition: ClientConnQueues.cc:47
ClientConnQueues.h
SWC::Comm::client::Host::endpoints
const EndPoints endpoints
Definition: ClientConnQueues.h:21
SWC::Comm::client::Host::close_issued
void close_issued() override
Definition: ClientConnQueues.cc:15
SWC::Comm::ConnHandlerPtr
std::shared_ptr< ConnHandler > ConnHandlerPtr
Definition: AppContext.h:17
SWC::Core::Vector< EndPoint >
SWC::Comm::client::Host::~Host
virtual ~Host()
Definition: ClientConnQueues.cc:11
SWC::Comm::client::Host::connect
bool connect() override
Definition: ClientConnQueues.cc:19
SWC::Core::Vector< Host::Ptr >::cend
constexpr SWC_CAN_INLINE const_iterator cend() const noexcept
Definition: Vector.h:232
SWC::Comm::client::ConnQueues::m_mutex
Core::MutexSptd m_mutex
Definition: ClientConnQueues.h:81
SWC::Core::Vector< Host::Ptr >::cbegin
constexpr SWC_CAN_INLINE const_iterator cbegin() const noexcept
Definition: Vector.h:216
SWC::Comm::client::ConnQueues::cfg_keepalive_ms
const Config::Property::Value_int32_g::Ptr cfg_keepalive_ms
Definition: ClientConnQueues.h:47
SWC::Core::Vector< Host::Ptr >::emplace_back
SWC_CAN_INLINE reference emplace_back(ArgsT &&... args)
Definition: Vector.h:349
SWC::Comm::client::ConnQueue::operator=
ConnQueue & operator=(ConnQueue &&)=delete
SWC::Comm::client::ConnQueuePtr
std::shared_ptr< ConnQueue > ConnQueuePtr
Definition: ClientConnQueue.h:19