source: src/Fragmentation/Automation/Pool/PoolWorker.hpp@ aec098

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since aec098 was aec098, checked in by Frederik Heber <heber@…>, 13 years ago

Added signal handling function to poolworker to intercept ctrl-c via PoolWorker::shutdown().

  • this is for gracefully shutting down the worker (i.e. letting server know that we are off).
  • Added PoolWorker::shutdown() function to gracefully shutdown.
  • We use RemoveFromPoolOperation() to unlist from server's pool.
  • PoolWorker now contains ref to io_Service in order to stop the service on shutdown.
  • Property mode set to 100644
File size: 2.8 KB
Line 
1/*
2 * \file PoolWorker.hpp
3 *
4 * This file strongly follows the Serialization example from the boost::asio
5 * library (see client.cpp).
6 *
7 * Created on: Feb 28, 2012
8 * Author: heber
9 */
10
11#ifndef POOLWORKER_HPP_
12#define POOLWORKER_HPP_
13
14// include config.h
15#ifdef HAVE_CONFIG_H
16#include <config.h>
17#endif
18
19#include <boost/asio.hpp>
20#include <boost/function.hpp>
21#include <vector>
22#include "Connection.hpp"
23#include "Jobs/FragmentJob.hpp"
24#include "Controller/Commands/EnrollInPoolOperation.hpp"
25#include "Controller/Commands/RemoveFromPoolOperation.hpp"
26#include "Controller/Commands/SubmitResultOperation.hpp"
27#include "Listener.hpp"
28#include "WorkerAddress.hpp"
29
30/** Receives a job from Server to execute and return FragmentResult.
31 *
32 */
33class PoolWorker
34{
35public:
36 /// Constructor starts the asynchronous connect operation.
37 PoolWorker(
38 boost::asio::io_service& io_service,
39 const std::string& host,
40 const std::string& service,
41 const std::string& listenhost,
42 const std::string& listenservice);
43
44 /** Returns the flag of the handled operation.
45 *
46 */
47 size_t getFlag() const
48 {
49 return submitOp.getFlag();
50 }
51
52 void WorkOnJob(FragmentJob::ptr &job);
53 void removeFromPool();
54 void shutdown(int sig);
55
56 class PoolListener_t : public Listener
57 {
58 public:
59 PoolListener_t(
60 boost::asio::io_service& io_service,
61 unsigned short port,
62 PoolWorker &_callback) :
63 Listener(io_service, port),
64 callback(_callback)
65 {}
66 virtual ~PoolListener_t() {}
67
68 protected:
69 /// Handle completion of a accept controller operation.
70 void handle_Accept(const boost::system::error_code& e, connection_ptr conn);
71
72 /// Controller callback function when job has been sent.
73 void handle_ReceiveJob(const boost::system::error_code& e, connection_ptr conn);
74
75 private:
76 //!> callback reference to PoolWorker for handling the job
77 PoolWorker &callback;
78
79 //!> current job
80 FragmentJob::ptr job;
81 };
82
83private:
84 //!> reference to io_service which we use for connections
85 boost::asio::io_service& io_service;
86
87 //!> The listener for the WorkerPool
88 PoolListener_t PoolListener;
89
90 //!> address of this worker
91 const WorkerAddress address;
92
93 //!> The Connection to the server for the stored operations
94 Connection connection_;
95
96 //!> operation that handles obtaining a job
97 EnrollInPoolOperation enrollOp;
98
99 //!> operation that handles submitting job's result
100 SubmitResultOperation submitOp;
101
102 //!> internally bound function such that host and service don't have to be stored, submits result
103 boost::function<void ()> submitresult;
104
105 //!> operation that handles removal from pool
106 RemoveFromPoolOperation removeOp;
107
108 //!> internally bound function such that host and service don't have to be stored, submits result
109 boost::function<void ()> removeme;
110};
111
112#endif /* POOLWORKER_HPP_ */
Note: See TracBrowser for help on using the repository browser.