Implémentation complète du scénario 11 (IO System Stress Test) avec correction majeure de l'architecture de routing IntraIO. ## Nouveaux Modules de Test (Scenario 11) - ProducerModule: Publie messages pour tests IO - ConsumerModule: Consomme et valide messages reçus - BroadcastModule: Test multi-subscriber broadcasting - BatchModule: Test low-frequency batching - IOStressModule: Tests de charge concurrents ## Test d'Intégration - test_11_io_system.cpp: 6 tests validant: * Basic Publish-Subscribe * Pattern Matching avec wildcards * Multi-Module Routing (1-to-many) * Low-Frequency Subscriptions (batching) * Backpressure & Queue Overflow * Thread Safety (concurrent pub/pull) ## Fix Architecture Critique: IntraIO Routing **Problème**: IntraIO::publish() et subscribe() n'utilisaient PAS IntraIOManager pour router entre modules. **Solution**: Utilisation de JSON comme format de transport intermédiaire - IntraIO::publish() → extrait JSON → IntraIOManager::routeMessage() - IntraIO::subscribe() → enregistre au IntraIOManager::registerSubscription() - IntraIOManager::routeMessage() → copie JSON pour chaque subscriber → deliverMessage() **Bénéfices**: - ✅ Routing centralisé fonctionnel - ✅ Support 1-to-many (copie JSON au lieu de move unique_ptr) - ✅ Pas besoin d'implémenter IDataNode::clone() - ✅ Compatible futur NetworkIO (JSON sérialisable) ## Modules Scenario 13 (Cross-System) - ConfigWatcherModule, PlayerModule, EconomyModule, MetricsModule - test_13_cross_system.cpp (stub) ## Documentation - CLAUDE_NEXT_SESSION.md: Instructions détaillées pour build/test 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
133 lines
3.9 KiB
C++
133 lines
3.9 KiB
C++
#include "EconomyModule.h"
|
|
#include <iostream>
|
|
|
|
namespace grove {
|
|
|
|
EconomyModule::EconomyModule() {
|
|
std::cout << "[EconomyModule] Constructor" << std::endl;
|
|
}
|
|
|
|
EconomyModule::~EconomyModule() {
|
|
std::cout << "[EconomyModule] Destructor" << std::endl;
|
|
}
|
|
|
|
void EconomyModule::process(const IDataNode& input) {
|
|
// Process incoming messages from IO
|
|
if (io && io->hasMessages() > 0) {
|
|
auto msg = io->pullMessage();
|
|
playerEventsProcessed++;
|
|
handlePlayerEvent(msg.topic, msg.data.get());
|
|
}
|
|
}
|
|
|
|
void EconomyModule::setConfiguration(const IDataNode& configNode, IIO* ioPtr, ITaskScheduler* schedulerPtr) {
|
|
std::cout << "[EconomyModule] setConfiguration called" << std::endl;
|
|
|
|
this->io = ioPtr;
|
|
this->scheduler = schedulerPtr;
|
|
|
|
// Store config
|
|
config = std::make_unique<JsonDataNode>("config", nlohmann::json::object());
|
|
|
|
// Subscribe to player events
|
|
if (io) {
|
|
io->subscribe("player:*");
|
|
}
|
|
}
|
|
|
|
const IDataNode& EconomyModule::getConfiguration() {
|
|
if (!config) {
|
|
config = std::make_unique<JsonDataNode>("config", nlohmann::json::object());
|
|
}
|
|
return *config;
|
|
}
|
|
|
|
std::unique_ptr<IDataNode> EconomyModule::getHealthStatus() {
|
|
nlohmann::json health = {
|
|
{"status", "healthy"},
|
|
{"totalBonusesApplied", totalBonusesApplied},
|
|
{"playerEventsProcessed", playerEventsProcessed}
|
|
};
|
|
return std::make_unique<JsonDataNode>("health", health);
|
|
}
|
|
|
|
void EconomyModule::shutdown() {
|
|
std::cout << "[EconomyModule] Shutdown - Processed " << playerEventsProcessed << " player events" << std::endl;
|
|
}
|
|
|
|
std::unique_ptr<IDataNode> EconomyModule::getState() {
|
|
nlohmann::json state = {
|
|
{"totalBonusesApplied", totalBonusesApplied},
|
|
{"playerEventsProcessed", playerEventsProcessed}
|
|
};
|
|
return std::make_unique<JsonDataNode>("state", state);
|
|
}
|
|
|
|
void EconomyModule::setState(const IDataNode& state) {
|
|
totalBonusesApplied = state.getInt("totalBonusesApplied", 0);
|
|
playerEventsProcessed = state.getInt("playerEventsProcessed", 0);
|
|
std::cout << "[EconomyModule] State restored" << std::endl;
|
|
}
|
|
|
|
void EconomyModule::setDataTree(IDataTree* treePtr) {
|
|
this->tree = treePtr;
|
|
}
|
|
|
|
void EconomyModule::handlePlayerEvent(const std::string& topic, IDataNode* data) {
|
|
std::cout << "[EconomyModule] Handling player event: " << topic << std::endl;
|
|
|
|
if (topic == "player:level_up") {
|
|
// Apply economy bonus
|
|
if (data) {
|
|
int goldBonus = data->getInt("goldBonus", 0);
|
|
applyEconomyBonus(goldBonus);
|
|
}
|
|
} else if (topic == "player:gold:updated") {
|
|
// Verify synchronization
|
|
if (data && tree) {
|
|
auto dataRoot = tree->getDataRoot();
|
|
auto player = dataRoot->getChild("player");
|
|
if (player) {
|
|
auto profile = player->getChild("profile");
|
|
if (profile) {
|
|
int goldInData = profile->getInt("gold", 0);
|
|
int goldInMsg = data->getInt("gold", 0);
|
|
|
|
if (goldInData == goldInMsg) {
|
|
std::cout << "[EconomyModule] Sync OK: gold=" << goldInData << std::endl;
|
|
} else {
|
|
std::cout << "[EconomyModule] SYNC ERROR: msg=" << goldInMsg
|
|
<< " data=" << goldInData << std::endl;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void EconomyModule::applyEconomyBonus(int goldBonus) {
|
|
totalBonusesApplied += goldBonus;
|
|
|
|
if (!tree) return;
|
|
|
|
auto dataRoot = tree->getDataRoot();
|
|
|
|
nlohmann::json bonusData = {
|
|
{"levelUpBonus", goldBonus},
|
|
{"totalBonuses", totalBonusesApplied}
|
|
};
|
|
|
|
auto bonuses = std::make_unique<JsonDataNode>("bonuses", bonusData);
|
|
|
|
std::cout << "[EconomyModule] Applied bonus: " << goldBonus << std::endl;
|
|
}
|
|
|
|
} // namespace grove
|
|
|
|
// Export C API
|
|
extern "C" {
|
|
grove::IModule* createModule() {
|
|
return new grove::EconomyModule();
|
|
}
|
|
}
|