Changeset aec098


Ignore:
Timestamp:
Jun 29, 2012, 1:23:20 PM (13 years ago)
Author:
Frederik Heber <heber@…>
Branches:
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
Children:
e8f397
Parents:
9a3f84
git-author:
Frederik Heber <heber@…> (03/04/12 16:12:28)
git-committer:
Frederik Heber <heber@…> (06/29/12 13:23:20)
Message:

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.
Location:
src/Fragmentation/Automation
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/Fragmentation/Automation/Pool/PoolWorker.cpp

    r9a3f84 raec098  
    5252 * We automatically connect to the given pool and enroll.
    5353 *
    54  * @param io_service io service for creating connections
     54 * @param _io_service io service for creating connections
    5555 * @param _host host part of address of pool to connect to
    5656 * @param _service service part of address of pool to connect to
     
    5959 */
    6060PoolWorker::PoolWorker(
    61     boost::asio::io_service& io_service,
     61    boost::asio::io_service& _io_service,
    6262    const std::string& _host,
    6363    const std::string& _service,
    6464    const std::string& listenhost,
    6565    const std::string& listenservice) :
    66   connection_(io_service),
    67   PoolListener(io_service, boost::lexical_cast<unsigned short>(listenservice), *this),
     66  io_service(_io_service),
     67  PoolListener(_io_service, boost::lexical_cast<unsigned short>(listenservice), *this),
    6868  address(listenhost, listenservice),
     69  connection_(_io_service),
    6970  enrollOp(connection_, address),
    7071  submitOp(connection_, address),
    7172  submitresult(boost::bind(&AsyncOperation::operator(),
    7273      boost::ref(submitOp),
     74      _host, _service)),
     75  removeOp(connection_, address),
     76  removeme(boost::bind(&Operation::operator(),
     77      boost::ref(removeOp),
    7378      _host, _service))
    7479{
     
    138143  submitresult();
    139144}
     145
     146/** Helper function to shutdown the worker properly.
     147 *
     148 * Note that we will use ShutdownWorkerOperation to unlist from server's pool.
     149 *
     150 */
     151void PoolWorker::shutdown(int sig)
     152{
     153  LOG(1, "INFO: Shutting down due to signal "+toString(sig)+".");
     154
     155  // remove us from pool
     156  removeme();
     157
     158  // somehow stop listener
     159  PoolListener.closeSocket();
     160
     161  // finally, stop io_service
     162  io_service.stop();
     163}
  • src/Fragmentation/Automation/Pool/PoolWorker.hpp

    r9a3f84 raec098  
    2323#include "Jobs/FragmentJob.hpp"
    2424#include "Controller/Commands/EnrollInPoolOperation.hpp"
     25#include "Controller/Commands/RemoveFromPoolOperation.hpp"
    2526#include "Controller/Commands/SubmitResultOperation.hpp"
    2627#include "Listener.hpp"
     
    5051
    5152  void WorkOnJob(FragmentJob::ptr &job);
     53  void removeFromPool();
     54  void shutdown(int sig);
    5255
    5356  class PoolListener_t : public Listener
     
    7982
    8083private:
    81   //!> The Connection to the server.
    82   Connection connection_;
     84  //!> reference to io_service which we use for connections
     85  boost::asio::io_service& io_service;
    8386
    8487  //!> The listener for the WorkerPool
     
    8790  //!> address of this worker
    8891  const WorkerAddress address;
     92
     93  //!> The Connection to the server for the stored operations
     94  Connection connection_;
    8995
    9096  //!> operation that handles obtaining a job
     
    96102  //!> internally bound function such that host and service don't have to be stored, submits result
    97103  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;
    98110};
    99111
  • src/Fragmentation/Automation/poolworker.cpp

    r9a3f84 raec098  
    2929#include <iostream>
    3030#include <boost/lexical_cast.hpp>
     31#include <signal.h>
    3132
    3233#include "atexit.hpp"
     
    3536#include "Pool/PoolWorker.hpp"
    3637
     38boost::function<void (int)> shutdownfunction;
     39
     40void signalhandler(int sig)
     41{
     42  if (shutdownfunction)
     43    shutdownfunction(sig);
     44  signal(SIGINT, NULL);
     45}
    3746
    3847int main(int argc, char* argv[])
     
    5665    boost::asio::io_service io_service;
    5766    PoolWorker client(io_service, argv[1], argv[2], argv[3], argv[4]);
     67
     68    // catch ctrl-c and shutdown worker properly
     69    shutdownfunction = boost::bind(&PoolWorker::shutdown, boost::ref(client), _1);
     70//    signal(SIGABRT, &signalhandler);
     71//    signal(SIGTERM, &signalhandler);
     72    signal(SIGINT, &signalhandler);
     73
     74    // process io requests
    5875    {
    5976      Info info("io_service");
Note: See TracChangeset for help on using the changeset viewer.