CatapultServer  v0.5.0.1 (Elephant)
PluginManager.h
Go to the documentation of this file.
1 
21 #pragma once
34 #include "catapult/plugins.h"
35 
36 namespace catapult { namespace plugins {
37 
41  bool PreferCacheDatabase = false;
42 
45 
48  };
49 
51  class PluginManager {
52  private:
58 
59  using StatelessValidatorPointer = std::unique_ptr<const validators::stateless::AggregateNotificationValidator>;
60  using StatefulValidatorPointer = std::unique_ptr<const validators::stateful::AggregateNotificationValidator>;
62 
63  template<typename TUnresolved, typename TResolved>
67 
68  template<typename TUnresolved, typename TResolved>
69  using AggregateResolver = std::function<TResolved (const cache::ReadOnlyCatapultCache&, const TUnresolved&)>;
72 
73  using PublisherPointer = std::unique_ptr<model::NotificationPublisher>;
74 
75  public:
81 
82  public:
83  // region config
84 
87 
89  const StorageConfiguration& storageConfig() const;
90 
92  cache::CacheConfiguration cacheConfig(const std::string& name) const;
93 
96 
97  // endregion
98 
99  // region transactions
100 
102  void addTransactionSupport(std::unique_ptr<model::TransactionPlugin>&& pTransactionPlugin);
103 
106 
107  // endregion
108 
109  // region cache
110 
112  template<typename TStorageTraits, typename TCache>
113  void addCacheSupport(std::unique_ptr<TCache>&& pSubCache) {
114  m_cacheBuilder.add<TStorageTraits>(std::move(pSubCache));
115  }
116 
118  void addCacheSupport(std::unique_ptr<cache::SubCachePlugin>&& pSubCachePlugin);
119 
122 
123  // endregion
124 
125  // region handlers
126 
128  void addHandlerHook(const HandlerHook& hook);
129 
131  void addHandlers(ionet::ServerPacketHandlers& handlers, const cache::CatapultCache& cache) const;
132 
133  // endregion
134 
135  // region diagnostics
136 
138  void addDiagnosticHandlerHook(const HandlerHook& hook);
139 
141  void addDiagnosticCounterHook(const CounterHook& hook);
142 
144  void addDiagnosticHandlers(ionet::ServerPacketHandlers& handlers, const cache::CatapultCache& cache) const;
145 
147  void addDiagnosticCounters(std::vector<utils::DiagnosticCounter>& counters, const cache::CatapultCache& cache) const;
148 
149  // endregion
150 
151  // region validators
152 
155 
158 
161 
164 
167 
170 
171  // endregion
172 
173  // region observers
174 
176  void addObserverHook(const ObserverHook& hook);
177 
179  void addTransientObserverHook(const ObserverHook& hook);
180 
183 
186 
187  // endregion
188 
189  // region resolvers
190 
192  void addMosaicResolver(const MosaicResolver& resolver);
193 
195  void addAddressResolver(const AddressResolver& resolver);
196 
199 
200  // endregion
201 
202  // region publisher
203 
206 
207  // endregion
208 
209  private:
215 
216  std::vector<HandlerHook> m_nonDiagnosticHandlerHooks;
217  std::vector<HandlerHook> m_diagnosticHandlerHooks;
218  std::vector<CounterHook> m_diagnosticCounterHooks;
219  std::vector<StatelessValidatorHook> m_statelessValidatorHooks;
220  std::vector<StatefulValidatorHook> m_statefulValidatorHooks;
221  std::vector<ObserverHook> m_observerHooks;
222  std::vector<ObserverHook> m_transientObserverHooks;
223 
224  std::vector<MosaicResolver> m_mosaicResolvers;
225  std::vector<AddressResolver> m_addressResolvers;
226  };
227 }}
228 
230 extern "C" PLUGIN_API
catapult::plugins::PluginManager::addHandlers
void addHandlers(ionet::ServerPacketHandlers &handlers, const cache::CatapultCache &cache) const
Adds all (non-diagnostic) handlers to handlers given cache.
Definition: PluginManager.cpp:106
catapult::plugins::PluginManager::addDiagnosticCounters
void addDiagnosticCounters(std::vector< utils::DiagnosticCounter > &counters, const cache::CatapultCache &cache) const
Adds all diagnostic counters to counters given cache.
Definition: PluginManager.cpp:126
catapult::plugins::PluginManager::ObserverHook
consumer< observers::DemuxObserverBuilder & > ObserverHook
Definition: PluginManager.h:57
catapult::plugins::PluginManager::createResolverContext
model::ResolverContext createResolverContext(const cache::ReadOnlyCatapultCache &cache) const
Creates a resolver context given cache.
Definition: PluginManager.cpp:210
NotificationPublisher.h
catapult::plugins::PluginManager::addTransactionSupport
void addTransactionSupport(std::unique_ptr< model::TransactionPlugin > &&pTransactionPlugin)
Adds support for a transaction described by pTransactionPlugin.
Definition: PluginManager.cpp:63
DemuxObserverBuilder.h
catapult::model::BlockChainConfiguration
Block chain configuration settings.
Definition: BlockChainConfiguration.h:33
BlockChainConfiguration.h
catapult::plugins::PluginManager::m_diagnosticCounterHooks
std::vector< CounterHook > m_diagnosticCounterHooks
Definition: PluginManager.h:218
catapult::plugins::PluginManager::m_transientObserverHooks
std::vector< ObserverHook > m_transientObserverHooks
Definition: PluginManager.h:222
catapult::plugins::PluginManager::HandlerHook
consumer< ionet::ServerPacketHandlers &, const cache::CatapultCache & > HandlerHook
Definition: PluginManager.h:53
catapult::plugins::StorageConfiguration
Additional storage configuration.
Definition: PluginManager.h:39
catapult::config::InflationConfiguration
Inflation configuration settings.
Definition: InflationConfiguration.h:29
catapult::cache::PatriciaTreeStorageMode::Enabled
Patricia tree storage should be enabled.
catapult::plugins::PluginManager::addDiagnosticHandlerHook
void addDiagnosticHandlerHook(const HandlerHook &hook)
Adds a diagnostic handler hook.
Definition: PluginManager.cpp:114
catapult::plugins::PluginManager::addDiagnosticHandlers
void addDiagnosticHandlers(ionet::ServerPacketHandlers &handlers, const cache::CatapultCache &cache) const
Adds all diagnostic handlers to handlers given cache.
Definition: PluginManager.cpp:122
catapult::plugins::PluginManager::ObserverPointer
observers::AggregateNotificationObserverPointerT< model::Notification > ObserverPointer
Definition: PluginManager.h:61
catapult::plugins::PluginManager::createObserver
ObserverPointer createObserver() const
Creates an observer.
Definition: PluginManager.cpp:172
catapult::predicate
std::function< bool(TArgs...)> predicate
A predicate function.
Definition: functions.h:31
catapult::plugins::PluginManager::PluginManager
PluginManager(const model::BlockChainConfiguration &config, const StorageConfiguration &storageConfig, const config::InflationConfiguration &inflationConfig)
Creates a new plugin manager around config, storageConfig and inflationConfig.
Definition: PluginManager.cpp:26
catapult::plugins::PluginManager::config
const model::BlockChainConfiguration & config() const
Gets the block chain configuration.
Definition: PluginManager.cpp:37
catapult::model::ResolverContext::resolve
MosaicId resolve(UnresolvedMosaicId mosaicId) const
Resolves mosaic id (mosaicId).
Definition: ResolverContext.cpp:41
catapult::plugins::PluginManager::m_config
model::BlockChainConfiguration m_config
Definition: PluginManager.h:210
catapult::model::BlockChainConfiguration::ShouldEnableVerifiableState
bool ShouldEnableVerifiableState
true if block chain should calculate state hashes so that state is fully verifiable at each block.
Definition: BlockChainConfiguration.h:39
catapult::plugins::PluginManager::m_diagnosticHandlerHooks
std::vector< HandlerHook > m_diagnosticHandlerHooks
Definition: PluginManager.h:217
catapult::model::ResolverContext
Context used to resolve unresolved types.
Definition: ResolverContext.h:28
ObserverTypes.h
catapult::model::GetUnresolvedCurrencyMosaicId
UnresolvedMosaicId GetUnresolvedCurrencyMosaicId(const BlockChainConfiguration &config)
Gets unresolved currency mosaic id from config.
Definition: BlockChainConfiguration.cpp:105
DiagnosticCounter.h
catapult::plugins::PluginManager::m_statefulValidatorHooks
std::vector< StatefulValidatorHook > m_statefulValidatorHooks
Definition: PluginManager.h:220
catapult::plugins::PluginManager::createStatefulValidator
StatefulValidatorPointer createStatefulValidator() const
Creates a stateful validator with no suppressed failures.
Definition: PluginManager.cpp:156
catapult::plugins::PluginManager::MosaicResolver
Resolver< UnresolvedMosaicId, MosaicId > MosaicResolver
Definition: PluginManager.h:65
catapult::plugins::PluginManager::createStatelessValidator
StatelessValidatorPointer createStatelessValidator() const
Creates a stateless validator with no suppressed failures.
Definition: PluginManager.cpp:147
catapult::plugins::PluginManager
A manager for registering plugins.
Definition: PluginManager.h:51
catapult::plugins::PluginManager::Resolver
predicate< const cache::ReadOnlyCatapultCache &, const TUnresolved &, TResolved & > Resolver
Definition: PluginManager.h:64
catapult::plugins::PluginManager::cacheConfig
cache::CacheConfiguration cacheConfig(const std::string &name) const
Gets the cache configuration for cache with name.
Definition: PluginManager.cpp:49
catapult::plugins::PluginManager::addAddressResolver
void addAddressResolver(const AddressResolver &resolver)
Adds an address resolver.
Definition: PluginManager.cpp:191
catapult::plugins::StorageConfiguration::PreferCacheDatabase
bool PreferCacheDatabase
Prefer using a database for cache storage.
Definition: PluginManager.h:41
CatapultCacheBuilder.h
catapult::plugins::PluginManager::m_transactionRegistry
model::TransactionRegistry m_transactionRegistry
Definition: PluginManager.h:213
catapult::plugins::PluginManager::m_addressResolvers
std::vector< AddressResolver > m_addressResolvers
Definition: PluginManager.h:225
catapult::plugins::PluginManager::m_mosaicResolvers
std::vector< MosaicResolver > m_mosaicResolvers
Definition: PluginManager.h:224
catapult::cache::CatapultCacheBuilder
Builder for creating a catapult cache around sub caches.
Definition: CatapultCacheBuilder.h:29
InflationConfiguration.h
PacketHandlers.h
catapult::plugins::PluginManager::m_inflationConfig
config::InflationConfiguration m_inflationConfig
Definition: PluginManager.h:212
plugins.h
catapult::plugins::PluginManager::m_observerHooks
std::vector< ObserverHook > m_observerHooks
Definition: PluginManager.h:221
PLUGIN_API
#define PLUGIN_API
Definition: plugins.h:30
catapult::plugins::PluginManager::PublisherPointer
std::unique_ptr< model::NotificationPublisher > PublisherPointer
Definition: PluginManager.h:73
RegisterSubsystem
PLUGIN_API void RegisterSubsystem(catapult::plugins::PluginManager &manager)
Entry point for registering a dynamic module with manager.
Definition: MemoryHashCacheSystem.cpp:63
catapult::plugins::PluginManager::StatelessValidatorPointer
std::unique_ptr< const validators::stateless::AggregateNotificationValidator > StatelessValidatorPointer
Definition: PluginManager.h:59
catapult::plugins::PluginManager::createCache
cache::CatapultCache createCache()
Creates a catapult cache.
Definition: PluginManager.cpp:79
catapult::observers::AggregateNotificationObserverPointerT
std::unique_ptr< const AggregateNotificationObserverT< TNotification > > AggregateNotificationObserverPointerT
An aggregate notification observer (unique) pointer.
Definition: ObserverTypes.h:41
catapult::plugins::PluginManager::inflationConfig
const config::InflationConfiguration & inflationConfig() const
Gets the inflation configuration.
Definition: PluginManager.cpp:45
catapult::plugins::PluginManager::m_storageConfig
StorageConfiguration m_storageConfig
Definition: PluginManager.h:211
catapult::plugins::PluginManager::addCacheSupport
void addCacheSupport(std::unique_ptr< TCache > &&pSubCache)
Adds support for a sub cache described by pSubCache.
Definition: PluginManager.h:113
TransactionPlugin.h
catapult::plugins::PluginManager::AddressResolver
Resolver< UnresolvedAddress, Address > AddressResolver
Definition: PluginManager.h:66
catapult::cache::CatapultCache
Central cache holding all sub caches.
Definition: CatapultCache.h:40
catapult::plugins::PluginManager::AggregateResolver
std::function< TResolved(const cache::ReadOnlyCatapultCache &, const TUnresolved &)> AggregateResolver
Definition: PluginManager.h:69
catapult::utils::FileSize
Represents a file size.
Definition: FileSize.h:29
catapult::plugins::StorageConfiguration::CacheDatabaseDirectory
std::string CacheDatabaseDirectory
Base directory to use for storing cache database.
Definition: PluginManager.h:44
catapult::plugins::PluginManager::AggregateAddressResolver
AggregateResolver< UnresolvedAddress, Address > AggregateAddressResolver
Definition: PluginManager.h:71
m_config
HarvestingConfiguration m_config
Definition: HarvestingService.cpp:126
catapult::plugins::PluginManager::addTransientObserverHook
void addTransientObserverHook(const ObserverHook &hook)
Adds a (transient) observer hook.
Definition: PluginManager.cpp:168
catapult::plugins::StorageConfiguration::MaxCacheDatabaseWriteBatchSize
utils::FileSize MaxCacheDatabaseWriteBatchSize
Maximum cache database write batch size.
Definition: PluginManager.h:47
catapult::validators::ValidationResultPredicate
predicate< ValidationResult > ValidationResultPredicate
Validation result predicate.
Definition: ValidatorTypes.h:42
catapult::plugins::PluginManager::createNotificationPublisher
PublisherPointer createNotificationPublisher(model::PublicationMode mode=model::PublicationMode::All) const
Creates a notification publisher for the specified mode.
Definition: PluginManager.cpp:225
catapult::observers::DemuxObserverBuilder::build
AggregateNotificationObserverPointerT< model::Notification > build()
Builds a demultiplexing observer.
Definition: DemuxObserverBuilder.h:46
catapult::plugins::PluginManager::addMosaicResolver
void addMosaicResolver(const MosaicResolver &resolver)
Adds a mosaic resolver.
Definition: PluginManager.cpp:187
catapult::cache::CacheConfiguration
Cache configuration.
Definition: CacheConfiguration.h:37
catapult::plugins::PluginManager::m_nonDiagnosticHandlerHooks
std::vector< HandlerHook > m_nonDiagnosticHandlerHooks
Definition: PluginManager.h:216
ValidatorTypes.h
catapult::plugins::PluginManager::storageConfig
const StorageConfiguration & storageConfig() const
Gets the storage configuration.
Definition: PluginManager.cpp:41
DemuxValidatorBuilder.h
catapult::plugins::PluginManager::StatefulValidatorHook
consumer< validators::stateful::DemuxValidatorBuilder & > StatefulValidatorHook
Definition: PluginManager.h:56
catapult::plugins::PluginManager::m_statelessValidatorHooks
std::vector< StatelessValidatorHook > m_statelessValidatorHooks
Definition: PluginManager.h:219
catapult::plugins::PluginManager::addDiagnosticCounterHook
void addDiagnosticCounterHook(const CounterHook &hook)
Adds a diagnostic counter hook.
Definition: PluginManager.cpp:118
PluginManager.h
catapult::cache::PatriciaTreeStorageMode::Disabled
Patricia tree storage should be disabled.
catapult::plugins::PluginManager::StatelessValidatorHook
consumer< validators::stateless::DemuxValidatorBuilder & > StatelessValidatorHook
Definition: PluginManager.h:55
catapult
Definition: AddressExtractionExtension.cpp:28
catapult::plugins::PluginManager::addObserverHook
void addObserverHook(const ObserverHook &hook)
Adds an observer hook.
Definition: PluginManager.cpp:164
catapult::model::TransactionRegistry
A registry of transaction plugins.
Definition: TransactionPlugin.h:98
catapult::model::CreateNotificationPublisher
std::unique_ptr< NotificationPublisher > CreateNotificationPublisher(const TransactionRegistry &transactionRegistry, UnresolvedMosaicId feeMosaicId, PublicationMode mode)
Definition: NotificationPublisher.cpp:191
catapult::model::MosaicFlags::All
All flags.
catapult::cache::CatapultCacheBuilder::add
void add(std::unique_ptr< TCache > &&pSubCache)
Adds pSubCache to the builder with the specified storage traits.
Definition: CatapultCacheBuilder.h:33
catapult::model::PublicationMode
PublicationMode
Publication modes.
Definition: NotificationPublisher.h:34
catapult::plugins::PluginManager::transactionRegistry
const model::TransactionRegistry & transactionRegistry() const
Gets the transaction registry.
Definition: PluginManager.cpp:67
catapult::plugins::PluginManager::StatefulValidatorPointer
std::unique_ptr< const validators::stateful::AggregateNotificationValidator > StatefulValidatorPointer
Definition: PluginManager.h:60
catapult::plugins::PluginManager::createPermanentObserver
ObserverPointer createPermanentObserver() const
Creates an observer that only observes permanent state changes.
Definition: PluginManager.cpp:179
catapult::cache::CatapultCacheBuilder::build
CatapultCache build()
Builds a catapult cache.
Definition: CatapultCacheBuilder.h:49
catapult::model::PluginRegistry::registerPlugin
void registerPlugin(std::unique_ptr< const TPlugin > &&pPlugin)
Registers pPlugin with the registry.
Definition: PluginRegistry.h:48
catapult::consumer
std::function< void(TArgs...)> consumer
A consumer function.
Definition: functions.h:35
catapult::plugins::PluginManager::m_cacheBuilder
cache::CatapultCacheBuilder m_cacheBuilder
Definition: PluginManager.h:214
catapult::ionet::ServerPacketHandlers
A collection of packet handlers where there is at most one handler per packet type.
Definition: PacketHandlers.h:62
catapult::plugins::PluginManager::addStatefulValidatorHook
void addStatefulValidatorHook(const StatefulValidatorHook &hook)
Adds a stateful validator hook.
Definition: PluginManager.cpp:138
catapult::plugins::PluginManager::CounterHook
consumer< std::vector< utils::DiagnosticCounter > &, const cache::CatapultCache & > CounterHook
Definition: PluginManager.h:54
catapult::observers::DemuxObserverBuilder
A demultiplexing observer builder.
Definition: DemuxObserverBuilder.h:30
CacheConfiguration.h
catapult::plugins::PluginManager::AggregateMosaicResolver
AggregateResolver< UnresolvedMosaicId, MosaicId > AggregateMosaicResolver
Definition: PluginManager.h:70
catapult::cache::ReadOnlyCatapultCache
A read-only overlay on top of a catapult cache.
Definition: ReadOnlyCatapultCache.h:27
catapult::plugins::PluginManager::addStatelessValidatorHook
void addStatelessValidatorHook(const StatelessValidatorHook &hook)
Adds a stateless validator hook.
Definition: PluginManager.cpp:134
catapult::plugins::PluginManager::addHandlerHook
void addHandlerHook(const HandlerHook &hook)
Adds a (non-diagnostic) handler hook.
Definition: PluginManager.cpp:102