0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
DispatchHandlerOperationSystemStatus.cc
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 #include <Common/Compat.h>
22 
24 
26 
27 #include <Common/Error.h>
28 #include <Common/Logger.h>
29 #include <Common/Time.h>
30 
31 using namespace Hypertable;
32 
34  DispatchHandlerOperation(context), m_timer(timer) {
35 }
36 
37 void DispatchHandlerOperationSystemStatus::initialize(std::vector<Result> &results) {
38  for (auto &result : results)
39  m_index[result.addr] = &result;
40  m_timer.start();
41 }
42 
43 
45  CommAddress addr;
46  addr.set_proxy(location);
47  m_rsclient.status(addr, this, m_timer);
48 }
49 
50 
52  int error;
53  auto iter = m_index.find(event->addr);
54  if (iter != m_index.end()) {
55  Result *result = iter->second;
56  if (event->type == Event::MESSAGE) {
57  if ((error = Protocol::response_code(event)) != Error::OK) {
58  result->error = error;
60  }
61  else {
62  result->error = Error::OK;
63  try {
64  size_t remaining = event->payload_len - 4;
65  const uint8_t *ptr = event->payload + 4;
67  params.decode(&ptr, &remaining);
68  result->status = params.status();
69  }
70  catch (Exception &e) {
71  result->error = e.code();
72  result->message = e.what();
73  }
74  }
75  }
76  else {
77  result->error = event->error;
78  }
79  }
80  else
81  HT_WARN_OUT << "Received 'status' response from unexpected connection "
82  << event->addr.format() << HT_END;
83 }
Response parameters for open requests.
Definition: Status.h:49
void status(const CommAddress &addr, Status &status)
Issues a "status" request.
Definition: Client.cc:491
const Hypertable::Status & status() const
Gets status information.
Definition: Status.h:64
static int32_t response_code(const Event *event)
Returns the response code from an event event generated in response to a request message.
Definition: Protocol.cc:39
std::string String
A String is simply a typedef to std::string.
Definition: String.h:44
static String string_format_message(const Event *event)
Returns error message decoded standard error MESSAGE generated in response to a request message...
Definition: Protocol.cc:51
DispatchHandlerOperationSystemStatus(ContextPtr &context, Timer &timer)
Constructor.
Declarations for DispatchHandlerOperationSystemStatus.
std::shared_ptr< Event > EventPtr
Smart pointer to Event.
Definition: Event.h:228
std::shared_ptr< Context > ContextPtr
Smart pointer to Context.
Definition: Context.h:265
DispatchHandler class for managing async RangeServer requests.
Logging routines and macros.
void set_proxy(const String &str)
Sets address type to CommAddress::PROXY and proxy name to p.
Definition: CommAddress.h:76
Compatibility Macros for C/C++.
void start(const String &location) override
Issues a status request for the range server at location.
RangeServer::Client m_rsclient
Range server client object
#define HT_END
Definition: Logger.h:220
Time related declarations.
virtual void decode(const uint8_t **bufp, size_t *remainp)
Reads serialized representation of object from a buffer.
Definition: Serializable.cc:70
void initialize(std::vector< Result > &results)
Performs initialization.
#define HT_WARN_OUT
Definition: Logger.h:291
Hypertable definitions
void result_callback(const EventPtr &event) override
Handles a status request event.
void start()
Starts the timer.
Definition: Timer.h:64
Request/response message event.
Definition: Event.h:63
A timer class to keep timeout states across AsyncComm related calls.
Definition: Timer.h:44
This is a generic exception class for Hypertable.
Definition: Error.h:314
Error codes, Exception handling, error logging.
Declarations for Status response parameters.
Address abstraction to hold either proxy name or IPv4:port address.
Definition: CommAddress.h:52
int code() const
Returns the error code.
Definition: Error.h:391