0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ConnectionHandler.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 
22 #include <Common/Compat.h>
23 
24 #include "ConnectionHandler.h"
25 
55 
57 
60 
61 #include <Common/Error.h>
62 #include <Common/StringExt.h>
63 
64 #include <iostream>
65 
66 extern "C" {
67 #include <poll.h>
68 }
69 
70 using namespace Hypertable;
71 using namespace Hypertable::RangeServer;
72 
74 
75  if (m_shutdown &&
76  event->header.command != Lib::RangeServer::Protocol::COMMAND_SHUTDOWN &&
77  event->header.command != Lib::RangeServer::Protocol::COMMAND_STATUS) {
78  ResponseCallback cb(m_comm, event);
80  return;
81  }
82 
83  if (event->type == Event::MESSAGE) {
84  ApplicationHandler *handler = 0;
85 
86  //event->display();
87 
88  try {
89 
90  // sanity check command code
91  if (event->header.command >= Lib::RangeServer::Protocol::COMMAND_MAX)
92  HT_THROWF(Error::PROTOCOL_ERROR, "Invalid command (%llu)",
93  (Llu)event->header.command);
94 
95  switch (event->header.command) {
98  event);
99  break;
102  event);
103  break;
106  event);
107  break;
110  event);
111  break;
114  m_range_server, event);
115  break;
118  m_range_server, event);
119  break;
122  m_range_server, event);
123  break;
126  event);
127  break;
130  event);
131  break;
132 
135  event);
136  break;
138  handler = new Request::Handler::Status(m_comm, m_range_server, event);
139  break;
142  break;
144  HT_INFO("Received shutdown command");
145  m_shutdown = true;
146  handler = new Request::Handler::Shutdown(m_comm, m_range_server, event);
147  break;
150  event);
151  break;
154  event);
155  break;
158  m_range_server, event);
159  break;
162  m_range_server, event);
163  break;
166  event);
167  break;
170  break;
173  event);
174  break;
175 
178  event);
179  break;
180 
183  event);
184  break;
185 
188  event);
189  break;
190 
193  event);
194  break;
195 
198  event);
199  break;
200 
203  event);
204  break;
205 
208  break;
209 
212  break;
213 
214  default:
215  HT_THROWF(Error::PROTOCOL_ERROR, "Unimplemented command (%llu)",
216  (Llu)event->header.command);
217  }
218  m_app_queue->add(handler);
219  }
220  catch (Exception &e) {
221  ResponseCallback cb(m_comm, event);
222  HT_ERROR_OUT << e << HT_END;
223  std::string errmsg = format("%s - %s", e.what(), Error::get_text(e.code()));
224  cb.error(Error::PROTOCOL_ERROR, errmsg);
225  }
226  }
227  else {
228  HT_INFOF("%s", event->to_str().c_str());
229  }
230 
231 }
String format(const char *fmt,...)
Returns a String using printf like format facilities Vanilla snprintf is about 1.5x faster than this...
Definition: String.cc:37
long long unsigned int Llu
Shortcut for printf formats.
Definition: String.h:50
ApplicationHandler class for carrying out a RangeServer::table_maintenance_disable() request...
std::shared_ptr< Event > EventPtr
Smart pointer to Event.
Definition: Event.h:228
#define HT_INFO(msg)
Definition: Logger.h:271
Declarations for RangeServer.
Declarations for RequestHandlerTableMaintenanceDisable.
Declarations for RangeServerProtocol.
Declarations for RequestHandlerSetState.
const char * get_text(int error)
Returns a descriptive error message.
Definition: Error.cc:330
Compatibility Macros for C/C++.
Decodes set state request and calls RangeServer::set_state().
Definition: SetState.h:46
#define HT_END
Definition: Logger.h:220
#define HT_ERROR_OUT
Definition: Logger.h:301
This class is used to generate and deliver standard responses back to a client.
Hypertable definitions
Declarations for RequestHandlerGetStatistics.
virtual void handle(EventPtr &event)
Callback method.
#define HT_INFOF(msg,...)
Definition: Logger.h:272
#define HT_THROWF(_code_, _fmt_,...)
Definition: Error.h:490
Decodes "get statistics" request and calls RangeServer::get_statistics().
Definition: GetStatistics.h:47
Request/response message event.
Definition: Event.h:63
This is a generic exception class for Hypertable.
Definition: Error.h:314
Base clase for application handlers.
Declarations for RequestHandlerTableMaintenanceEnable.
Declarations for ApplicationQueue.
Declarations for ResponseCallback.
String extensions and helpers: sets, maps, append operators etc.
Error codes, Exception handling, error logging.
ApplicationHandler class for carrying out a RangeServer::table_maintenance_enable() request...
int code() const
Returns the error code.
Definition: Error.h:391