<commit_before>#include <simgrid/s4u.hpp>
#include <xbt/string.hpp>
#include <iostream>
#include <stdexcept>
#include <boost/shared_ptr.hpp>
#include <thrift/processor/TMultiplexedProcessor.h>

#include <simgrid/msg.h>

#include "../services.hpp"
#include "../../common.hpp"

using namespace ::apache::thrift;
using namespace ::apache::thrift::protocol;
using namespace ::apache::thrift::transport;
using namespace ::apache::thrift::server;

using namespace  ::RsgService;

using namespace  ::simgrid;

#define UNUSED(x) (void)(x)

std::unordered_map<int, simgrid::s4u::ActorPtr> rsg::RsgActorHandler::pActors;
unsigned long long rsg::RsgActorHandler::pActorMapId = 0;

rsg::RsgActorHandler::RsgActorHandler()
    : server_exit(false)
{
}

void rsg::RsgActorHandler::close() {
    server_exit = true;
}

void  rsg::RsgActorHandler::sleep(const double duration) {
    s4u::this_actor::sleep_for(duration);
}

void rsg::RsgActorHandler::execute(const double flops) {
    s4u::this_actor::execute(flops);
}

void rsg::RsgActorHandler::send(const int64_t mbAddr, const std::string& content, const int64_t simulatedSize) {
    s4u::MailboxPtr mbox = rsg::RsgMailboxHandler::pMailboxes.at(mbAddr);
    std::string *internalPtr = new std::string(content.data(), content.length());
    s4u::this_actor::send(mbox, (void*) internalPtr, simulatedSize);
}

void rsg::RsgActorHandler::recv(std::string& _return, const int64_t mbAddr) {
    s4u::MailboxPtr mbox = rsg::RsgMailboxHandler::pMailboxes.at(mbAddr);
    std::string *content = (std::string*) s4u::this_actor::recv(mbox);  
    _return.assign(content->data(), content->length());
    delete content;
}

void rsg::RsgActorHandler::getName(std::string& _return, const int64_t addr) {
    try {
        simgrid::s4u::ActorPtr actor = pActors.at(addr);
        simgrid::xbt::string c_name = actor->getName();
        _return.assign(c_name);
    } catch(std::out_of_range& e) {
        std::cerr << "rsg::RsgActorHandler::getName no actors for this addr" << std::endl; 
    }
}


void rsg::RsgActorHandler::getHost(rsgHostCurrentResType& _return, const int64_t addr) {
    try {
        simgrid::s4u::ActorPtr actor = pActors.at(addr);
        s4u::Host *host = actor->getHost();
        _return.name = host->getName();
        _return.addr = (unsigned long int) host;
    } catch(std::out_of_range& e) {
        std::cerr << "rsg::RsgActorHandler::getHost no actors for this addr" << std::endl; 
    }
}


int32_t rsg::RsgActorHandler::getPid(const int64_t addr) {
    try {
        simgrid::s4u::ActorPtr actor = pActors.at(addr);
        return actor->getPid();
    } catch(std::out_of_range& e) {
        std::cerr << "rsg::RsgActorHandler::getPid no actors for this addr" << std::endl; 
    }
    return 0;
}


void rsg::RsgActorHandler::setAutoRestart(const int64_t addr, const bool autorestart) {
    try {
        simgrid::s4u::ActorPtr actor = pActors.at(addr);
        actor->setAutoRestart(autorestart);
    } catch(std::out_of_range& e) {
        std::cerr << "rsg::RsgActorHandler::setAutoRestart no actors for this addr" << std::endl; 
    }
}


void rsg::RsgActorHandler::setKillTime(const int64_t addr, const double time) {
    try {
        simgrid::s4u::ActorPtr actor = pActors.at(addr);
        actor->setKillTime(time);
    } catch(std::out_of_range& e) {
        std::cerr << "rsg::RsgActorHandler::setKillTime no actors for this addr" << std::endl; 
    }
}


double rsg::RsgActorHandler::getKillTime(const int64_t addr) {
    try {
        simgrid::s4u::ActorPtr actor = pActors.at(addr);
        return actor->getKillTime();
    } catch(std::out_of_range& e) {
        std::cerr << "rsg::RsgActorHandler::getKillTime no actors for this addr" << std::endl;
    }
    return -1;
}

void rsg::RsgActorHandler::killAll() {
    s4u::Actor::killAll();
}

void rsg::RsgActorHandler::kill(const int64_t mbAddr) {
    try {
        simgrid::s4u::ActorPtr actor = pActors.at(mbAddr);
        actor->kill();
    } catch(std::out_of_range& e) {
        std::cerr << "rsg::RsgActorHandler::kill no actors for this addr" << std::endl;
    }
}

int32_t rsg::RsgActorHandler::killPid(const int32_t pid) {
    try {
        /*@Adrien: why this ?
        int positiv_pid = pid;
        if(pid < -1)
            positiv_pid = pid*-1;*/
        
        simgrid::s4u::Actor::kill(pid);
        return 0;
    } catch(std::out_of_range& e) {
        return 1;
    } catch(std::exception &e) {
        return 1;
    }
}

void rsg::RsgActorHandler::join(const int64_t addr) {
    try {
        simgrid::s4u::ActorPtr actor = pActors.at(addr);
        actor->join();
    } catch(std::out_of_range& e) {
        std::cerr << "rsg::RsgActorHandler::join no actors for this addr" << std::endl;
    }
}

void rsg::RsgActorHandler::createActorPrepare(std::string& _return) {
    TZmqServer::get_new_endpoint(_return);
    lastChildServer = new RsgThriftServer(_return);
}

int64_t rsg::RsgActorHandler::selfAddr() {
    simgrid::s4u::ActorPtr actor = s4u::Actor::self();
    unsigned long long newId = pActorMapId++;
    pActors.insert({newId, actor});
    return newId;
}

int deleteServerWhenActorIsKilled(void *arg, void *arg2) {
    UNUSED(arg);
    debug_server_print("deleteServerWhenActorIsKilled begin");<commit_msg>[code] logging++<commit_after>#include <simgrid/s4u.hpp>
#include <xbt/string.hpp>
#include <iostream>
#include <stdexcept>
#include <boost/shared_ptr.hpp>
#include <thrift/processor/TMultiplexedProcessor.h>

#include <simgrid/msg.h>

#include "../services.hpp"
#include "../../common.hpp"

using namespace ::apache::thrift;
using namespace ::apache::thrift::protocol;
using namespace ::apache::thrift::transport;
using namespace ::apache::thrift::server;

using namespace  ::RsgService;

using namespace  ::simgrid;

#define UNUSED(x) (void)(x)

std::unordered_map<int, simgrid::s4u::ActorPtr> rsg::RsgActorHandler::pActors;
unsigned long long rsg::RsgActorHandler::pActorMapId = 0;

rsg::RsgActorHandler::RsgActorHandler()
    : server_exit(false)
{
}

void rsg::RsgActorHandler::close() {
    server_exit = true;
}

void  rsg::RsgActorHandler::sleep(const double duration) {
    s4u::this_actor::sleep_for(duration);
}

void rsg::RsgActorHandler::execute(const double flops) {
    s4u::this_actor::execute(flops);
}

void rsg::RsgActorHandler::send(const int64_t mbAddr, const std::string& content, const int64_t simulatedSize) {
    s4u::MailboxPtr mbox = rsg::RsgMailboxHandler::pMailboxes.at(mbAddr);
    std::string *internalPtr = new std::string(content.data(), content.length());
    s4u::this_actor::send(mbox, (void*) internalPtr, simulatedSize);
}

void rsg::RsgActorHandler::recv(std::string& _return, const int64_t mbAddr) {
    s4u::MailboxPtr mbox = rsg::RsgMailboxHandler::pMailboxes.at(mbAddr);
    std::string *content = (std::string*) s4u::this_actor::recv(mbox);  
    _return.assign(content->data(), content->length());
    delete content;
}

void rsg::RsgActorHandler::getName(std::string& _return, const int64_t addr) {
    try {
        simgrid::s4u::ActorPtr actor = pActors.at(addr);
        simgrid::xbt::string c_name = actor->getName();
        _return.assign(c_name);
    } catch(std::out_of_range& e) {
        std::cerr << "rsg::RsgActorHandler::getName no actors for this addr" << std::endl; 
    }
}


void rsg::RsgActorHandler::getHost(rsgHostCurrentResType& _return, const int64_t addr) {
    try {
        simgrid::s4u::ActorPtr actor = pActors.at(addr);
        s4u::Host *host = actor->getHost();
        _return.name = host->getName();
        _return.addr = (unsigned long int) host;
    } catch(std::out_of_range& e) {
        std::cerr << "rsg::RsgActorHandler::getHost no actors for this addr" << std::endl; 
    }
}


int32_t rsg::RsgActorHandler::getPid(const int64_t addr) {
    try {
        simgrid::s4u::ActorPtr actor = pActors.at(addr);
        return actor->getPid();
    } catch(std::out_of_range& e) {
        std::cerr << "rsg::RsgActorHandler::getPid no actors for this addr" << std::endl; 
    }
    return 0;
}


void rsg::RsgActorHandler::setAutoRestart(const int64_t addr, const bool autorestart) {
    try {
        simgrid::s4u::ActorPtr actor = pActors.at(addr);
        actor->setAutoRestart(autorestart);
    } catch(std::out_of_range& e) {
        std::cerr << "rsg::RsgActorHandler::setAutoRestart no actors for this addr" << std::endl; 
    }
}


void rsg::RsgActorHandler::setKillTime(const int64_t addr, const double time) {
    try {
        simgrid::s4u::ActorPtr actor = pActors.at(addr);
        actor->setKillTime(time);
    } catch(std::out_of_range& e) {
        std::cerr << "rsg::RsgActorHandler::setKillTime no actors for this addr" << std::endl; 
    }
}


double rsg::RsgActorHandler::getKillTime(const int64_t addr) {
    try {
        simgrid::s4u::ActorPtr actor = pActors.at(addr);
        return actor->getKillTime();
    } catch(std::out_of_range& e) {
        std::cerr << "rsg::RsgActorHandler::getKillTime no actors for this addr" << std::endl;
    }
    return -1;
}

void rsg::RsgActorHandler::killAll() {
    s4u::Actor::killAll();
}

void rsg::RsgActorHandler::kill(const int64_t mbAddr) {
    try {
        simgrid::s4u::ActorPtr actor = pActors.at(mbAddr);
        actor->kill();
    } catch(std::out_of_range& e) {
        std::cerr << "rsg::RsgActorHandler::kill no actors for this addr" << std::endl;
    }
}

int32_t rsg::RsgActorHandler::killPid(const int32_t pid) {
    try {
        /*@Adrien: why this ?
        int positiv_pid = pid;
        if(pid < -1)
            positiv_pid = pid*-1;*/
        
        simgrid::s4u::Actor::kill(pid);
        return 0;
    } catch(std::out_of_range& e) {
        return 1;
    } catch(std::exception &e) {
        return 1;
    }
}

void rsg::RsgActorHandler::join(const int64_t addr) {
    try {
        simgrid::s4u::ActorPtr actor = pActors.at(addr);
        actor->join();
    } catch(std::out_of_range& e) {
        std::cerr << "rsg::RsgActorHandler::join no actors for this addr" << std::endl;
    }
}

void rsg::RsgActorHandler::createActorPrepare(std::string& _return) {
    TZmqServer::get_new_endpoint(_return);
    debug_server_print("Allocating a new RsgThriftServer instance");
    lastChildServer = new RsgThriftServer(_return);
}

int64_t rsg::RsgActorHandler::selfAddr() {
    simgrid::s4u::ActorPtr actor = s4u::Actor::self();
    unsigned long long newId = pActorMapId++;
    pActors.insert({newId, actor});
    return newId;
}

int deleteServerWhenActorIsKilled(void *arg, void *arg2) {
    UNUSED(arg);
    debug_server_print("deleteServerWhenActorIsKilled begin");
{'fraction_non_alphanumeric': 0.15282235227487256, 'fraction_numerical': 0.011327166320558807, 'mean_word_length': 4.042836744407425, 'pattern_counts': {'":': 0, '<': 85, '<?xml version=': 0, '>': 41, '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': '2956369', 'n_tokens_mistral': 3816, 'n_tokens_neox': 3742, 'n_words': 685}