CatapultServer
v0.5.0.1 (Elephant)
|
Go to the documentation of this file.
30 namespace catapult {
namespace chain {
41 const std::string& operationName)
50 template<
typename TRemoteApiAction,
typename TRemoteApiFactory>
55 return thread::make_ready_future(ionet::NodeInteractionResult());
58 // pass in a non-owning pointer to the registry
59 auto pRemoteApiUnique = apiFactory(*packetIoPair.io(), packetIoPair.node().identityKey(), m_transactionRegistry);
60 auto pRemoteApi = utils::UniqueToShared(std::move(pRemoteApiUnique));
62 // extend the lifetimes of pRemoteApi and packetIoPair until the completion of the action
63 // (pRemoteApi is a pointer so that the reference taken by action is valid throughout the entire asynchronous action)
64 return action(*pRemoteApi).then([pRemoteApi, packetIoPair, operationName = m_operationName](auto&& resultFuture) {
65 auto result = resultFuture.get();
66 CATAPULT_LOG_LEVEL(ionet::NodeInteractionResultCode::Neutral == result ? utils::LogLevel::Trace : utils::LogLevel::Info)
67 << "completed '" << operationName << "' (" << packetIoPair.node() << ") with result " << result;
68 return ionet::NodeInteractionResult(packetIoPair.node().identityKey(), result);
73 net::PacketIoPicker& m_packetIoPicker;
74 const model::TransactionRegistry& m_transactionRegistry;
75 utils::TimeSpan m_timeout;
76 std::string m_operationName;
const model::TransactionRegistry & m_transactionRegistry
Definition: RemoteApiForwarder.h:74
def warning(*args)
Definition: colorPrint.py:10
Represents a time duration.
Definition: TimeSpan.h:30
Simplifies interacting with remote nodes via apis.
Definition: RemoteApiForwarder.h:33
Provides a way to access the result of an asynchronous operation.
Definition: Future.h:29
utils::TimeSpan m_timeout
Definition: RemoteApiForwarder.h:75
std::function< void()> action
An action function.
Definition: functions.h:27
An interface for picking packet io pairs.
Definition: PacketIoPicker.h:30
virtual ionet::NodePacketIoPair pickOne(const utils::TimeSpan &ioDuration)=0
#define CATAPULT_LOG_THROTTLE(LEVEL, THROTTLE_MILLIS)
Definition: ThrottleLogger.h:76
std::string m_operationName
Definition: RemoteApiForwarder.h:76
Definition: AddressExtractionExtension.cpp:28
A registry of transaction plugins.
Definition: TransactionPlugin.h:98
thread::future< ionet::NodeInteractionResult > processSync(TRemoteApiAction action, TRemoteApiFactory apiFactory) const
Picks a random peer and wraps an api around it using apiFactory. Finally, passes the api to action.
Definition: RemoteApiForwarder.h:51
RemoteApiForwarder(net::PacketIoPicker &packetIoPicker, const model::TransactionRegistry &transactionRegistry, const utils::TimeSpan &timeout, const std::string &operationName)
Definition: RemoteApiForwarder.h:37
net::PacketIoPicker & m_packetIoPicker
Definition: RemoteApiForwarder.h:73