1
/* Copyright 2012 10gen Inc.
3
* Licensed under the Apache License, Version 2.0 (the "License");
4
* you may not use this file except in compliance with the License.
5
* You may obtain a copy of the License at
7
* http://www.apache.org/licenses/LICENSE-2.0
9
* Unless required by applicable law or agreed to in writing, software
10
* distributed under the License is distributed on an "AS IS" BASIS,
11
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
* See the License for the specific language governing permissions and
13
* limitations under the License.
21
#include "mongo/base/configuration_variable_manager.h"
22
#include "mongo/base/disallow_copying.h"
23
#include "mongo/base/initializer_context.h"
24
#include "mongo/base/initializer_dependency_graph.h"
25
#include "mongo/base/status.h"
30
* Class representing an initialization process.
32
* Such a process is described by a directed acyclic graph of initialization operations, the
33
* InitializerDependencyGraph, and a collection of mutable global state, the
34
* ConfigurationVariableManager. One constructs an initialization process by adding nodes and
35
* edges to the graph, and variable mappings in the variable manager. Then, one executes the
36
* process, causing each initialization operation to execute in an order that respects the
37
* programmer-established prerequistes.
40
MONGO_DISALLOW_COPYING(Initializer);
46
* Get the initializer dependency graph, presumably for the purpose of adding more nodes.
48
InitializerDependencyGraph& getInitializerDependencyGraph() { return _graph; }
51
* Get the configuration variable manager, for the purpose of describing more configurable
54
ConfigurationVariableManager& getConfigurationVariableManager() { return _configVariables; }
57
* Execute the initializer process, using the given argv and environment data as input.
59
* Returns Status::OK on success. All other returns constitute initialization failures,
60
* and the thing being initialized should be considered dead in the water.
62
Status execute(const InitializerContext::ArgumentVector& args,
63
const InitializerContext::EnvironmentMap& env) const;
67
InitializerDependencyGraph _graph;
68
ConfigurationVariableManager _configVariables;
72
* Run the global initializers.
74
* It's a programming error for this to fail, but if it does it will return a status other
77
* This means that the few initializers that might want to terminate the program by failing
78
* should probably arrange to terminate the process themselves.
80
Status runGlobalInitializers(const InitializerContext::ArgumentVector& args,
81
const InitializerContext::EnvironmentMap& env);
84
* Same as runGlobalInitializers(), except prints a brief message to std::cerr
85
* and terminates the process on failure.
87
void runGlobalInitializersOrDie(const InitializerContext::ArgumentVector& args,
88
const InitializerContext::EnvironmentMap& env);
90
void runGlobalInitializersOrDie(int argc, const char* const* argv, const char* const* envp);