0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
DispatchHandlerOperation.h
Go to the documentation of this file.
1 /*
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; version 3 of the
9  * 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 
29 #ifndef Hypertable_Master_DispatchHandlerOperation_h
30 #define Hypertable_Master_DispatchHandlerOperation_h
31 
32 #include "Context.h"
33 
35 
36 #include <AsyncComm/Comm.h>
38 
39 #include <Common/StringExt.h>
40 
41 #include <condition_variable>
42 #include <mutex>
43 #include <set>
44 
45 namespace Hypertable {
46 
47  using namespace Lib;
48 
58 
59  public:
60 
63  class Result {
64  public:
68  Result(const String &loc) : location(loc), error(Error::REQUEST_TIMEOUT) { }
69 
75  bool operator<(const Result &other) const {
76  return location.compare(other.location) < 0;
77  }
79  int error;
81  };
82 
87 
95  void start(StringSet &locations);
96 
100  virtual void start(const String &location) = 0;
101 
107  virtual void result_callback(const EventPtr &event) { }
108 
115  virtual void handle(EventPtr &event);
116 
123  bool wait_for_completion();
124 
131  void process_events();
132 
137  void get_results(std::set<Result> &results);
138 
139  protected:
140 
143 
145  RangeServer::Client m_rsclient;
146 
147  private:
148 
150  struct LtEventPtr {
151  bool operator()(const EventPtr &e1, const EventPtr &e2) const {
152  return e1->addr < e2->addr;
153  }
154  };
155 
158 
160  std::condition_variable m_cond;
161 
163  std::set<EventPtr, LtEventPtr> m_events;
164 
166  int m_outstanding {};
167 
169  int m_error_count {};
170 
173 
175  std::set<Result> m_results;
176  };
177 
179  typedef std::shared_ptr<DispatchHandlerOperation> DispatchHandlerOperationPtr;
180 
182 }
183 
184 #endif // Hypertable_Master_DispatchHandlerOperation_h
std::set< String > StringSet
STL Set managing Strings.
Definition: StringExt.h:42
static std::mutex mutex
Definition: Logger.cc:43
std::mutex m_mutex
Mutex for serializing concurrent access
std::string String
A String is simply a typedef to std::string.
Definition: String.h:44
Abstract base class for application dispatch handlers registered with AsyncComm.
std::shared_ptr< Event > EventPtr
Smart pointer to Event.
Definition: Event.h:228
std::set< Result > m_results
Set of result objects.
Declarations for RangeServerClient.
std::shared_ptr< Context > ContextPtr
Smart pointer to Context.
Definition: Context.h:265
DispatchHandler class for managing async RangeServer requests.
Declarations for DispatchHandler.
bool operator()(const EventPtr &e1, const EventPtr &e2) const
RangeServer::Client m_rsclient
Range server client object
Hypertable definitions
virtual void result_callback(const EventPtr &event)
Post-request hook method.
std::condition_variable m_cond
Condition variable used to wait for completion.
StringSet m_locations
Set of servers participating in operation.
Declarations for Comm.
std::set< EventPtr, LtEventPtr > m_events
Set of events generated by range server responses.
bool operator<(const Result &other) const
Less-than operator comparing on location member.
Strict Weak Ordering for comparing events by source address.
String extensions and helpers: sets, maps, append operators etc.
Declarations for Context.
std::shared_ptr< DispatchHandlerOperation > DispatchHandlerOperationPtr
Smart pointer to DispatchHandlerOperation.