0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ClientKeepaliveHandler.h
Go to the documentation of this file.
1 /* -*- c++ -*-
2  * Copyright (C) 2007-2015 Hypertable, Inc.
3  *
4  * This file is part of Hypertable.
5  *
6  * Hypertable is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 3
9  * of the License, or any later version.
10  *
11  * Hypertable is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301, USA.
20  */
21 
22 #ifndef Hyperspace_ClientKeepaliveHandler_h
23 #define Hyperspace_ClientKeepaliveHandler_h
24 
27 
28 #include <AsyncComm/Comm.h>
30 
31 #include <Common/Time.h>
32 #include <Common/StringExt.h>
33 #include <Common/Properties.h>
34 
35 #include <cassert>
36 #include <chrono>
37 #include <condition_variable>
38 #include <mutex>
39 #include <set>
40 #include <unordered_map>
41 #include <vector>
42 
43 namespace Hyperspace {
44 
45  class Session;
46 
47  /*
48  *
49  */
51 
52  public:
54 
55  void start();
56 
57  virtual void handle(Hypertable::EventPtr &event);
58 
59  void register_handle(ClientHandleStatePtr &handle_state) {
60  std::lock_guard<std::recursive_mutex> lock(m_mutex);
61 #ifndef NDEBUG
62  HandleMap::iterator iter = m_handle_map.find(handle_state->handle);
63  assert(iter == m_handle_map.end());
64 #endif
65  m_handle_map[handle_state->handle] = handle_state;
66  }
67 
68  void unregister_handle(uint64_t handle) {
69  std::lock_guard<std::recursive_mutex> lock(m_mutex);
70  m_handle_map.erase(handle);
71  }
72 
73  bool get_handle_state(uint64_t handle, ClientHandleStatePtr &handle_state) {
74  std::lock_guard<std::recursive_mutex> lock(m_mutex);
75  HandleMap::iterator iter = m_handle_map.find(handle);
76  if (iter == m_handle_map.end())
77  return false;
78  handle_state = (*iter).second;
79  return true;
80  }
81 
82  uint64_t get_session_id() {return m_session_id;}
83  void expire_session();
84 
85  void destroy_session();
87 
88  private:
89 
90  void destroy();
91 
92  std::recursive_mutex m_mutex;
93  std::chrono::steady_clock::time_point m_last_keep_alive_send_time;
94  std::chrono::steady_clock::time_point m_jeopardy_time;
95  bool m_dead {};
96  bool m_destroying {};
97  std::condition_variable_any m_cond_destroyed;
98  Comm *m_comm {};
99  uint32_t m_lease_interval {};
101  sockaddr_in m_master_addr;
103  bool m_verbose {};
105  uint64_t m_session_id {};
107  std::set<uint64_t> m_delivered_events;
108  typedef std::unordered_map<uint64_t, ClientHandleStatePtr> HandleMap;
109  HandleMap m_handle_map;
110  typedef std::unordered_map<uint64_t, std::chrono::steady_clock::time_point> BadNotificationHandleMap;
111  BadNotificationHandleMap m_bad_handle_map;
112  static const uint64_t ms_bad_notification_grace_period = 120000;
113  bool m_reconnect {};
114  uint16_t m_hyperspace_port {};
115  uint16_t m_datagram_send_port {};
116  std::vector<String> m_hyperspace_replicas;
117  };
118 
119  typedef std::shared_ptr<ClientKeepaliveHandler> ClientKeepaliveHandlerPtr;
120 
121 } // namespace Hypertable
122 
123 #endif // Hyperspace_ClientKeepaliveHandler_h
124 
std::shared_ptr< ClientKeepaliveHandler > ClientKeepaliveHandlerPtr
static const uint64_t ms_bad_notification_grace_period
Abstract base class for application dispatch handlers registered with AsyncComm.
std::unordered_map< uint64_t, std::chrono::steady_clock::time_point > BadNotificationHandleMap
Program options handling.
std::shared_ptr< Event > EventPtr
Smart pointer to Event.
Definition: Event.h:228
std::shared_ptr< ClientConnectionHandler > ClientConnectionHandlerPtr
Shared smart pointer to ClientConnectionHandler.
virtual void handle(Hypertable::EventPtr &event)
Callback method.
Hyperspace definitions
Declarations for DispatchHandler.
std::shared_ptr< Properties > PropertiesPtr
Definition: Properties.h:447
ClientConnectionHandlerPtr m_conn_handler
bool get_handle_state(uint64_t handle, ClientHandleStatePtr &handle_state)
std::unordered_map< uint64_t, ClientHandleStatePtr > HandleMap
ClientKeepaliveHandler(Comm *, PropertiesPtr &, Session *)
Time related declarations.
std::chrono::steady_clock::time_point m_jeopardy_time
Hyperspace session.
Definition: Session.h:148
Entry point to AsyncComm service.
Definition: Comm.h:61
Declarations for Comm.
std::chrono::steady_clock::time_point m_last_keep_alive_send_time
std::condition_variable_any m_cond_destroyed
void register_handle(ClientHandleStatePtr &handle_state)
std::shared_ptr< ClientHandleState > ClientHandleStatePtr
String extensions and helpers: sets, maps, append operators etc.
Address abstraction to hold either proxy name or IPv4:port address.
Definition: CommAddress.h:52