[framework] TxCore → common-framework (ACM-FW-001)

This commit is contained in:
forge-bot 2026-07-18 11:11:56 +00:00
parent dedbfdc4a6
commit 78505a81ea

View file

@ -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<String, TxService> 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 <T> TxResult<T> 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();
}
}