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(); + } +}