【发布时间】:2019-06-19 05:02:29
【问题描述】:
我有一个接口,用于在 ENUM 收集的某些子系统中进行搜索。界面如下所示:
public interface ReferenceController {
public Map<String, ReferenceElement> searchElements(String searchField, List<String> searchItems, SystemStage systemStage) throws Exception;
public Boolean isAvailable(SystemStage systemStage) throws Exception;
public Boolean isAvailable(SystemStage systemStage) throws Exception;
}
ENUM 看起来像这样
public enum ReferenceSystem implements ReferenceController{
UCMDB (UcmdbFunctions.class),
PROIPS (ProIPSFunctions.class),
KV (KvFunctions.class),
FISERVICE(FiServiceFunctions.class),
COMMAND (CommandFunctions.class),
FII (FiiFunctions.class);
private Class<? extends ReferenceController> clazz;
private ReferenceSystem(Class<? extends ReferenceController> controllerClass) {
this.clazz = controllerClass;
}
public String displayName() {
return displayName(Locale.GERMAN);
}
public String displayName(Locale locale) {
ResourceBundle bundle = ResourceBundle.getBundle("EnumI18n", locale);
return bundle.getString(toString());
}
public Class<? extends ReferenceController> getClassname() { return clazz; }
@Override
public Map<String, ReferenceElement> searchElements(String searchField, List<String> searchItems, SystemStage systemStage) throws Exception {
Map<String, ReferenceElement> result = clazz.newInstance().searchElements(searchField, searchItems, systemStage);
return result;
}
@Override
public String getStateMapping(String value) {
try {
return clazz.newInstance().getStateMapping(value);
} catch (IllegalAccessException | InstantiationException e) {
return null;
}
}
@Override
public Boolean isAvailable(SystemStage systemStage) throws Exception {
return clazz.newInstance().isAvailable(systemStage);
}
}
此刻我开始一个接一个地搜索。所以我的服务器必须等待搜索完成才能开始下一个搜索。因此,用户必须等待很长时间才能显示结果。 此代码开始搜索
public static void performSingleSearch(ReferenceSystem referenceSystem, String searchField, List<String> searchValues, SystemStage systemStage) throws Exception {
if(!isAvailable(referenceSystem, systemStage)) return;
Map<String, ReferenceElement> result = new HashMap<>();
try {
result = referenceSystem.searchElements(searchField, searchValues, systemStage);
} catch (Exception e) {
return;
}
if(result != null) orderResults(result, referenceSystem);
}
resultmap 是所有子系统的同一个对象,所以我需要一个系统,所有搜索都立即开始,并且能够将它们的结果放入结果对象中。
我希望可以几乎同步地填充这些对象,这样用户就不必等待所有系统完成。
最好的问候 丹尼尔
【问题讨论】:
标签: java multithreading