4
* Copyright (C) 2012 10gen Inc.
6
* This program is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU Affero General Public License, version 3,
8
* as published by the Free Software Foundation.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU Affero General Public License for more details.
15
* You should have received a copy of the GNU Affero General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
24
#include "mongo/base/status.h"
25
#include "mongo/db/jsobj.h"
29
class ServerParameterSet;
32
* Lets you make server level settings easily configurable.
33
* Hooks into (set|get)Paramter, as well as command line processing
35
class ServerParameter {
37
typedef std::map< std::string, ServerParameter* > Map;
39
ServerParameter( ServerParameterSet* sps, const std::string& name,
40
bool allowedToChangeAtStartup, bool allowedToChangeAtRuntime );
41
ServerParameter( ServerParameterSet* sps, const std::string& name );
42
virtual ~ServerParameter();
44
std::string name() const { return _name; }
47
* @return if you can set on command line or config file
49
bool allowedToChangeAtStartup() const { return _allowedToChangeAtStartup; }
52
* @param if you can use (get|set)Parameter
54
bool allowedToChangeAtRuntime() const { return _allowedToChangeAtRuntime; }
57
virtual void append( BSONObjBuilder& b, const string& name ) = 0;
59
virtual Status set( const BSONElement& newValueElement ) = 0;
61
virtual Status setFromString( const string& str ) = 0;
65
bool _allowedToChangeAtStartup;
66
bool _allowedToChangeAtRuntime;
69
class ServerParameterSet {
71
typedef std::map< std::string, ServerParameter* > Map;
73
void add( ServerParameter* sp );
75
const Map& getMap() const { return _map; }
77
static ServerParameterSet* getGlobal();
84
* Implementation of ServerParameter for reading and writing a server parameter with a given
85
* name and type into a specific C++ variable.
88
class ExportedServerParameter : public ServerParameter {
92
* Construct an ExportedServerParameter in parameter set "sps", named "name", whose storage
95
* If allowedToChangeAtStartup is true, the parameter may be set at the command line,
96
* e.g. via the --setParameter switch. If allowedToChangeAtRuntime is true, the parameter
97
* may be set at runtime, e.g. via the setParameter command.
99
ExportedServerParameter( ServerParameterSet* sps, const std::string& name, T* value,
100
bool allowedToChangeAtStartup, bool allowedToChangeAtRuntime)
101
: ServerParameter( sps, name, allowedToChangeAtStartup, allowedToChangeAtRuntime ),
103
virtual ~ExportedServerParameter() {}
105
virtual void append( BSONObjBuilder& b, const string& name ) {
106
b.append( name, *_value );
109
virtual Status set( const BSONElement& newValueElement );
110
virtual Status set( const T& newValue );
112
virtual const T& get() const { return *_value; }
114
virtual Status setFromString( const string& str );
118
virtual Status validate( const T& potentialNewValue ){ return Status::OK(); }
120
T* _value; // owned elsewhere
124
#define MONGO_EXPORT_SERVER_PARAMETER_IMPL( NAME, TYPE, INITIAL_VALUE, \
125
CHANGE_AT_STARTUP, CHANGE_AT_RUNTIME ) \
126
TYPE NAME = INITIAL_VALUE; \
127
ExportedServerParameter<TYPE> _##NAME(\
128
ServerParameterSet::getGlobal(), #NAME, &NAME, CHANGE_AT_STARTUP, CHANGE_AT_RUNTIME )
131
* Create a global variable of type "TYPE" named "NAME" with the given INITIAL_VALUE. The
132
* value may be set at startup or at runtime.
134
#define MONGO_EXPORT_SERVER_PARAMETER( NAME, TYPE, INITIAL_VALUE ) \
135
MONGO_EXPORT_SERVER_PARAMETER_IMPL( NAME, TYPE, INITIAL_VALUE, true, true )
138
* Like MONGO_EXPORT_SERVER_PARAMETER, but the value may only be set at startup.
140
#define MONGO_EXPORT_STARTUP_SERVER_PARAMETER( NAME, TYPE, INITIAL_VALUE ) \
141
MONGO_EXPORT_SERVER_PARAMETER_IMPL( NAME, TYPE, INITIAL_VALUE, true, false )
144
* Like MONGO_EXPORT_SERVER_PARAMETER, but the value may only be set at runtime.
146
#define MONGO_EXPORT_RUNTIME_SERVER_PARAMETER( NAME, TYPE, INITIAL_VALUE ) \
147
MONGO_EXPORT_SERVER_PARAMETER_IMPL( NAME, TYPE, INITIAL_VALUE, false, true )
149
#include "server_parameters_inline.h"