[framework] TxCore → common-framework (ACM-FW-001)
This commit is contained in:
parent
ebac6af45d
commit
16f1c5beeb
1 changed files with 57 additions and 0 deletions
|
|
@ -0,0 +1,57 @@
|
|||
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 for transaction-aware services.
|
||||
* Migrated from txcore.c TX_SERVICE registry functionality.
|
||||
* Replaces C function pointers and registry with Spring @Service DI.
|
||||
*/
|
||||
@Service
|
||||
public class TxServiceRegistry {
|
||||
|
||||
private final Map<String, TxService> services = new ConcurrentHashMap<>();
|
||||
|
||||
@PostConstruct
|
||||
public void initialize() {}
|
||||
|
||||
public void registerService(String name, TxService service) {
|
||||
services.put(name, service);
|
||||
}
|
||||
|
||||
public void unregisterService(String name) {
|
||||
services.remove(name);
|
||||
}
|
||||
|
||||
public TxService getService(String name) {
|
||||
return services.get(name);
|
||||
}
|
||||
|
||||
public boolean hasService(String name) {
|
||||
return services.containsKey(name);
|
||||
}
|
||||
|
||||
public <T> TxResult<T> executeInTransaction(String serviceName, TxOperation<T> operation) {
|
||||
TxService service = services.get(serviceName);
|
||||
if (service == null) {
|
||||
return TxResult.failure("SERVICE_NOT_FOUND", "Service not registered: " + serviceName);
|
||||
}
|
||||
return service.execute(operation);
|
||||
}
|
||||
|
||||
public String[] getRegisteredServiceNames() {
|
||||
return services.keySet().toArray(new String[0]);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
services.clear();
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface TxOperation<T> {
|
||||
T execute(TxContext context);
|
||||
}
|
||||
}
|
||||
Reference in a new issue