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 "MaprBroker.h"
25 
26 #include <FsBroker/Lib/Config.h>
28 
30 #include <AsyncComm/Comm.h>
31 
32 #include <Common/Config.h>
33 #include <Common/Error.h>
34 #include <Common/FileUtils.h>
35 #include <Common/InetAddr.h>
36 #include <Common/Init.h>
37 #include <Common/Usage.h>
38 
39 #include <cstdlib>
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 Hypertable;
51 using namespace Hypertable::FsBroker;
52 using namespace Config;
53 using namespace std;
54 
55 namespace {
56 
57 struct AppPolicy : Policy {
58  static void init_options() {
59  cmdline_desc().add_options()
60  ("root", str()->default_value("fs/local"), "root directory for local "
61  "broker (if relative, it's relative to the installation directory")
62  ;
63  alias("port", "FsBroker.Local.Port");
64  alias("root", "FsBroker.Local.Root");
65  alias("workers", "FsBroker.Local.Workers");
66  alias("reactors", "FsBroker.Local.Reactors");
67  }
68 };
69 
70 typedef Meta::list<AppPolicy, FsBrokerPolicy, DefaultCommPolicy> Policies;
71 
72 } // local namespace
73 
74 
75 int main(int argc, char **argv) {
76  try {
77  init_with_policies<Policies>(argc, argv);
78  int port;
79  int worker_count = get_i32("workers");
80 
81  if (has("port"))
82  port = get_i16("port");
83  else if (has("DfsBroker.Port"))
84  port = get_i16("DfsBroker.Port");
85  else
86  port = get_i16("FsBroker.Port");
87 
88  Comm *comm = Comm::instance();
89  ApplicationQueuePtr app_queue = make_shared<ApplicationQueue>(worker_count);
90  BrokerPtr broker = make_shared<MaprBroker>(properties);
91  ConnectionHandlerFactoryPtr handler_factory =
92  make_shared<FsBroker::Lib::ConnectionHandlerFactory>(comm, app_queue, broker);
93  InetAddr listen_addr(INADDR_ANY, port);
94 
95  comm->listen(listen_addr, handler_factory);
96  app_queue->join();
97  }
98  catch (Exception &e) {
99  HT_ERROR_OUT << e << HT_END;
100  return 1;
101  }
102 
103  if (has("pidfile"))
104  FileUtils::unlink(get_str("pidfile"));
105 
106  return 0;
107 }
static Comm * instance()
Creates/returns singleton instance of the Comm class.
Definition: Comm.h:72
Interface and base of config policy.
Definition: Config.h:149
Meta::list< AppPolicy, FsBrokerPolicy, DefaultCommPolicy > Policies
Definition: main.cc:69
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.
Po::typed_value< String > * str(String *v=0)
Definition: Properties.h:166
File system broker definitions.
Definition: CephBroker.h:38
STL namespace.
int main(int argc, char **argv)
Definition: main.cc:71
Desc & cmdline_desc(const char *usage)
A macro which definds global functions like get_bool(), get_str(), get_i16() etc. ...
Definition: Config.cc:72
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
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.
Internet address wrapper classes and utility functions.
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.
Error codes, Exception handling, error logging.