Seastar
High performance C++ framework for concurrent servers
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
app-template.hh
1/*
2 * This file is open source software, licensed to you under the terms
3 * of the Apache License, Version 2.0 (the "License"). See the NOTICE file
4 * distributed with this work for additional information regarding copyright
5 * ownership. You may not use this file except in compliance with the License.
6 *
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing,
12 * software distributed under the License is distributed on an
13 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 * KIND, either express or implied. See the License for the
15 * specific language governing permissions and limitations
16 * under the License.
17 */
18/*
19 * Copyright (C) 2014 Cloudius Systems, Ltd.
20 */
21#pragma once
22
23#ifndef SEASTAR_MODULE
24#include <boost/program_options.hpp>
25#include <functional>
26#include <chrono>
27#endif
28#include <seastar/core/future.hh>
29#include <seastar/core/smp.hh>
31#include <seastar/core/sstring.hh>
32#include <seastar/util/program-options.hh>
34#include <seastar/core/scollectd.hh>
35#include <seastar/util/log-cli.hh>
36#include <seastar/util/modules.hh>
37
38namespace seastar {
39
40namespace alien {
41
42class instance;
43
44}
45
46SEASTAR_MODULE_EXPORT
47class app_template {
48public:
49 struct config {
55 sstring name = "App";
60 sstring description = "";
61 std::chrono::duration<double> default_task_quota = std::chrono::microseconds(500);
72 bool auto_handle_sigint_sigterm = true;
75 unsigned max_networking_aio_io_control_blocks = 10000;
81 size_t reserve_additional_memory_per_shard = 0;
82 config() {}
83 };
84
86 struct seastar_options : public program_options::option_group {
92 sstring name = "App";
97 sstring description = "";
108 bool auto_handle_sigint_sigterm = true;
110 reactor_options reactor_opts;
112 metrics::options metrics_opts;
114 smp_options smp_opts;
116 scollectd::options scollectd_opts;
118 log_cli::options log_opts;
119
120 seastar_options();
121 };
122
123 using configuration_reader = std::function<void (boost::program_options::variables_map&)>;
124private:
125 // unique_ptr to avoid pulling in alien.hh.
126 std::unique_ptr<alien::instance> _alien;
127 // reactor destruction is asynchronous, so we must let the last reactor
128 // destroy the smp instance
129 std::shared_ptr<smp> _smp;
130 seastar_options _opts;
131 boost::program_options::options_description _app_opts;
132 boost::program_options::options_description _seastar_opts;
133 boost::program_options::options_description _opts_conf_file;
134 boost::program_options::positional_options_description _pos_opts;
135 std::optional<boost::program_options::variables_map> _configuration;
136 configuration_reader _conf_reader;
137
138 configuration_reader get_default_configuration_reader();
139public:
140 struct positional_option {
141 const char* name;
142 const boost::program_options::value_semantic* value_semantic;
143 const char* help;
144 int max_count;
145 };
146public:
147 explicit app_template(seastar_options opts);
148 explicit app_template(config cfg = config());
149 ~app_template();
150
151 const seastar_options& options() const;
152
153 boost::program_options::options_description& get_options_description();
154 boost::program_options::options_description& get_conf_file_options_description();
155 boost::program_options::options_description_easy_init add_options();
156 void add_positional_options(std::initializer_list<positional_option> options);
157 boost::program_options::variables_map& configuration();
158 int run_deprecated(int ac, char ** av, std::function<void ()>&& func) noexcept;
159
160 void set_configuration_reader(configuration_reader conf_reader);
161
164 alien::instance& alien() { return *_alien; }
165
166 // Runs given function and terminates the application when the future it
167 // returns resolves. The value with which the future resolves will be
168 // returned by this function.
169 int run(int ac, char ** av, std::function<future<int> ()>&& func) noexcept;
170
171 // Like run() which takes std::function<future<int>()>, but returns
172 // with exit code 0 when the future returned by func resolves
173 // successfully.
174 int run(int ac, char ** av, std::function<future<> ()>&& func) noexcept;
175};
176
177}
header file for metric API layer (like prometheus or collectd)
boost::program_options::options_description get_options_description()
Options for controlling logging at run-time.
Seastar API namespace.
Definition: abort_on_ebadf.hh:26