Samchon Framework for CPP  1.0.0
DistributedSystemArray.cpp
1 #include <samchon/protocol/master/DistributedSystemArray.hpp>
2 
3 #include <samchon/protocol/master/DistributedSystem.hpp>
4 #include <samchon/protocol/master/DistributedSystemRole.hpp>
5 
6 using namespace std;
7 using namespace samchon;
8 using namespace samchon::library;
9 using namespace samchon::protocol;
10 using namespace samchon::protocol::master;
11 
12 /* ------------------------------------------------------------------
13  CONSTRUCTORS
14 ------------------------------------------------------------------ */
15 DistributedSystemArray::DistributedSystemArray()
16  : super()
17 {
18 
19 }
20 void DistributedSystemArray::construct(shared_ptr<XML> xml)
21 {
22  super::construct(xml);
23 
24  if (xml->has("roleArray") == false)
25  return;
26 
27  shared_ptr<XMLList> &xmlList = xml->get("roleArray")->at(0)->get("role");
28  for (size_t i = 0; i < xmlList->size(); i++)
29  {
30  shared_ptr<DistributedSystemRole> role( createRole(xmlList->at(i)) );
31  role->construct(xmlList->at(i));
32 
33  roleDictionary.set(role->key(), role);
34  }
35 }
36 
37 /* ------------------------------------------------------------------
38  PROCESS
39 ------------------------------------------------------------------ */
41 {
42  allocateRoles();
43 }
45 {
46 
47 }
48 
49 /* ------------------------------------------------------------------
50  GETTERS
51 ------------------------------------------------------------------ */
52 SHARED_ENTITY_ARRAY_ELEMENT_ACCESSOR_BODY(DistributedSystemArray, DistributedSystem)
53 
54 auto DistributedSystemArray::hasRole(const string &key) const -> bool
55 {
56  return roleDictionary.has(key);
57 }
58 auto DistributedSystemArray::getRole(const string &key) const -> shared_ptr<DistributedSystemRole>
59 {
60  return roleDictionary.get(key);
61 }
62 
63 /* ------------------------------------------------------------------
64  EXPORTERS
65 ------------------------------------------------------------------ */
66 auto DistributedSystemArray::toXML() const -> shared_ptr<XML>
67 {
68  shared_ptr<XML> &xml = super::toXML();
69 
70  if (roleDictionary.empty() == true)
71  return xml;
72 
73  shared_ptr<XML> roleArray(new XML());
74  xml->setTag("roleArray");
75 
76  for (auto it = roleDictionary.begin(); it != roleDictionary.end(); it++)
77  roleArray->push_back(it->second->toXML());
78 
79  xml->push_back(roleArray);
80 
81  return xml;
82 }
virtual auto createRole(std::shared_ptr< library::XML >) -> DistributedSystemRole *=0
Factory method of a DistributedSystemRole.
virtual void construct(std::shared_ptr< library::XML >) override
Construct data of the Entity from an XML object.
Package for external system, within the framework of master.
Definition: RWMutex.hpp:4
virtual void start() override
Start interaction.
Package of libraries.
Definition: library.hpp:84
An array of distributed system drivers.
Dictionary< std::shared_ptr< DistributedSystemRole > > roleDictionary
A dictionary of role objects.
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.
virtual auto toXML() const -> std::shared_ptr< library::XML > override
Get an XML object represents the EntityGroup.
Package of network protocol and libraries.
Definition: protocol.hpp:185
A network driver for a distributed system.
virtual auto key() const -> std::string
Get a key that can identify the Entity uniquely.
Definition: Entity.cpp:15
XML is a class representing xml object.
Definition: XML.hpp:72
auto hasRole(const std::string &) const -> bool
Test whether has a role.
auto getRole(const std::string &) const -> std::shared_ptr< DistributedSystemRole >
Get a role.
virtual void construct(std::shared_ptr< library::XML > xml)
Construct data of the Entity from an XML object.
Definition: EntityGroup.hpp:90
virtual void allocateRoles()
Allocate roles to each distributed processing system.
Top level namespace of products built from samchon.
Definition: ByteArray.hpp:7