Samchon Framework for CPP  1.0.0
ParallelSystemArrayMediator.cpp
1 #include <samchon/protocol/master/ParallelSystemArrayMediator.hpp>
2 
3 #include <samchon/protocol/master/ParallelSlaveSystemMediator.hpp>
4 #include <samchon/protocol/master/PRMasterHistory.hpp>
5 
6 #include <array>
7 #include <thread>
8 #include <samchon/library/XML.hpp>
9 #include <samchon/protocol/Invoke.hpp>
10 
11 using namespace std;
12 using namespace samchon::library;
13 using namespace samchon::protocol;
14 using namespace samchon::protocol::master;
15 
16 /* ------------------------------------------------------------------
17  CONSTRUCTORS
18 ------------------------------------------------------------------ */
19 ParallelSystemArrayMediator::ParallelSystemArrayMediator()
20  : super()
21 {
22  slave = nullptr;
23 }
24 ParallelSystemArrayMediator::~ParallelSystemArrayMediator()
25 {
26  delete slave;
27 }
28 
29 void ParallelSystemArrayMediator::construct(shared_ptr<XML> xml)
30 {
31  super::construct(xml);
32 
33  if (slave == nullptr)
34  return;
35 
36  if (xml->has(slave->TAG()))
37  slave->construct(xml->get(slave->TAG())->at(0));
38 }
39 
40 /* ------------------------------------------------------------------
41  PROCESS
42 ------------------------------------------------------------------ */
44 {
45  if (slave == nullptr)
46  return;
47 
48  slave->master = this;
49  slave->start();
50 
51  //STARTS EACH SYSTEM ASYNCHRONOUSLY
52  /*array<thread, 2> threadArray;
53  threadArray[0] = thread(&ParallelSystemArray::start, this);
54  threadArray[1] = thread(&ParallelSlaveSystemMediator::start, slave);
55 
56  //HOWEVER, THIS START IS SYNCHRONOUS
57  for (size_t i = 0; i < threadArray.size(); i++)
58  threadArray[i].join();*/
59 }
60 
61 /* ------------------------------------------------------------------
62  CHAIN OF INVOKE MESSAGE
63 ------------------------------------------------------------------ */
65 {
66  //RE-CALCULATE PERFORMANCE INDEX
67  super::notifyEnd(masterHistory);
68 
69  //REPORT TO ITS ORIGIN MASTER
70  slave->sendData(masterHistory->toInvoke());
71 }
72 
73 /* ------------------------------------------------------------------
74  EXPORTERS
75 ------------------------------------------------------------------ */
76 auto ParallelSystemArrayMediator::toXML() const -> shared_ptr<XML>
77 {
78  shared_ptr<XML> &xml = super::toXML();
79  if (slave != nullptr)
80  xml->push_back(slave->toXML());
81 
82  return xml;
83 }
A history log of an Invoke message on a master.
virtual auto TAG() const -> std::string override
A tag name when represented by XML.
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 notifyEnd(PRMasterHistory *)
Notify end of a master history.
virtual void sendData(std::shared_ptr< Invoke >)
Sends message to a related system.
Definition: IClient.cpp:309
virtual void notifyEnd(PRMasterHistory *)
Notify end of a master history.
An Entity and a container of children Entity objects.
Definition: EntityGroup.hpp:52
virtual auto toXML() const -> std::shared_ptr< library::XML >
Get an XML object represents the EntityGroup.
Package of network protocol and libraries.
Definition: protocol.hpp:185
virtual void start()=0
Start interaction.
ParallelSlaveSystemMediator * slave
A slave system for mediation.
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 toInvoke() const -> std::shared_ptr< Invoke >
Get an Invoke message.
ParallelSystemArrayMediator * master
A master system for mediation.
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
virtual void construct(std::shared_ptr< library::XML > xml)
Construct data of the Entity from an XML object.
Definition: EntityGroup.hpp:90