Ignore:
Timestamp:
May 17, 2012, 3:21:12 PM (14 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, Candidate_v1.7.0, Candidate_v1.7.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:
1dc209
Parents:
fb2324
git-author:
Frederik Heber <heber@…> (12/10/11 15:17:06)
git-committer:
Frederik Heber <heber@…> (05/17/12 15:21:12)
Message:

Factored out Operation and derived all operations from it.

  • a number of subclass of FragmentController that encapsulate each operation.
  • Operation contains getEndpointIterator(), handle_FinishOperation() and disconnect().
  • Operation now also contains Exitflag that was formerly in FragmentController.
  • new derived Operations: ReceiveJobsOperation(), CheckResultsOperation(), SendResultsOperation(), ShutdownOperation() that each contain the connect_..., handle_... functions.
  • functions to initiate operation have been placed into these Operation- derived classes as implemented virtual operator().
  • most of the required member variables have also been associated with the class that needs them. Getters and Setters have been relayed for the moment.
  • each Operation as of now needs ref to connection, host and service. This should be changed and the stuff around getEndpointIterator() refactored along with it.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Fragmentation/Automation/FragmentController.cpp

    rfb2324 r5adb84  
    5050    host(_host),
    5151    service(_service),
    52     Exitflag(OkFlag)
     52    recjobs(connection_, _host, _service),
     53    checkres(connection_, _host, _service),
     54    sendres(connection_, _host, _service),
     55    shutdown(connection_, _host, _service)
    5356{
    5457  Info info(__FUNCTION__);
     
    6164{}
    6265
    63 /** Handle completion of a connect operation.
     66/** Constructor for class Operation.
     67 *
     68 * \param _connection connection to operate on
     69 */
     70FragmentController::Operation::Operation(Connection &_connection, const std::string& _host, const std::string& _service) :
     71    connection_(_connection),
     72    host(_host),
     73    service(_service),
     74    Exitflag(OkFlag)
     75{}
     76
     77/** Destructor for class Operation.
     78 *
     79 */
     80FragmentController::Operation::~Operation()
     81{}
     82
     83/** Handle connect operation to receive jobs from controller
    6484 *
    6585 * \param e error code if something went wrong
    6686 * \param endpoint_iterator endpoint of the connection
    6787 */
    68 void FragmentController::handle_connect_calc(const boost::system::error_code& e,
     88void FragmentController::ReceiveJobsOperation::handle_connect_calc(const boost::system::error_code& e,
    6989    boost::asio::ip::tcp::resolver::iterator endpoint_iterator)
    7090{
     
    7595    enum ControllerChoices choice = ReceiveJobs;
    7696    connection_.async_write(choice,
    77       boost::bind(&FragmentController::handle_SendJobs, this,
     97      boost::bind(&FragmentController::ReceiveJobsOperation::handle_SendJobs, this,
    7898      boost::asio::placeholders::error));
    7999  } else if (endpoint_iterator != boost::asio::ip::tcp::resolver::iterator()) {
     
    82102    boost::asio::ip::tcp::endpoint endpoint = *endpoint_iterator;
    83103    connection_.socket().async_connect(endpoint,
    84       boost::bind(&FragmentController::handle_connect_calc, this,
     104      boost::bind(&FragmentController::ReceiveJobsOperation::handle_connect_calc, this,
    85105      boost::asio::placeholders::error, ++endpoint_iterator));
    86106  } else {
     
    93113}
    94114
    95 /** Handle completion of a connect operation.
     115/** Callback function when an operation has been completed.
     116 *
     117 * \param e error code if something went wrong
     118 */
     119void FragmentController::ReceiveJobsOperation::handle_FinishOperation(const boost::system::error_code& e)
     120{
     121  Info info(__FUNCTION__);
     122
     123  LOG(1, "INFO: Jobs have been sent. Clearing.");
     124  jobs.clear();
     125
     126  Operation::handle_FinishOperation(e);
     127}
     128
     129
     130/** Handle connect operation to send number of done jobs.
    96131 *
    97132 * \param e error code if something went wrong
    98133 * \param endpoint_iterator endpoint of the connection
    99134 */
    100 void FragmentController::handle_connect_check(const boost::system::error_code& e,
     135void FragmentController::CheckResultsOperation::handle_connect_check(const boost::system::error_code& e,
    101136    boost::asio::ip::tcp::resolver::iterator endpoint_iterator)
    102137{
     
    107142    enum ControllerChoices choice = CheckState;
    108143    connection_.async_write(choice,
    109       boost::bind(&FragmentController::handle_ReceiveDoneJobs, this,
     144      boost::bind(&FragmentController::CheckResultsOperation::handle_ReceiveDoneJobs, this,
    110145      boost::asio::placeholders::error));
    111146  } else if (endpoint_iterator != boost::asio::ip::tcp::resolver::iterator()) {
     
    114149    boost::asio::ip::tcp::endpoint endpoint = *endpoint_iterator;
    115150    connection_.socket().async_connect(endpoint,
    116       boost::bind(&FragmentController::handle_connect_check, this,
     151      boost::bind(&FragmentController::CheckResultsOperation::handle_connect_check, this,
    117152      boost::asio::placeholders::error, ++endpoint_iterator));
    118153  } else {
     
    125160}
    126161
    127 /** Handle completion of a connect operation.
     162/** Handle connect operation to send results.
    128163 *
    129164 * \param e error code if something went wrong
    130165 * \param endpoint_iterator endpoint of the connection
    131166 */
    132 void FragmentController::handle_connect_get(const boost::system::error_code& e,
     167void FragmentController::SendResultsOperation::handle_connect_get(const boost::system::error_code& e,
    133168    boost::asio::ip::tcp::resolver::iterator endpoint_iterator)
    134169{
     
    139174    enum ControllerChoices choice = SendResults;
    140175    connection_.async_write(choice,
    141       boost::bind(&FragmentController::handle_ReceivingResults, this,
     176      boost::bind(&FragmentController::SendResultsOperation::handle_ReceivingResults, this,
    142177      boost::asio::placeholders::error));
    143178  } else if (endpoint_iterator != boost::asio::ip::tcp::resolver::iterator()) {
     
    146181    boost::asio::ip::tcp::endpoint endpoint = *endpoint_iterator;
    147182    connection_.socket().async_connect(endpoint,
    148       boost::bind(&FragmentController::handle_connect_check, this,
     183      boost::bind(&FragmentController::SendResultsOperation::handle_connect_get, this,
    149184      boost::asio::placeholders::error, ++endpoint_iterator));
    150185  } else {
     
    157192}
    158193
    159 /** Handle completion of a connect operation.
     194/** Handle connect operation to shutdown scheduler.
    160195 *
    161196 * \param e error code if something went wrong
    162197 * \param endpoint_iterator endpoint of the connection
    163198 */
    164 void FragmentController::handle_connect_shutdown(const boost::system::error_code& e,
     199void FragmentController::ShutdownOperation::handle_connect_shutdown(const boost::system::error_code& e,
    165200    boost::asio::ip::tcp::resolver::iterator endpoint_iterator)
    166201{
     
    171206    enum ControllerChoices choice = Shutdown;
    172207    connection_.async_write(choice,
    173       boost::bind(&FragmentController::handle_FinishOperation, this,
     208      boost::bind(&FragmentController::ShutdownOperation::handle_FinishOperation, this,
    174209      boost::asio::placeholders::error));
    175210  } else if (endpoint_iterator != boost::asio::ip::tcp::resolver::iterator()) {
     
    178213    boost::asio::ip::tcp::endpoint endpoint = *endpoint_iterator;
    179214    connection_.socket().async_connect(endpoint,
    180       boost::bind(&FragmentController::handle_connect_calc, this,
     215      boost::bind(&FragmentController::ShutdownOperation::handle_connect_shutdown, this,
    181216      boost::asio::placeholders::error, ++endpoint_iterator));
    182217  } else {
     
    189224}
    190225
    191 /** Callback function when operation has been completed.
    192  *
    193  * \param e error code if something went wrong
    194  */
    195 void FragmentController::handle_FinishOperation(const boost::system::error_code& e)
     226/** Callback function when an operation has been completed.
     227 *
     228 * \param e error code if something went wrong
     229 */
     230void FragmentController::Operation::handle_FinishOperation(const boost::system::error_code& e)
    196231{
    197232  Info info(__FUNCTION__);
     
    215250 * \param e error code if something went wrong
    216251 */
    217 void FragmentController::handle_SendJobs(const boost::system::error_code& e)
     252void FragmentController::ReceiveJobsOperation::handle_SendJobs(const boost::system::error_code& e)
    218253{
    219254  Info info(__FUNCTION__);
     
    225260    LOG(1, "INFO: Sending "+toString(jobs.size())+" jobs ...");
    226261    connection_.async_write(jobs,
    227       boost::bind(&FragmentController::handle_FinishOperation, this,
     262      boost::bind(&FragmentController::ReceiveJobsOperation::handle_FinishOperation, this,
    228263      boost::asio::placeholders::error));
    229264  }
     
    243278 * \param e error code if something went wrong
    244279 */
    245 void FragmentController::handle_ReceivingResults(const boost::system::error_code& e)
     280void FragmentController::SendResultsOperation::handle_ReceivingResults(const boost::system::error_code& e)
    246281{
    247282  Info info(__FUNCTION__);
     
    251286    // decode the data that is written to the underlying socket.
    252287    connection_.async_read(results,
    253       boost::bind(&FragmentController::handle_ReceivedResults, this,
     288      boost::bind(&FragmentController::SendResultsOperation::handle_ReceivedResults, this,
    254289      boost::asio::placeholders::error));
    255290  }
     
    269304 * \param e error code if something went wrong
    270305 */
    271 void FragmentController::handle_ReceivedResults(const boost::system::error_code& e)
     306void FragmentController::SendResultsOperation::handle_ReceivedResults(const boost::system::error_code& e)
    272307{
    273308  Info info(__FUNCTION__);
     
    282317 * \param e error code if something went wrong
    283318 */
    284 void FragmentController::handle_ReceiveDoneJobs(const boost::system::error_code& e)
     319void FragmentController::CheckResultsOperation::handle_ReceiveDoneJobs(const boost::system::error_code& e)
    285320{
    286321  Info info(__FUNCTION__);
     
    291326    LOG(1, "INFO: Checking number of done jobs ...");
    292327    connection_.async_read(doneJobs,
    293       boost::bind(&FragmentController::handle_FinishOperation, this,
     328      boost::bind(&FragmentController::Operation::handle_FinishOperation, this,
    294329      boost::asio::placeholders::error));
    295330  }
     
    306341 * \return endpoint iterator of connection
    307342 */
    308 boost::asio::ip::tcp::resolver::iterator FragmentController::getEndpointIterator()
     343boost::asio::ip::tcp::resolver::iterator FragmentController::Operation::getEndpointIterator()
    309344{
    310345  // Resolve the host name into an IP address.
     
    321356 * We require internal connetion_ and host and service to be set up for this.
    322357 */
    323 void FragmentController::connect_calc()
     358void FragmentController::ReceiveJobsOperation::connect_calc()
    324359{
    325360  Info info(__FUNCTION__);
     
    331366  std::cout << "Connecting to endpoint " << endpoint << " to calc " << std::endl;
    332367  connection_.socket().async_connect(endpoint,
    333     boost::bind(&FragmentController::handle_connect_calc, this,
     368    boost::bind(&FragmentController::ReceiveJobsOperation::handle_connect_calc, this,
    334369      boost::asio::placeholders::error, ++endpoint_iterator));
    335370}
     
    339374 * We require internal connetion_ and host and service to be set up for this.
    340375 */
    341 void FragmentController::connect_check()
     376void FragmentController::CheckResultsOperation::connect_check()
    342377{
    343378  Info info(__FUNCTION__);
     
    349384  std::cout << "Connecting to endpoint " << endpoint << " to check " << std::endl;
    350385  connection_.socket().async_connect(endpoint,
    351     boost::bind(&FragmentController::handle_connect_check, this,
     386    boost::bind(&FragmentController::CheckResultsOperation::handle_connect_check, this,
    352387      boost::asio::placeholders::error, ++endpoint_iterator));
    353388}
     
    357392 * We require internal connetion_ and host and service to be set up for this.
    358393 */
    359 void FragmentController::connect_get()
     394void FragmentController::SendResultsOperation::connect_get()
    360395{
    361396  Info info(__FUNCTION__);
     
    367402  std::cout << "Connecting to endpoint " << endpoint << " to get results " << std::endl;
    368403  connection_.socket().async_connect(endpoint,
    369     boost::bind(&FragmentController::handle_connect_get, this,
     404    boost::bind(&FragmentController::SendResultsOperation::handle_connect_get, this,
    370405      boost::asio::placeholders::error, ++endpoint_iterator));
    371406}
     
    375410 * We require internal connetion_ and host and service to be set up for this.
    376411 */
    377 void FragmentController::connect_shutdown()
     412void FragmentController::ShutdownOperation::connect_shutdown()
    378413{
    379414  Info info(__FUNCTION__);
     
    385420  std::cout << "Connecting to endpoint " << endpoint << " to get results " << std::endl;
    386421  connection_.socket().async_connect(endpoint,
    387     boost::bind(&FragmentController::handle_connect_shutdown, this,
     422    boost::bind(&FragmentController::ShutdownOperation::handle_connect_shutdown, this,
    388423      boost::asio::placeholders::error, ++endpoint_iterator));
    389424}
     
    392427 *
    393428 */
    394 void FragmentController::disconnect()
     429void FragmentController::Operation::disconnect()
    395430{
    396431  //connection_.socket().close();
     
    401436 * \param _jobs jobs to add
    402437 */
    403 void FragmentController::addJobs(const std::vector<FragmentJob> &_jobs)
     438void FragmentController::ReceiveJobsOperation::addJobs(const std::vector<FragmentJob> &_jobs)
    404439{
    405440  jobs.reserve(jobs.size()+_jobs.size());
     
    411446/** Prepares the calculation of the results for the current jobs.
    412447 */
    413 void FragmentController::calculateResults()
     448void FragmentController::ReceiveJobsOperation::operator()()
    414449{
    415450  Info info(__FUNCTION__);
     
    422457/** Prepares the calculation of the results for the current jobs.
    423458 */
    424 void FragmentController::checkResults()
     459void FragmentController::CheckResultsOperation::operator()()
    425460{
    426461  Info info(__FUNCTION__);
     
    433468/** Getter for results.
    434469 *
    435  * \sa calculateResults()
    436470 * \return vector of results for the added jobs (\sa addJobs()).
    437471 */
    438 std::vector<FragmentResult> FragmentController::getResults()
     472std::vector<FragmentResult> FragmentController::SendResultsOperation::getResults()
    439473{
    440474  Info info(__FUNCTION__);
     
    445479 *
    446480 */
    447 void FragmentController::obtainResults()
     481void FragmentController::SendResultsOperation::operator()()
    448482{
    449483  // connect
     
    456490 *
    457491 */
    458 void FragmentController::shutdown()
     492void FragmentController::ShutdownOperation::operator()()
    459493{
    460494  // connect
     
    469503 * \param doneJobs
    470504 */
    471 size_t FragmentController::getDoneJobs() const
     505size_t FragmentController::CheckResultsOperation::getDoneJobs() const
    472506{
    473507  return doneJobs;
     
    478512 * \return jobs.size()
    479513 */
    480 size_t FragmentController::getPresentJobs() const
     514size_t FragmentController::ReceiveJobsOperation::getPresentJobs() const
    481515{
    482516  return jobs.size();
Note: See TracChangeset for help on using the changeset viewer.