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 "LocalBroker.h"
25 
26 #include <FsBroker/Lib/Config.h>
28 
30 #include <AsyncComm/Comm.h>
32 
33 #include <Common/Config.h>
34 #include <Common/Error.h>
35 #include <Common/FileUtils.h>
36 #include <Common/InetAddr.h>
37 #include <Common/Init.h>
38 #include <Common/Usage.h>
39 
40 #include <cstdlib>
41 #include <iostream>
42 #include <fstream>
43 #include <string>
44 
45 extern "C" {
46 #include <poll.h>
47 #include <sys/types.h>
48 #include <unistd.h>
49 }
50 
51 using namespace Hypertable;
52 using namespace Hypertable::FsBroker;
53 using namespace Config;
54 using namespace std;
55 
56 namespace {
57 
58  struct AppPolicy : Policy {
59  static void init_options() {
60  cmdline_desc().add_options()
61  ("root", str()->default_value("fs/local"), "root directory for local "
62  "broker (if relative, it's relative to the installation directory")
63  ;
64  alias("port", "FsBroker.Local.Port");
65  alias("root", "FsBroker.Local.Root");
66  alias("workers", "FsBroker.Local.Workers");
67  alias("reactors", "FsBroker.Local.Reactors");
68  }
69  };
70 
71  typedef Meta::list<AppPolicy, FsBrokerPolicy, DefaultCommPolicy> Policies;
72 
73 } // local namespace
74 
75 
76 int main(int argc, char **argv) {
77  try {
78  init_with_policies<Policies>(argc, argv);
79  int port;
80  int worker_count = get_i32("workers");
81 
82  if (has("port"))
83  port = get_i16("port");
84  else
85  port = get_i16("FsBroker.Port");
86 
87  // Backward compatibility
88  if (has("DfsBroker.Local.Port"))
89  port = get_i16("DfsBroker.Local.Port");
90  else if (has("DfsBroker.Port"))
91  port = get_i16("DfsBroker.Port");
92  if (has("DfsBroker.Local.Workers"))
93  worker_count = get_i32("DfsBroker.Local.Workers");
94 
95  Comm *comm = Comm::instance();
96 
97  ApplicationQueuePtr app_queue = make_shared<ApplicationQueue>(worker_count);
98  BrokerPtr broker = make_shared<LocalBroker>(properties);
99  ConnectionHandlerFactoryPtr handler_factory =
100  make_shared<FsBroker::Lib::ConnectionHandlerFactory>(comm, app_queue, broker);
101  InetAddr listen_addr(INADDR_ANY, port);
102 
103  comm->listen(listen_addr, handler_factory);
104  app_queue->join();
105  }
106  catch (Exception &e) {
107  HT_ERROR_OUT << e << HT_END;
108  return 1;
109  }
110 
111  if (has("pidfile"))
112  FileUtils::unlink(get_str("pidfile"));
113 
114  return 0;
115 }
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.
Declarations for DispatchHandler.
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.