I have an Interface for searching in some subsystems gathered by an ENUM. The Interface looks like this:
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;
}
And the ENUM looks like this
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);
}
}
At the moment I start the searches one after another. So my server hast to wait for a search to finish before it starts the next one. So the user has to wait very lang for the results to be presented. This code starts the search
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);
}
The resultmap is the same object for all subsystems, so I need a system that all searches are started at once and are able to put their result into the result-object.
I hope it is possible to fill those objects nearly synchron so the User doesn't have to wait for all systems to finish.
Best regards Daniel