/* * SpecificFragmentController_ReceiveResultContainer_impl.hpp * * Created on: Aug 27, 2012 * Author: heber */ #ifndef SPECIFICFRAGMENTCONTROLLER_RECEIVERESULTCONTAINER_IMPL_HPP_ #define SPECIFICFRAGMENTCONTROLLER_RECEIVERESULTCONTAINER_IMPL_HPP_ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include "SpecificFragmentController.hpp" #include "CodePatterns/Assert.hpp" #include "CodePatterns/toString.hpp" template size_t SpecificFragmentController::ReceiveResultContainer::receiveResults( SpecificFragmentController &callback) { // receive (and remove the respective ids) callback.receiveResults(callback.host, callback.port); callback.RunService("Requesting results"); std::vector fragmentresults = callback.getReceivedResults(); // convert std::vector fragmentData; SpecificFragmentController::ReceiveResultContainer::ConvertFragmentResultTo( fragmentresults, fragmentData); // insert into map SpecificFragmentController::ReceiveResultContainer::insertResults( fragmentresults, fragmentData); return fragmentData.size(); } template void SpecificFragmentController::ReceiveResultContainer::waitforResults( const size_t NoExpectedResults, boost::asio::io_service &io_service, SpecificFragmentController &callback) { // wait but receive all results that are already done size_t NoReceivedResults = 0; while ((NoReceivedResults != NoExpectedResults) && (callback.getExitflag() == 0)) { // wait a bit boost::asio::deadline_timer timer(io_service); timer.expires_from_now(boost::posix_time::milliseconds(500)); timer.wait(); // then request status callback.checkResults(callback.host, callback.port); callback.RunService("Checking on results"); if (callback.getExitflag() != 0) break; const std::pair JobStatus = callback.getJobStatus(); const size_t NoCalculatedResults = JobStatus.second; // if some are done, get them if (NoCalculatedResults != 0) { NoReceivedResults += receiveResults(callback); callback.handler(NoReceivedResults, NoExpectedResults); LOG(1, "INFO: #" << JobStatus.first << " are waiting in the queue and #" << NoReceivedResults << " of " << NoExpectedResults << " jobs are calculated so far."); } } } #endif /* SPECIFICFRAGMENTCONTROLLER_RECEIVERESULTCONTAINER_IMPL_HPP_ */