CatapultServer  v0.5.0.1 (Elephant)
SynchronizerTaskCallbacks.h
Go to the documentation of this file.
1 
21 #pragma once
22 #include "NodeInteractionUtils.h"
23 #include "ServiceState.h"
27 
28 namespace catapult { namespace extensions {
29 
33  template<typename TRemoteApi, typename TRemoteApiFactory>
36  TRemoteApiFactory remoteApiFactory,
37  net::PacketIoPicker& packetIoPicker,
38  const extensions::ServiceState& state,
39  const std::string& taskName) {
40  auto syncTimeout = state.config().Node.SyncTimeout;
41  chain::RemoteApiForwarder forwarder(packetIoPicker, state.pluginManager().transactionRegistry(), syncTimeout, taskName);
42 
43  auto syncHandler = [&nodes = state.nodes()](auto&& future) {
44  auto result = future.get();
45  IncrementNodeInteraction(nodes, result);
47  };
48 
49  return [forwarder, syncHandler, synchronizer, remoteApiFactory]() {
50  return forwarder.processSync(synchronizer, remoteApiFactory).then(syncHandler);
51  };
52  }
53 
57  template<typename TRemoteApi, typename TRemoteApiFactory>
60  TRemoteApiFactory remoteApiFactory,
61  net::PacketIoPicker& packetIoPicker,
62  const extensions::ServiceState& state,
63  const std::string& taskName) {
64  const auto& chainSynced = state.hooks().chainSyncedPredicate();
65  auto synchronize = CreateSynchronizerTaskCallback(std::move(synchronizer), remoteApiFactory, packetIoPicker, state, taskName);
66  return [chainSynced, synchronize]() {
67  if (!chainSynced())
69 
70  return synchronize();
71  };
72  }
73 }}
catapult::thread::TaskCallback
supplier< thread::future< TaskResult > > TaskCallback
Task callback that is invoked by the scheduler.
Definition: Task.h:39
catapult::chain::RemoteNodeSynchronizer
std::function< thread::future< ionet::NodeInteractionResultCode >(const TRemoteApi &)> RemoteNodeSynchronizer
Function signature for synchronizing with a remote node.
Definition: RemoteNodeSynchronizer.h:30
RemoteNodeSynchronizer.h
catapult::extensions::CreateSynchronizerTaskCallback
thread::TaskCallback CreateSynchronizerTaskCallback(chain::RemoteNodeSynchronizer< TRemoteApi > &&synchronizer, TRemoteApiFactory remoteApiFactory, net::PacketIoPicker &packetIoPicker, const extensions::ServiceState &state, const std::string &taskName)
Definition: SynchronizerTaskCallbacks.h:34
catapult::extensions::IncrementNodeInteraction
void IncrementNodeInteraction(ionet::NodeContainer &nodes, const ionet::NodeInteractionResult &result)
Increments the interaction counter indicated by result in the node container (nodes).
Definition: NodeInteractionUtils.cpp:27
catapult::extensions::CreateChainSyncAwareSynchronizerTaskCallback
thread::TaskCallback CreateChainSyncAwareSynchronizerTaskCallback(chain::RemoteNodeSynchronizer< TRemoteApi > &&synchronizer, TRemoteApiFactory remoteApiFactory, net::PacketIoPicker &packetIoPicker, const extensions::ServiceState &state, const std::string &taskName)
Definition: SynchronizerTaskCallbacks.h:58
catapult::extensions::ServiceState::config
const auto & config() const
Gets the config.
Definition: ServiceState.h:89
catapult::chain::RemoteApiForwarder
Simplifies interacting with remote nodes via apis.
Definition: RemoteApiForwarder.h:33
catapult::thread::TaskResult::Continue
Task should repeat.
catapult::extensions::ServiceState
State that is used as part of service registration.
Definition: ServiceState.h:51
NodeInteractionUtils.h
catapult::extensions::ServiceState::nodes
auto & nodes() const
Gets the nodes.
Definition: ServiceState.h:94
catapult::thread::make_ready_future
future< T > make_ready_future(T &&value)
Produces a future that is ready immediately and holds the given value.
Definition: Future.h:126
catapult::net::PacketIoPicker
An interface for picking packet io pairs.
Definition: PacketIoPicker.h:30
catapult::extensions::ServiceState::hooks
const auto & hooks() const
Gets the server hooks.
Definition: ServiceState.h:170
PluginManager.h
catapult
Definition: AddressExtractionExtension.cpp:28
RemoteApiForwarder.h
catapult::extensions::ServiceState::pluginManager
const auto & pluginManager() const
Gets the plugin manager.
Definition: ServiceState.h:150
ServiceState.h