2 #include <samchon/templates/distributed/DistributedClientArray.hpp> 3 # include <samchon/examples/interaction/MasterSystem.hpp> 4 #include <samchon/examples/interaction/base/ChiefBase.hpp> 6 #include <samchon/examples/interaction/TSPProcess.hpp> 7 #include <samchon/examples/interaction/PackerProcess.hpp> 16 :
public virtual templates::distributed::DistributedClientArray<MasterSystem>,
17 public base::ChiefBase
20 typedef templates::distributed::DistributedClientArray<MasterSystem> super;
28 monitor.reset(
new MonitorDriver(
this));
30 insertProcess(std::make_shared<TSPProcess>(
this));
31 insertProcess(std::make_shared<PackerProcess>(
this));
33 virtual ~Chief() =
default;
35 virtual void construct(std::shared_ptr<library::XML> xml)
override 37 setUID(xml->getProperty<
int>(
"uid"));
42 virtual void open(
int port)
override 44 std::thread(&MonitorDriver::connect, monitor.get()).detach();
50 virtual auto createProcess(std::shared_ptr<library::XML> xml) -> templates::distributed::DistributedProcess*
override 52 if (xml->getProperty(
"name") ==
"tsp")
53 return new TSPProcess(
this);
55 return new PackerProcess(
this);
58 virtual auto createExternalClient(std::shared_ptr<protocol::ClientDriver> driver) -> MasterSystem*
override 60 return new MasterSystem(
this, driver);
67 virtual void sendData(std::shared_ptr<protocol::Invoke> invoke)
override 72 virtual void replyData(std::shared_ptr<protocol::Invoke> invoke)
override 74 if (invoke->getListener() ==
"set_uid")
75 set_uid(invoke->front()->getValue<
size_t>());
84 sendData(std::make_shared<protocol::Invoke>(
"set_chief_uid", getUID()));
91 virtual auto TAG() const ->
std::
string override 96 virtual auto toXML() const ->
std::shared_ptr<library::XML>
override 99 xml->setProperty(
"uid", getUID());
100 xml->setProperty(
"name",
"chief");
111 std::thread(&Chief::open, &chief, 37000).detach();
121 std::cout <<
"Select what to do." << std::endl;
122 std::cout <<
" 1. Solve TSP" << std::endl;
123 std::cout <<
" 2. Solve Packer" << std::endl;
125 int no = std::cin.get();
127 std::dynamic_pointer_cast<TSPProcess>(chief.getProcess(
"tsp"))->solve();
129 std::dynamic_pointer_cast<PackerProcess>(chief.getProcess(
"packer"))->solve();
virtual void open(int port)
virtual void construct(std::shared_ptr< library::XML > xml) override
virtual void replyData(std::shared_ptr< Invoke >)=0
virtual void sendData(std::shared_ptr< protocol::Invoke > invoke)
virtual auto toXML() const -> std::shared_ptr< library::XML > override
virtual void sendData(std::shared_ptr< Invoke >)=0