CatapultServer  v0.5.0.1 (Elephant)
EntitiesSynchronizer.h
Go to the documentation of this file.
1 
21 #pragma once
24 
25 namespace catapult { namespace chain {
26 
28  template<typename TSynchronizerTraits>
30  public:
31  using RemoteApiType = typename TSynchronizerTraits::RemoteApiType;
32 
33  private:
35 
36  public:
38  explicit EntitiesSynchronizer(TSynchronizerTraits&& traits) : m_traits(std::move(traits))
39  {}
40 
41  public:
44  return m_traits.apiCall(api).then([&traits = m_traits, sourcePublicKey = api.remotePublicKey()](auto&& rangeFuture) {
45  try {
46  auto range = rangeFuture.get();
47  if (range.empty())
48  return ionet::NodeInteractionResultCode::Neutral;
49 
50  CATAPULT_LOG(debug) << "peer returned " << range.size() << " " << TSynchronizerTraits::Name;
51  traits.consume(std::move(range), sourcePublicKey);
52  return ionet::NodeInteractionResultCode::Success;
53  } catch (const catapult_runtime_error& e) {
54  CATAPULT_LOG(warning) << "exception thrown while requesting " << TSynchronizerTraits::Name << ": " << e.what();
55  return ionet::NodeInteractionResultCode::Failure;
56  }
57  });
58  }
59 
60  private:
61  TSynchronizerTraits m_traits;
62  };
63 }}
FutureUtils.h
CATAPULT_LOG
#define CATAPULT_LOG(SEV)
Writes a log entry to the default logger with SEV severity.
Definition: Logging.h:340
Parser.debug
def debug(*args)
Definition: Parser.py:46
colorPrint.warning
def warning(*args)
Definition: colorPrint.py:10
NodeInteractionResultCode.h
catapult::thread::future
Provides a way to access the result of an asynchronous operation.
Definition: Future.h:29
catapult::chain::EntitiesSynchronizer
An entities synchronizer.
Definition: EntitiesSynchronizer.h:29
Name
static constexpr auto Name
Definition: PtSynchronizer.cpp:31
catapult::chain::EntitiesSynchronizer::operator()
NodeInteractionFuture operator()(const RemoteApiType &api)
Pulls entities from a remote node using api.
Definition: EntitiesSynchronizer.h:43
catapult
Definition: AddressExtractionExtension.cpp:28
catapult::catapult_error
Base class for all catapult exceptions that derives from both std::exception and boost::exception.
Definition: exceptions.h:42
catapult::chain::EntitiesSynchronizer::m_traits
TSynchronizerTraits m_traits
Definition: EntitiesSynchronizer.h:61
catapult::chain::EntitiesSynchronizer::EntitiesSynchronizer
EntitiesSynchronizer(TSynchronizerTraits &&traits)
Creates an entities synchronizer around traits.
Definition: EntitiesSynchronizer.h:38
catapult::chain::EntitiesSynchronizer::RemoteApiType
typename TSynchronizerTraits::RemoteApiType RemoteApiType
Definition: EntitiesSynchronizer.h:31