use of org.apache.ofbiz.service.config.model.GlobalServices in project ofbiz-framework by apache.
the class DispatchContext method getGlobalServiceMap.
private Map<String, ModelService> getGlobalServiceMap() {
Map<String, ModelService> serviceMap = modelServiceMapByModel.get(this.model);
if (serviceMap == null) {
serviceMap = new HashMap<>();
List<Future<Map<String, ModelService>>> futures = new LinkedList<>();
List<GlobalServices> globalServicesList = null;
try {
globalServicesList = ServiceConfigUtil.getServiceEngine().getGlobalServices();
} catch (GenericConfigException e) {
// FIXME: Refactor API so exceptions can be thrown and caught.
Debug.logError(e, module);
throw new RuntimeException(e.getMessage());
}
for (GlobalServices globalServices : globalServicesList) {
ResourceHandler handler = new MainResourceHandler(ServiceConfigUtil.getServiceEngineXmlFileName(), globalServices.getLoader(), globalServices.getLocation());
futures.add(ExecutionPool.GLOBAL_FORK_JOIN.submit(createServiceReaderCallable(handler)));
}
// get all of the component resource model stuff, ie specified in each ofbiz-component.xml file
for (ComponentConfig.ServiceResourceInfo componentResourceInfo : ComponentConfig.getAllServiceResourceInfos("model")) {
futures.add(ExecutionPool.GLOBAL_FORK_JOIN.submit(createServiceReaderCallable(componentResourceInfo.createResourceHandler())));
}
for (Map<String, ModelService> servicesMap : ExecutionPool.getAllFutures(futures)) {
if (servicesMap != null) {
serviceMap.putAll(servicesMap);
}
}
Map<String, ModelService> cachedServiceMap = modelServiceMapByModel.putIfAbsentAndGet(this.model, serviceMap);
if (cachedServiceMap == serviceMap) {
// same object: this means that the object created by this thread was actually added to the cache
ServiceEcaUtil.reloadConfig();
}
}
return serviceMap;
}
Aggregations