0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
RequestCache.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 
28 #ifndef AsyncComm_RequestCache_h
29 #define AsyncComm_RequestCache_h
30 
31 #include <AsyncComm/Clock.h>
33 
34 #include <unordered_map>
35 
36 namespace Hypertable {
37 
42  class IOHandler;
43 
50  class RequestCache {
51 
54  class CacheNode {
55  public:
57  : id(id), handler(handler), dh(dh) {}
60  uint32_t id;
65  };
66 
68  typedef std::unordered_map<uint32_t, CacheNode *> IdHandlerMap;
69 
70  public:
71 
74 
82  void insert(uint32_t id, IOHandler *handler, DispatchHandler *dh,
83  ClockT::time_point &expire);
84 
90  bool remove(uint32_t id, DispatchHandler *&handler);
91 
106  bool get_next_timeout(ClockT::time_point &now, IOHandler *&handlerp,
107  DispatchHandler *&dh,
108  ClockT::time_point *next_timeout);
109 
118  void purge_requests(IOHandler *handler, int32_t error);
119 
120  private:
121  IdHandlerMap m_id_map;
124  };
125 }
126 
127 #endif // AsyncComm_RequestCache_h
CacheNode * m_head
Head of doubly-linked list.
Definition: RequestCache.h:122
void purge_requests(IOHandler *handler, int32_t error)
Purges all requests assocated with handler.
CacheNode(uint32_t id, IOHandler *handler, DispatchHandler *dh)
Definition: RequestCache.h:56
Class used to hold pending request callback handlers.
Definition: RequestCache.h:50
chrono::time_point< fast_clock > time_point
Definition: fast_clock.h:42
Abstract base class for application dispatch handlers registered with AsyncComm.
CacheNode * next
Doubly-linked list pointers.
Definition: RequestCache.h:58
Internal cache node structure.
Definition: RequestCache.h:54
Declaration of ClockT.
IdHandlerMap m_id_map
RequestID-to-CacheNode map.
Definition: RequestCache.h:121
Declarations for DispatchHandler.
std::unordered_map< uint32_t, CacheNode * > IdHandlerMap
RequestID-to-CacheNode map.
Definition: RequestCache.h:68
IOHandler * handler
IOHandler associated with this request.
Definition: RequestCache.h:61
Base class for socket descriptor I/O handlers.
Definition: IOHandler.h:76
Hypertable definitions
ClockT::time_point expire
Absolute expiration time.
Definition: RequestCache.h:59
void insert(uint32_t id, IOHandler *handler, DispatchHandler *dh, ClockT::time_point &expire)
Inserts pending request callback handler into cache.
Definition: RequestCache.cc:43
CacheNode * m_tail
Tail of doubly-linked list.
Definition: RequestCache.h:123
DispatchHandler * dh
Callback handler to which MESSAGE, TIMEOUT, ERROR, and DISCONNECT events are delivered.
Definition: RequestCache.h:64
RequestCache()
Constructor.
Definition: RequestCache.h:73
bool get_next_timeout(ClockT::time_point &now, IOHandler *&handlerp, DispatchHandler *&dh, ClockT::time_point *next_timeout)
Removes next request that has timed out.