0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
hyperspace.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.
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 <Hyperspace/Config.h>
25 #include <Hyperspace/Session.h>
28 
29 #include <Tools/Lib/CommandShell.h>
30 
31 #include <AsyncComm/Comm.h>
32 
33 #include <Common/FailureInducer.h>
34 #include <Common/Init.h>
35 
36 #include <boost/algorithm/string.hpp>
37 #include <boost/thread/exceptions.hpp>
38 
39 #include <cstdio>
40 #include <string>
41 #include <vector>
42 
43 using namespace Hypertable;
44 using namespace Config;
45 using namespace Hyperspace;
46 using namespace std;
47 using namespace boost;
48 
49 
51 public:
52  virtual void jeopardy() { }
53  virtual void safe() { }
54  virtual void expired() { }
55  virtual void disconnected() { }
56  virtual void reconnected() { }
57 };
58 
59 int main(int argc, char **argv) {
60  bool silent {};
61 
63 
64  try {
65  Comm *comm;
66  CommandInterpreterPtr interp;
67  CommandShellPtr shell;
68  SessionPtr session_ptr;
69  SessionHandler session_handler;
70 
71  init_with_policy<MyPolicy>(argc, argv);
73  comm = Comm::instance();
74 
75  int32_t timeout = has("timeout") ? get_i32("timeout") : 10000;
76  silent = has("silent") && get_bool("silent");
77 
78  session_ptr = make_shared<Hyperspace::Session>(comm, properties);
79  session_ptr->add_callback(&session_handler);
80 
81  interp = session_ptr->create_hs_interpreter();
82  shell = make_shared<CommandShell>("hyperspace", "Hyperspace", interp, properties);
83  interp->set_silent(shell->silent());
84  interp->set_test_mode(shell->test_mode());
85 
86  if (has("induce-failure")) {
87  if (FailureInducer::instance == 0)
89  FailureInducer::instance->parse_option(get_str("induce-failure"));
90  }
91 
92  if(!session_ptr->wait_for_connection(timeout)) {
93  if (!silent)
94  cout << "Hyperspace CRITICAL - connect error" << endl;
95  quick_exit(2);
96  }
97 
98  HsClientState::exit_status = shell->run();
100  }
101  catch(Exception &e) {
102  if (!silent) {
103  cout << "Hyperspace CRITICAL - " << Error::get_text(e.code());
104  const char *msg = e.what();
105  if (msg && *msg)
106  cout << " - " << msg;
107  cout << endl;
108  }
109  quick_exit(2);
110  }
111  return 0;
112 }
static Comm * instance()
Creates/returns singleton instance of the Comm class.
Definition: Comm.h:72
A callback object derived from this class gets passed into the constructor of Hyperspace.
Definition: Session.h:94
The FailureInducer simulates errors.
Boost library.
Definition: Properties.cc:39
PropertiesPtr properties
This singleton map stores all options.
Definition: Config.cc:47
STL namespace.
static FailureInducer * instance
This is a singleton class.
bool has(const String &name)
Check existence of a configuration value.
Definition: Config.h:57
Hyperspace definitions
virtual void safe()
Definition: hyperspace.cc:53
std::shared_ptr< Session > SessionPtr
Definition: Session.h:734
const char * get_text(int error)
Returns a descriptive error message.
Definition: Error.cc:330
Helpers to compose init policies; allow to combine two policies into one.
Definition: Config.h:174
virtual void reconnected()
Definition: hyperspace.cc:56
Compatibility Macros for C/C++.
virtual void jeopardy()
Definition: hyperspace.cc:52
void parse_option(String spec)
Parses a spec string (as explained above) and stores it in an internal structure. ...
virtual void expired()
Definition: hyperspace.cc:54
Initialization helper for applications.
std::shared_ptr< CommandInterpreter > CommandInterpreterPtr
std::shared_ptr< CommandShell > CommandShellPtr
Definition: CommandShell.h:91
Hypertable definitions
Entry point to AsyncComm service.
Definition: Comm.h:61
Declarations for Comm.
This is a generic exception class for Hypertable.
Definition: Error.h:314
int main(int argc, char **argv)
Definition: hyperspace.cc:59
virtual void disconnected()
Definition: hyperspace.cc:55
int code() const
Returns the error code.
Definition: Error.h:391