From 78505a81ea4e7103f5c8c33717fbd824874ceb17 Mon Sep 17 00:00:00 2001 From: forge-bot Date: Sat, 18 Jul 2026 11:11:56 +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 | 77 +++++++++++++++++++ 1 file changed, 77 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..7c43a3f --- /dev/null +++ b/boot/common-framework/src/main/java/com/klaro/acquirecore/framework/TxServiceRegistry.java @@ -0,0 +1,77 @@ +package com.klaro.acquirecore.framework; + +import org.springframework.stereotype.Service; + +import jakarta.annotation.PostConstruct; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +/** + * Service registry replacing C TX_SERVICE/registry pattern. + * Acts as a central dispatcher for transactional services. + * Annotated with @Service for Spring component scanning. + */ +@Service +public class TxServiceRegistry { + + private final Map services = new ConcurrentHashMap<>(); + + @PostConstruct + public void init() { + // Registry initialized and ready for service lookups + } + + /** + * Register a transactional service by name. + * Mirrors C tx_registry_add(). + */ + public void registerService(String name, TxService service) { + services.put(name, service); + } + + /** + * Unregister a service by name. + */ + public void unregisterService(String name) { + services.remove(name); + } + + /** + * Lookup a registered service by name. + * Mirrors C tx_registry_lookup(). + */ + public TxService lookupService(String name) { + return services.get(name); + } + + /** + * Execute a transactional operation on a named service. + * Mirrors C tx_service_dispatch(). + */ + public TxResult dispatch(String serviceName, TxContext ctx, Object input) { + TxService service = lookupService(serviceName); + if (service == null) { + return TxResult.error("SERVICE_NOT_FOUND", "Service not registered: " + serviceName); + } + try { + Object result = service.execute(ctx, input); + return TxResult.ok(result); + } catch (Exception e) { + return TxResult.error("EXECUTION_FAILED", e.getMessage()); + } + } + + /** + * Check if a service is registered. + */ + public boolean isRegistered(String name) { + return services.containsKey(name); + } + + /** + * Get count of registered services. + */ + public int getServiceCount() { + return services.size(); + } +}