source: src/Fragmentation/Automation/Pool/PoolWorker.hpp@ 9db22d

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 9db22d was 81c96b6, checked in by Frederik Heber <heber@…>, 13 years ago

FIX: Listener (and PoolWorker) now check whether address to listen on is in use.

  • we use acceptor construction as given in boost::asio::basic_socket_acceptor to listen on the desired port. Bind gives error code when error occurs.
  • Property mode set to 100644
File size: 2.9 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 "Operations/Workers/EnrollInPoolOperation.hpp"
25#include "Operations/Workers/RemoveFromPoolOperation.hpp"
26#include "Operations/Workers/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() + PoolListener.getExitflag();
50 }
51
52 void WorkOnJob(FragmentJob::ptr &job);
53 void removeFromPool();
54 void shutdown(int sig);
55 void shutdown();
56
57 class PoolListener_t : public Listener
58 {
59 public:
60 PoolListener_t(
61 boost::asio::io_service& io_service,
62 unsigned short port,
63 PoolWorker &_callback) :
64 Listener(io_service, port),
65 callback(_callback)
66 {}
67 virtual ~PoolListener_t() {}
68
69 protected:
70 /// Handle completion of a accept controller operation.
71 void handle_Accept(const boost::system::error_code& e, connection_ptr conn);
72
73 /// Controller callback function when job has been sent.
74 void handle_ReceiveJob(const boost::system::error_code& e, connection_ptr conn);
75
76 private:
77 //!> callback reference to PoolWorker for handling the job
78 PoolWorker &callback;
79
80 //!> current job
81 FragmentJob::ptr job;
82 };
83
84private:
85 //!> reference to io_service which we use for connections
86 boost::asio::io_service& io_service;
87
88 //!> The listener for the WorkerPool
89 PoolListener_t PoolListener;
90
91 //!> address of this worker
92 const WorkerAddress address;
93
94 //!> The Connection to the server for the stored operations
95 Connection connection_;
96
97 //!> operation that handles obtaining a job
98 EnrollInPoolOperation enrollOp;
99
100 //!> operation that handles submitting job's result
101 SubmitResultOperation submitOp;
102
103 //!> internally bound function such that host and service don't have to be stored, submits result
104 boost::function<void ()> submitresult;
105
106 //!> operation that handles removal from pool
107 RemoveFromPoolOperation removeOp;
108
109 //!> internally bound function such that host and service don't have to be stored, removes us from server
110 boost::function<void ()> removeme;
111};
112
113#endif /* POOLWORKER_HPP_ */
Note: See TracBrowser for help on using the repository browser.