<commit_before># include "broker.hpp"
# include "broker-util.hpp"
# include "synchronization.hpp"
# include "cache.hpp"
# include "conf.hpp"
# include "broker2broker.hpp"
# include "transaction-maps.hpp"

# include <chrono>

TransactionMap transaction_cache;

/*
 * LOCKING POLICY
 *
 * For reading operations, the mutex of that map has to be obtained shared, e.g. using a shared_lock object.
 * For writing operations, the lock has to be exclusive and therefore unique_lock has to be used.
 *
 * R/W-references may be taken from the maps and written to without existing lock because there are
 * currently no signs that one transaction object may be used by two threads concurrently (if the other servers
 * are implementing the protocol correctly). The only situtation in which a catastrophe (unrestricted concurrent access
 * to data) could happen is if, for example, Persistence sends two messages with the same sequence number in a very short interval.
 * I that case, two threads might access the same map key; however, it is very unlikely that this will happen.
 *
 */

/*
 * CACHING
 *
 * A user's information is cached whenever there has been a ULKUP which was not triggered by UONLQ (in that case, no information is saved),
 * and LOGIN/LOGOUT operations update that information.
 */

/**
 * @brief Receive and process incoming messages.
 *
 * This function receives incoming messages and gives them to the appropriate handlers for each protocol event. It's
 * just a single infinite loop.
 *
 */
void ProtocolDispatcher::dispatch(void)
{
    vector<Receivable*> received_messages;
    unsigned int received_size = 0;

    received_messages.resize(3);
    std::chrono::time_point<std::chrono::steady_clock> start, end;

    while ( true )
    {
	// received_messages is an output argument!
	received_size = communicator.receiveMessages(received_messages);

	for ( unsigned int i = 0; i < received_size; i++ )
	{
	    start = std::chrono::steady_clock::now();
	    switch ( received_messages[i]->sender )
	    {
		// shared_ptr -- because the delivered message is dynamically allocated.
		case MessageOrigin::fromPersistence:
		    handlePersistenceMessage(shared_ptr<Receivable>(received_messages[i]));
		    break;
		case MessageOrigin::fromWebApp:
		    handleWebappMessage(shared_ptr<Receivable>(received_messages[i]));
		    break;
		case MessageOrigin::fromMessageRelay:
		    handleMessagerelayMessage(shared_ptr<Receivable>(received_messages[i]));
		    break;
		case MessageOrigin::fromBroker:
		    handleBrokerMessage(shared_ptr<Receivable>(received_messages[i]));
		    break;
		default:
		    throw BrokerError(ErrorType::unimplemented,"dispatch(): Unimplemented origin.");
	    }
	    end = std::chrono::steady_clock::now();

	    error_log("Processed message in ",std::chrono::duration_cast<std::chrono::nanoseconds>(end-start).count()," ns");
	    // Shared pointers are destroyed automatically until control is here.
	}
    }
}
/***************************** Message handlers ****************************/

void ProtocolDispatcher::handlePersistenceMessage(shared_ptr<Receivable> msg)
{
    shared_ptr<PersistenceLayerResponse> response = dynamic_pointer_cast<PersistenceLayerResponse>(msg);
<commit_msg>Removed unnecessary benchmark code<commit_after># include "broker.hpp"
# include "broker-util.hpp"
# include "synchronization.hpp"
# include "cache.hpp"
# include "conf.hpp"
# include "broker2broker.hpp"
# include "transaction-maps.hpp"

TransactionMap transaction_cache;

/*
 * LOCKING POLICY
 *
 * For reading operations, the mutex of that map has to be obtained shared, e.g. using a shared_lock object.
 * For writing operations, the lock has to be exclusive and therefore unique_lock has to be used.
 *
 * R/W-references may be taken from the maps and written to without existing lock because there are
 * currently no signs that one transaction object may be used by two threads concurrently (if the other servers
 * are implementing the protocol correctly). The only situtation in which a catastrophe (unrestricted concurrent access
 * to data) could happen is if, for example, Persistence sends two messages with the same sequence number in a very short interval.
 * I that case, two threads might access the same map key; however, it is very unlikely that this will happen.
 *
 */

/*
 * CACHING
 *
 * A user's information is cached whenever there has been a ULKUP which was not triggered by UONLQ (in that case, no information is saved),
 * and LOGIN/LOGOUT operations update that information.
 */

/**
 * @brief Receive and process incoming messages.
 *
 * This function receives incoming messages and gives them to the appropriate handlers for each protocol event. It's
 * just a single infinite loop.
 *
 */
void ProtocolDispatcher::dispatch(void)
{
    vector<Receivable*> received_messages;
    unsigned int received_size = 0;

    received_messages.resize(3);

    while ( true )
    {
	// received_messages is an output argument!
	received_size = communicator.receiveMessages(received_messages);

	for ( unsigned int i = 0; i < received_size; i++ )
	{
	    switch ( received_messages[i]->sender )
	    {
		// shared_ptr -- because the delivered message is dynamically allocated.
		case MessageOrigin::fromPersistence:
		    handlePersistenceMessage(shared_ptr<Receivable>(received_messages[i]));
		    break;
		case MessageOrigin::fromWebApp:
		    handleWebappMessage(shared_ptr<Receivable>(received_messages[i]));
		    break;
		case MessageOrigin::fromMessageRelay:
		    handleMessagerelayMessage(shared_ptr<Receivable>(received_messages[i]));
		    break;
		case MessageOrigin::fromBroker:
		    handleBrokerMessage(shared_ptr<Receivable>(received_messages[i]));
		    break;
		default:
		    throw BrokerError(ErrorType::unimplemented,"dispatch(): Unimplemented origin.");
	    }
	    // Shared pointers are destroyed automatically until control is here.
	}
    }
}
/***************************** Message handlers ****************************/

void ProtocolDispatcher::handlePersistenceMessage(shared_ptr<Receivable> msg)
{
    shared_ptr<PersistenceLayerResponse> response = dynamic_pointer_cast<PersistenceLayerResponse>(msg);

{'fraction_non_alphanumeric': 0.1044969265609835, 'fraction_numerical': 0.0012940795858945326, 'mean_word_length': 4.600543478260869, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 24, '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': '97745', 'n_tokens_mistral': 1780, 'n_tokens_neox': 1633, 'n_words': 571}