Samchon Framework for CPP  1.0.0
ParallelSystem.cpp
1 #include <samchon/protocol/master/ParallelSystem.hpp>
2 
3 #include <samchon/protocol/master/ParallelSystemArray.hpp>
4 #include <samchon/protocol/master/PRInvokeHistoryArray.hpp>
5 #include <samchon/protocol/master/PRInvokeHistory.hpp>
6 
7 #include <samchon/library/XML.hpp>
8 #include <samchon/protocol/Invoke.hpp>
9 
10 using namespace std;
11 using namespace samchon::library;
12 using namespace samchon::protocol;
13 using namespace samchon::protocol::master;
14 
15 /* ------------------------------------------------------------------
16  CONSTRUCTORS
17 ------------------------------------------------------------------ */
18 ParallelSystem::ParallelSystem()
19  : super()
20 {
21  systemArray = nullptr;
24 
25  this->performance = 1.0;
26 }
27 ParallelSystem::~ParallelSystem()
28 {
29  delete historyArray;
30  delete progressArray;
31 }
32 
33 void ParallelSystem::construct(shared_ptr<XML> xml)
34 {
35  super::construct(xml);
36 
37  if (xml->hasProperty("performance"))
38  this->performance = xml->getProperty<double>("performance");
39 
40  if (xml->has(historyArray->TAG()) == true)
41  historyArray->construct(xml->get(historyArray->TAG())->at(0));
42 }
43 auto ParallelSystem::createChild(shared_ptr<XML> xml) -> ExternalSystemRole*
44 {
45  return nullptr;
46 }
47 
48 /* ------------------------------------------------------------------
49  CHAIN OF INVOKE MESSAGE
50 ------------------------------------------------------------------ */
51 void ParallelSystem::_replyData(shared_ptr<Invoke> invoke)
52 {
53  if (invoke->getListener() == "reportInvokeHistory")
54  {
55  InvokeHistory invokeHistory;
56  invokeHistory.construct(invoke->at(0)->getValueAsXML());
57 
58  string uid = to_string(invokeHistory.getUID());
59  if (progressArray->has(uid) == false)
60  return;
61 
62  //ERASE FROM PROGRESS AND REGISTER TO HISTORY
63  shared_ptr<PRInvokeHistory> history = progressArray->get(uid);
64  progressArray->erase(uid);
65  historyArray->push_back(history);
66 
67  //NOTIFY END
68  history->construct(invoke->at(0)->getValueAsXML());
69  history->notifyEnd();
70  }
71  else
72  replyData(invoke);
73 }
75  (
76  PRMasterHistory *masterHistory,
77  shared_ptr<Invoke> invoke, size_t index, size_t size
78  )
79 {
80  shared_ptr<Invoke> myInvoke(new Invoke(*invoke));
81  myInvoke->emplace_back(new InvokeParameter("invoke_history_index", index));
82  myInvoke->emplace_back(new InvokeParameter("invoke_history_size", size));
83 
84  try
85  {
86  sendData(myInvoke);
87  }
88  catch (exception &e)
89  {
90  throw e;
91  }
92 
93  //error on set/map iterator ???
94  //progressArray->emplace_back(new PRInvokeHistory(masterHistory, this, myInvoke));
95 }
96 
97 /* ------------------------------------------------------------------
98  EXPORTERS
99 ------------------------------------------------------------------ */
100 auto ParallelSystem::toXML() const -> shared_ptr<XML>
101 {
102  shared_ptr<XML> &xml = super::toXML();
103  xml->setProperty("performance", performance);
104 
105  return xml;
106 }
PRInvokeHistoryArray * historyArray
A list of history log for reported Invoke messages.
auto has(const std::string &key) const -> bool
Indicates whether a container has an object having the specified identifier.
A history log of an Invoke message on a master.
virtual void construct(std::shared_ptr< library::XML >) override
Construct data of the Entity from an XML object.
void sendPieceData(PRMasterHistory *, std::shared_ptr< Invoke >, size_t, size_t)
Send a message with segmentation index.
virtual auto createChild(std::shared_ptr< library::XML >) -> ExternalSystemRole *override
Factory method of a child Entity.
virtual auto toXML() const -> std::shared_ptr< library::XML > override
Get an XML object represents the EntityGroup.
Package for external system, within the framework of master.
Definition: RWMutex.hpp:4
Package of libraries.
Definition: library.hpp:84
virtual void _replyData(std::shared_ptr< Invoke >) override
A method for pre-processing replied Invoke message.
A history of an Invoke message.
virtual void sendData(std::shared_ptr< Invoke >)
Sends message to a related system.
Definition: IClient.cpp:309
virtual void replyData(std::shared_ptr< Invoke >) override
Handling replied message from an external system.
ParallelSystemArray * systemArray
A master that the system is belonged to.
An Entity and a container of children Entity objects.
Definition: EntityGroup.hpp:52
virtual auto TAG() const -> std::string
A tag name when represented by XML.
Package of network protocol and libraries.
Definition: protocol.hpp:185
PRInvokeHistoryArray * progressArray
A list of invoke messages on progress.
A role belongs to an external system.
Standard message of network I/O.
Definition: Invoke.hpp:47
virtual void construct(std::shared_ptr< library::XML >) override
Construct data of the Entity from an XML object.
virtual void construct(std::shared_ptr< library::XML >) override
Construct data of the Entity from an XML object.
auto getUID() const -> size_t
Get uid.
virtual auto toXML() const -> std::shared_ptr< library::XML > override
Get an XML object represents the EntityGroup.
XML is a class representing xml object.
Definition: XML.hpp:72
A parameter of an Invoke.
double performance
A performance index.
virtual void construct(std::shared_ptr< library::XML > xml)
Construct data of the Entity from an XML object.
Definition: EntityGroup.hpp:90
auto get(const std::string &key) -> value_type &
Access the element by specified identifier(key).