0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Config.cc
Go to the documentation of this file.
1 /* -*- C++ -*-
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.
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 
28 #include "Common/Compat.h"
29 #include "Common/System.h"
30 #include <fstream>
31 #include "Config.h"
32 #include "ReactorFactory.h"
33 
34 namespace Hypertable { namespace Config {
35 
37  cmdline_desc().add_options()
38  ("workers", i32(), "Number of worker threads")
39  ("reactors", i32(), "Number of reactor threads")
40  ;
41  alias("timeout", "Hypertable.Request.Timeout");
42 }
43 
44 void init_comm() {
45  int32_t num_cores = System::get_processor_count();
46 
47  if (get_bool("verbose"))
48  std::cout <<"CPU cores count="<< num_cores << std::endl;
49 
50  int32_t reactors = get("reactors", num_cores);
51 
52  if (!has("reactors"))
53  properties->add("reactors", reactors);
54 
56 }
57 
59  cmdline_desc().add_options()
60  ("port", i16(), "Listening port")
61  ("pidfile", str(), "File to contain the process id")
62  ;
63 }
64 
66  String pidfile = get("pidfile", String());
67 
68  if (pidfile.length()) {
69  std::ofstream out(pidfile.c_str());
70 
71  if (out)
72  out << System::get_pid() << std::endl;
73  else
74  HT_FATAL_OUT <<"Could not create pid file: "<< pidfile << HT_END;
75  }
76 }
77 
78 }} // namespace Hypertable::Config
Declarations for configuration properties.
Retrieves system information (hardware, installation directory, etc)
void init_generic_server_options()
Initializes generic server options.
Definition: Config.cc:58
PropertiesPtr properties
This singleton map stores all options.
Definition: Config.cc:47
std::string String
A String is simply a typedef to std::string.
Definition: String.h:44
static void initialize(uint16_t reactor_count)
Initializes I/O reactors.
Po::typed_value< uint16_t > * i16(uint16_t *v=0)
Definition: Properties.h:174
Po::typed_value< String > * str(String *v=0)
Definition: Properties.h:166
static int32_t get_processor_count()
The processor count.
Definition: System.cc:103
void init_comm_options()
Initializes Comm-layer options.
Definition: Config.cc:36
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
void init_comm()
This method initializes the Comm-layer.
Definition: Config.cc:44
Po::typed_value< int32_t > * i32(int32_t *v=0)
Definition: Properties.h:178
Compatibility Macros for C/C++.
#define HT_END
Definition: Logger.h:220
Hypertable definitions
void init_generic_server()
Initializes generic server by writing the pidfile.
Definition: Config.cc:65
Declarations for ReactorFactory.
static int32_t get_pid()
The pid of the current process.
Definition: System.cc:132
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
#define HT_FATAL_OUT
Definition: Logger.h:347