From 63f85f0f818aeaca557a3a95dc54c7b125ac058d Mon Sep 17 00:00:00 2001 From: forge-bot Date: Sat, 18 Jul 2026 10:10:44 +0000 Subject: [PATCH] =?UTF-8?q?[framework]=20TxCore=20=E2=86=92=20common-frame?= =?UTF-8?q?work=20(ACM-FW-001)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../framework/TxServiceRegistry.java | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 boot/common-framework/src/main/java/com/klaro/acquirecore/framework/TxServiceRegistry.java diff --git a/boot/common-framework/src/main/java/com/klaro/acquirecore/framework/TxServiceRegistry.java b/boot/common-framework/src/main/java/com/klaro/acquirecore/framework/TxServiceRegistry.java new file mode 100644 index 0000000..4488127 --- /dev/null +++ b/boot/common-framework/src/main/java/com/klaro/acquirecore/framework/TxServiceRegistry.java @@ -0,0 +1,69 @@ +package com.klaro.acquirecore.framework; + +import org.springframework.stereotype.Service; +import jakarta.annotation.PostConstruct; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.function.BiConsumer; + +/** + * Service registry for transaction services. Migrated from txcore.c tx_service_registry. + * Replaces TX_SERVICE/registry pattern with @Service dispatch. + */ +@Service +public class TxServiceRegistry { + + /** Functional interface for transaction service handlers. */ + @FunctionalInterface + public interface TxServiceHandler { + TxResult execute(TxContext context); + } + + private final Map services = new ConcurrentHashMap<>(); + private final Map serviceConfigs = new ConcurrentHashMap<>(); + + @PostConstruct + public void initialize() {} + + public void registerService(String serviceName, TxServiceHandler handler) { + services.put(serviceName, handler); + } + + public void registerService(String serviceName, TxServiceHandler handler, TxConfig config) { + services.put(serviceName, handler); + serviceConfigs.put(serviceName, config); + } + + public void unregisterService(String serviceName) { + services.remove(serviceName); + serviceConfigs.remove(serviceName); + } + + public TxServiceHandler getService(String serviceName) { + return services.get(serviceName); + } + + public boolean hasService(String serviceName) { + return services.containsKey(serviceName); + } + + public TxConfig getConfig(String serviceName) { + return serviceConfigs.getOrDefault(serviceName, new TxConfig()); + } + + public TxResult execute(String serviceName, TxContext context) { + TxServiceHandler handler = services.get(serviceName); + if (handler == null) { + return TxResult.fail(context.getTxId(), "Service not found: " + serviceName); + } + return handler.execute(context); + } + + public void forEachService(BiConsumer action) { + services.forEach(action); + } + + public int getServiceCount() { + return services.size(); + } +}