0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
main.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; 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 
22 #include "Common/Compat.h"
23 
24 #include <Hyperspace/Config.h>
27 #include <Hyperspace/Master.h>
28 
30 #include <AsyncComm/Comm.h>
32 
33 #include <Common/Init.h>
34 #include <Common/Error.h>
35 #include <Common/InetAddr.h>
37 #include <Common/System.h>
38 #include <Common/Usage.h>
39 
40 #include <iostream>
41 #include <fstream>
42 #include <string>
43 
44 extern "C" {
45 #include <poll.h>
46 #include <sys/types.h>
47 #include <unistd.h>
48 }
49 
50 using namespace Hyperspace;
51 using namespace Hypertable;
52 using namespace Config;
53 using namespace std;
54 
55 /*
56  * Handler factory for Hyperspace master
57  */
59 
60 public:
62  : m_app_queue(app_queue), m_master(master) { }
63 
64  virtual void get_instance(DispatchHandlerPtr &dhp) {
65  dhp = make_shared<ServerConnectionHandler>(m_app_queue, m_master);
66  }
67 
68 private:
71 };
72 
73 
74 int main(int argc, char **argv) {
76 
77  try {
78  init_with_policy<AppPolicy>(argc, argv);
79 
80  Comm *comm = Comm::instance();
81  ConnectionManagerPtr conn_mgr = make_shared<ConnectionManager>(comm);
82  ServerKeepaliveHandlerPtr keepalive_handler;
83  ApplicationQueuePtr app_queue;
84  MasterPtr master =
85  make_shared<Master>(conn_mgr, properties, keepalive_handler, app_queue);
86  function<void()> sleep_callback = [master]() -> void {master->handle_sleep();};
87  function<void()> wakeup_callback = [master]() -> void {master->handle_wakeup();};
88  SleepWakeNotifier sleep_wake_notifier(sleep_callback, wakeup_callback);
89  uint16_t port = has("port") ? get_i16("port") : get_i16("Hyperspace.Replica.Port");
90  CommAddress local_addr = InetAddr(INADDR_ANY, port);
91  ConnectionHandlerFactoryPtr hf(new HandlerFactory(app_queue, master));
92  comm->listen(local_addr, hf);
93 
94  // give hyperspace message higher priority if possible
95  comm->create_datagram_receive_socket(local_addr, 0x10, keepalive_handler);
96 
97  // set up maintenance timer
98  uint32_t maintenance_interval = get_i32("Hyperspace.Maintenance.Interval");
99  DispatchHandlerPtr maintenance_dhp;
100  int error;
101 
102  hf->get_instance(maintenance_dhp);
103  if ((error = comm->set_timer(maintenance_interval, maintenance_dhp)) != Error::OK)
104  HT_FATALF("Problem setting timer - %s", Error::get_text(error));
105 
106  app_queue->join();
107 
108  HT_INFO("Exitting...");
109  }
110  catch (Exception &e) {
111  HT_ERROR_OUT << e << HT_END;
112  return 1;
113  }
114  return 0;
115 }
static Comm * instance()
Creates/returns singleton instance of the Comm class.
Definition: Comm.h:72
Declarations for ConnectionHandlerFactory.
Retrieves system information (hardware, installation directory, etc)
virtual void get_instance(DispatchHandlerPtr &dhp)
Creates a connection dispatch handler.
Definition: main.cc:64
Delivers sleep and wakeup notifications.
PropertiesPtr properties
This singleton map stores all options.
Definition: Config.cc:47
Helper class for printing usage banners on the command line.
Abstract class for creating default application dispatch handlers.
std::shared_ptr< Master > MasterPtr
Definition: Master.h:362
#define HT_INFO(msg)
Definition: Logger.h:271
STL namespace.
int main(int argc, char **argv)
Definition: main.cc:71
HandlerFactory(ApplicationQueuePtr &app_queue, MasterPtr &master)
Definition: main.cc:61
bool has(const String &name)
Check existence of a configuration value.
Definition: Config.h:57
Hyperspace definitions
std::shared_ptr< ConnectionHandlerFactory > ConnectionHandlerFactoryPtr
Smart pointer to ConnectionHandlerFactory.
const char * get_text(int error)
Returns a descriptive error message.
Definition: Error.cc:330
Encapsulate an internet address.
Definition: InetAddr.h:66
Helpers to compose init policies; allow to combine two policies into one.
Definition: Config.h:174
Compatibility Macros for C/C++.
std::shared_ptr< ServerKeepaliveHandler > ServerKeepaliveHandlerPtr
Initialization helper for applications.
#define HT_END
Definition: Logger.h:220
#define HT_ERROR_OUT
Definition: Logger.h:301
Hypertable definitions
#define HT_FATALF(msg,...)
Definition: Logger.h:343
Entry point to AsyncComm service.
Definition: Comm.h:61
Declarations for Comm.
MasterPtr m_master
Definition: main.cc:70
Declaration for SleepWakeNotifier.
Internet address wrapper classes and utility functions.
This is a generic exception class for Hypertable.
Definition: Error.h:314
std::shared_ptr< DispatchHandler > DispatchHandlerPtr
Smart pointer to DispatchHandler.
Declarations for ApplicationQueue.
std::shared_ptr< ConnectionManager > ConnectionManagerPtr
Smart pointer to ConnectionManager.
std::shared_ptr< ApplicationQueue > ApplicationQueuePtr
Shared smart pointer to ApplicationQueue object.
Error codes, Exception handling, error logging.
Address abstraction to hold either proxy name or IPv4:port address.
Definition: CommAddress.h:52
ApplicationQueuePtr m_app_queue
Definition: main.cc:69