2 #include <samchon/templates/parallel/ParallelClientArray.hpp> 3 #include <samchon/examples/interaction/SlaveDriver.hpp> 4 #include <samchon/examples/interaction/base/MasterBase.hpp> 6 #include <samchon/examples/interaction/MonitorDriver.hpp> 7 #include <samchon/examples/interaction/ChiefDriver.hpp> 8 #include <samchon/examples/interaction/TSPRequest.hpp> 9 #include <samchon/examples/interaction/PackerRequest.hpp> 18 :
public virtual templates::parallel::ParallelClientArray<SlaveDriver>,
19 public base::MasterBase
22 typedef templates::parallel::ParallelClientArray<SlaveDriver> super;
24 std::unique_ptr<ChiefDriver> chief;
36 chief.reset(
new ChiefDriver(
this));
37 monitor.reset(
new MonitorDriver(
this));
39 tsp.reset(
new TSPRequest(
this));
40 packer.reset(
new PackerRequest(
this));
42 virtual ~Master() =
default;
44 virtual void construct(std::shared_ptr<library::XML> xml)
override 46 setUID(xml->getProperty<
int>(
"uid"));
47 name = xml->getProperty<std::string>(
"name");
52 virtual void open(
int port)
override 54 std::thread(&ChiefDriver::connect, chief.get(),
"127.0.0.1", 37000).detach();
55 std::thread(&MonitorDriver::connect, monitor.get()).detach();
61 virtual auto createExternalClient(std::shared_ptr<protocol::ClientDriver> driver) -> SlaveDriver*
63 return new SlaveDriver(
this, driver);
70 virtual auto getParent() const -> protocol::IProtocol*
override 78 virtual void sendData(std::shared_ptr<protocol::Invoke> invoke)
83 virtual void replyData(std::shared_ptr<protocol::Invoke> invoke)
85 if (invoke->getListener() ==
"set_uid")
86 set_uid(invoke->front()->getValue<
int>());
95 sendData(std::make_shared<protocol::Invoke>(
"set_master_uid", val));
102 xml->setTag(
"system");
104 getParent()->sendData(std::make_shared<protocol::Invoke>(
"construct", xml));
108 virtual auto _Complete_history(std::shared_ptr<templates::InvokeHistory> history) ->
bool override 110 bool ret = super::_Complete_history(history);
112 if (ret ==
true && p_invoke_queue.empty() ==
false)
115 p_invoke_queue.front()->complete();
116 p_invoke_queue.pop();
125 virtual auto TAG() const ->
std::
string 130 virtual auto toXML() const ->
std::shared_ptr<library::XML>
133 xml->setProperty(
"uid", getUID());
134 xml->setProperty(
"name", name);
142 static void main(
int port)
virtual void construct(std::shared_ptr< library::XML > xml)
Construct data of the Entity from an XML object.
virtual void open(int port)
virtual void replyData(std::shared_ptr< Invoke >)=0
virtual void sendData(std::shared_ptr< protocol::Invoke > invoke)
virtual void sendData(std::shared_ptr< Invoke >)=0
virtual auto toXML() const -> std::shared_ptr< library::XML >
Get an XML object represents the EntityGroup.