Search in sources :

Example 1 with GlobalServices

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;
}
Also used : ResourceHandler(org.apache.ofbiz.base.config.ResourceHandler) MainResourceHandler(org.apache.ofbiz.base.config.MainResourceHandler) LinkedList(java.util.LinkedList) GenericConfigException(org.apache.ofbiz.base.config.GenericConfigException) MainResourceHandler(org.apache.ofbiz.base.config.MainResourceHandler) ComponentConfig(org.apache.ofbiz.base.component.ComponentConfig) Future(java.util.concurrent.Future) GlobalServices(org.apache.ofbiz.service.config.model.GlobalServices)

Aggregations

LinkedList (java.util.LinkedList)1 Future (java.util.concurrent.Future)1 ComponentConfig (org.apache.ofbiz.base.component.ComponentConfig)1 GenericConfigException (org.apache.ofbiz.base.config.GenericConfigException)1 MainResourceHandler (org.apache.ofbiz.base.config.MainResourceHandler)1 ResourceHandler (org.apache.ofbiz.base.config.ResourceHandler)1 GlobalServices (org.apache.ofbiz.service.config.model.GlobalServices)1