java系统设计:为m个不同数据源中的n个用户请求数据的服务

pn9klfpd  于 2021-07-13  发布在  Java
关注(0)|答案(0)|浏览(144)

我正在努力为一个需要为m个申请者调用n个服务的系统创建一个干净的设计。
细节:
每个服务返回不同的域对象
每个服务调用应该在不同的线程中
申请人最多3人
最大服务数目前没有定义的限制。需要检查系统限制
我正在寻找设计和可维护性方面的最佳实践。我的目标是定义一个实现接口的新服务,然后系统将该服务添加到列表中。在我当前的设计中,我需要手动定义服务列表,并传递依赖项和所需的数据。注意:我使用的是Java8和spring
//给予
future futureone=新数据采集器Askone(应用数据,服务一);
future future2=新数据采集器asktwo(应用程序数据,服务二);
//在哪里
datacollectortask扩展了callable(不是bean,只是pojo),它将使用应用程序数据调用服务(从构造函数初始化)。

@Data
@RequiredArgsConstructor
public class DataCollectorTask<T> implements Callable<T> {
    public final BankRecordsService bankRecordsService;
    public final ApplicantData applicantData;

    @Override
    public T call() throws Exception {
        return bankRecordsService.executeRequest(applicantData)
    }

在spring中,我可以自动连接扩展接口的bean列表。在本例中,我将能够获得服务列表,因为它们将具有@service注解,但callableservice bean只是pojo(不是由spring管理)。
服务接口

public interface DataCollector<T> {

  /* This will be use to disable or enable services in different environments*/
  boolean isActive();

  /*The data service will be responsible to implement the mapping*/
  void mapData(DataCollectorRequest request, ApplicantData mappingDestination, T data);

  /*different services have different time expectations*/
  int getTimeOut();

  /*this will determine based on the data in the applicantData if everything was successful*/
  boolean isRequestSatisfied(ApplicantData valueInDatabase, DataCollectorRequest dataCollectorRequest);

}

我觉得有比我现在的设计更好的设计。另外,我有一个关于多线程的问题,如果系统为每个应用程序创建一个线程,那么每个线程将为每个服务创建一个线程?或者只是为n*m服务创建一个线程。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题