<commit_before>#include "broker.h"

#include <thread>
#include <functional>
#include <stdexcept>


using namespace GeoPoll;


Broker::Broker() 
    :   logger(Poco::Logger::get("Broker")),
        zmq_cx(0)
{
    poco_debug(logger, "Setting up the broker");
    
    zmq_cx = new zmq::context_t(1);
    if (zmq_cx == nullptr) {
        throw std::runtime_error("Could not intialize 0mq context");
    }
}


Broker::~Broker()
{
    stop();

    if (zmq_cx != nullptr) {
        delete zmq_cx;
    }
}


void
Broker::addListener(std::shared_ptr<Batyr::BaseListener> listener_ptr)
{
    listeners.push_back(listener_ptr);
}


void
Broker::run()
{
    // start all listeners
    for(auto ilistener = listeners.begin(); ilistener != listeners.end() ; ++ilistener) {
        // http://stackoverflow.com/questions/10673585/start-thread-with-member-function
        std::thread lThread( std::bind(&Batyr::BaseListener::run, (*ilistener)) );
        lThread.detach();
    }
}


void
Broker::stop()
{
    // stopping all listeners
    /*
    for(auto ilistener = listeners.begin(); ilistener != listeners.end() ; ++ilistener) {
        (*ilistener)->stop();
    }
    */
}<commit_msg>properly shutdown listeners<commit_after>#include "broker.h"

#include <thread>
#include <functional>
#include <stdexcept>


using namespace GeoPoll;


Broker::Broker() 
    :   logger(Poco::Logger::get("Broker")),
        zmq_cx(0)
{
    poco_debug(logger, "Setting up the broker");
    
    zmq_cx = new zmq::context_t(1);
    if (zmq_cx == nullptr) {
        throw std::runtime_error("Could not intialize 0mq context");
    }
}


Broker::~Broker()
{
    stop();

    if (zmq_cx != nullptr) {
        delete zmq_cx;
    }
}


void
Broker::addListener(std::shared_ptr<Batyr::BaseListener> listener_ptr)
{
    listeners.push_back(listener_ptr);
}


void
Broker::run()
{
    // start all listeners
    for(auto ilistener = listeners.begin(); ilistener != listeners.end() ; ++ilistener) {
        // http://stackoverflow.com/questions/10673585/start-thread-with-member-function
        std::thread lThread( std::bind(&Batyr::BaseListener::run, (*ilistener)) );
        lThread.detach();
    }
}


void
Broker::stop()
{
    // stopping all listeners
    for(auto ilistener = listeners.begin(); ilistener != listeners.end() ; ++ilistener) {
        (*ilistener)->stop();
    }
}
{'fraction_non_alphanumeric': 0.16183986371379896, 'fraction_numerical': 0.009369676320272573, 'mean_word_length': 3.3259668508287294, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3061259', 'n_tokens_mistral': 844, 'n_tokens_neox': 810, 'n_words': 144}