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 "QfsBroker.h"
25 
26 #include <FsBroker/Lib/Config.h>
28 
30 #include <AsyncComm/Comm.h>
31 
32 #include <Common/Config.h>
33 #include <Common/Init.h>
34 #include <Common/FileUtils.h>
35 #include <Common/System.h>
36 #include <Common/Usage.h>
37 
38 #include <iostream>
39 #include <fstream>
40 #include <string>
41 
42 extern "C" {
43 #include <poll.h>
44 #include <sys/types.h>
45 #include <unistd.h>
46 }
47 
48 using namespace Hypertable;
49 using namespace Hypertable::FsBroker;
50 using namespace Hypertable::Config;
51 using namespace std;
52 
53 namespace KFS {
54  extern std::string KFS_BUILD_VERSION_STRING;
55 }
56 
57 namespace {
58  struct AppPolicy : Policy {
59  static void init_options() {
60  alias("port", "Qfs.MetaServer.Port");
61  alias("host", "Qfs.MetaServer.Name");
62  alias("workers", "Qfs.Broker.Workers");
63  alias("reactors", "Qfs.Broker.Reactors");
64  }
65  };
66 
67  typedef Meta::list<AppPolicy, FsBrokerPolicy, DefaultCommPolicy> Policies;
68 }
69 
70 int main(int argc, char **argv) {
71  try {
72  init_with_policies<Policies>(argc, argv);
73  int port;
74  int worker_count = get_i32("workers");
75 
76  if (has("DfsBroker.Port"))
77  port = get_i16("DfsBroker.Port");
78  else
79  port = get_i16("FsBroker.Port");
80 
81  Comm *comm = Comm::instance();
82 
83  ApplicationQueuePtr app_queue = make_shared<ApplicationQueue>(worker_count);
84  BrokerPtr broker = make_shared<QfsBroker>(properties);
85 
86  ConnectionHandlerFactoryPtr handler_factory =
87  make_shared<FsBroker::Lib::ConnectionHandlerFactory>(comm, app_queue, broker);
88  InetAddr listen_addr(INADDR_ANY, port);
89 
90  comm->listen(listen_addr, handler_factory);
91  app_queue->join();
92  }
93  catch (Exception &e) {
94  HT_ERROR_OUT << e << HT_END;
95  return 1;
96  }
97 
98  if (has("pidfile"))
99  FileUtils::unlink(get_str("pidfile"));
100 
101  return 0;
102 }
static Comm * instance()
Creates/returns singleton instance of the Comm class.
Definition: Comm.h:72
Retrieves system information (hardware, installation directory, etc)
Interface and base of config policy.
Definition: Config.h:149
Meta::list< AppPolicy, FsBrokerPolicy, DefaultCommPolicy > Policies
Definition: main.cc:69
std::string KFS_BUILD_VERSION_STRING
PropertiesPtr properties
This singleton map stores all options.
Definition: Config.cc:47
static bool unlink(const String &fname)
Unlinks (deletes) a file or directory.
Definition: FileUtils.cc:427
Helper class for printing usage banners on the command line.
File system broker definitions.
Definition: CephBroker.h:38
STL namespace.
int main(int argc, char **argv)
Definition: main.cc:71
bool has(const String &name)
Check existence of a configuration value.
Definition: Config.h:57
File system utility functions.
std::shared_ptr< ConnectionHandlerFactory > ConnectionHandlerFactoryPtr
Smart pointer to ConnectionHandlerFactory.
Encapsulate an internet address.
Definition: InetAddr.h:66
Definition: main.cc:53
Compatibility Macros for C/C++.
Initialization helper for applications.
#define HT_END
Definition: Logger.h:220
#define HT_ERROR_OUT
Definition: Logger.h:301
std::shared_ptr< Broker > BrokerPtr
Smart pointer to Broker.
Definition: Broker.h:241
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
Declarations for ApplicationQueue.
Configuration settings.
void alias(const String &cmdline_opt, const String &file_opt, bool overwrite)
Setup command line option alias for config file option.
Definition: Config.cc:607
std::shared_ptr< ApplicationQueue > ApplicationQueuePtr
Shared smart pointer to ApplicationQueue object.