CatapultServer  v0.5.0.1 (Elephant)
HostUtils.h
Go to the documentation of this file.
1 
21 #pragma once
24 #include "catapult/exceptions.h"
25 #include <memory>
26 #include <vector>
27 
28 namespace catapult { namespace extensions { class ProcessBootstrapper; } }
29 
30 namespace catapult { namespace local {
31 
33  template<typename THost, typename... TArgs>
34  std::unique_ptr<THost> CreateAndBootHost(TArgs&&... args) {
35  // create and boot the host
36  auto pHost = std::make_unique<THost>(std::forward<TArgs>(args)...);
37  try {
38  pHost->boot();
39  } catch (const std::exception& ex) {
40  // log the exception and rethrow as a new exception in case the exception source is a dynamic plugin
41  // (this avoids a potential crash in the calling code, which would occur if the host destructor unloads the source plugin)
42  CATAPULT_LOG(fatal) << UNHANDLED_EXCEPTION_MESSAGE("boot");
44  }
45 
46  return std::move(pHost);
47  }
48 
50  std::vector<plugins::PluginModule> LoadAllPlugins(extensions::ProcessBootstrapper& bootstrapper);
51 }}
CATAPULT_LOG
#define CATAPULT_LOG(SEV)
Writes a log entry to the default logger with SEV severity.
Definition: Logging.h:340
exceptions.h
m_pluginModules
std::vector< plugins::PluginModule > m_pluginModules
Definition: HostUtils.cpp:60
HostUtils.h
PluginModule.h
m_extensionManager
const extensions::ExtensionManager & m_extensionManager
Definition: HostUtils.cpp:57
ExceptionLogging.h
catapult::mongo::LoadPluginByName
void LoadPluginByName(MongoPluginManager &manager, PluginModules &modules, const std::string &directory, const std::string &name)
Loads a plugin named name with manager from directory into modules.
Definition: MongoPluginLoader.cpp:32
m_config
const config::CatapultConfiguration & m_config
Definition: HostUtils.cpp:56
CATAPULT_THROW_RUNTIME_ERROR
#define CATAPULT_THROW_RUNTIME_ERROR(MESSAGE)
Macro used to throw a catapult runtime error.
Definition: exceptions.h:167
UNHANDLED_EXCEPTION_MESSAGE
#define UNHANDLED_EXCEPTION_MESSAGE(ACTION)
Outputs a message for an unhandled exception that occurred during ACTION.
Definition: ExceptionLogging.h:30
catapult::local::LoadAllPlugins
std::vector< plugins::PluginModule > LoadAllPlugins(extensions::ProcessBootstrapper &bootstrapper)
Loads all plugins using bootstrapper.
Definition: HostUtils.cpp:64
catapult
Definition: AddressExtractionExtension.cpp:28
catapult::extensions::ProcessBootstrapper
Process bootstrapper.
Definition: ProcessBootstrapper.h:42
catapult::local::CreateAndBootHost
std::unique_ptr< THost > CreateAndBootHost(TArgs &&... args)
Creates and boots a host with args.
Definition: HostUtils.h:34
m_pluginManager
plugins::PluginManager & m_pluginManager
Definition: HostUtils.cpp:58
ProcessBootstrapper.h
PluginLoader.h