use of org.apache.ofbiz.base.config.GenericConfigException in project ofbiz-framework by apache.
the class GenericEngineFactory method getGenericEngine.
/**
* Gets the GenericEngine instance that corresponds to given the name
*@param engineName Name of the engine
*@return GenericEngine that corresponds to the engineName
*/
public GenericEngine getGenericEngine(String engineName) throws GenericServiceException {
String className = null;
try {
className = ServiceConfigUtil.getServiceEngine().getEngine(engineName).getClassName();
} catch (GenericConfigException e) {
throw new GenericServiceException(e);
}
GenericEngine engine = engines.get(engineName);
if (engine == null) {
synchronized (GenericEngineFactory.class) {
engine = engines.get(engineName);
if (engine == null) {
try {
ClassLoader loader = Thread.currentThread().getContextClassLoader();
Class<?> c = loader.loadClass(className);
Constructor<GenericEngine> cn = UtilGenerics.cast(c.getConstructor(ServiceDispatcher.class));
engine = cn.newInstance(dispatcher);
} catch (Exception e) {
throw new GenericServiceException(e.getMessage(), e);
}
if (engine != null) {
engines.put(engineName, engine);
}
}
}
}
return engine;
}
use of org.apache.ofbiz.base.config.GenericConfigException 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;
}
use of org.apache.ofbiz.base.config.GenericConfigException in project ofbiz-framework by apache.
the class ServiceConfigUtil method getServiceConfig.
/**
* Returns the <code>ServiceConfig</code> instance.
* @throws GenericConfigException
*/
public static ServiceConfig getServiceConfig() throws GenericConfigException {
ServiceConfig instance = serviceConfigCache.get("instance");
if (instance == null) {
Element serviceConfigElement = getXmlDocument().getDocumentElement();
instance = ServiceConfig.create(serviceConfigElement);
serviceConfigCache.putIfAbsent("instance", instance);
instance = serviceConfigCache.get("instance");
for (ServiceConfigListener listener : configListeners) {
try {
listener.onServiceConfigChange(instance);
} catch (Exception e) {
Debug.logError(e, "Exception thrown while notifying listener " + listener + ": ", module);
}
}
}
return instance;
}
use of org.apache.ofbiz.base.config.GenericConfigException in project ofbiz-framework by apache.
the class AbstractEngine method createLocationMap.
// creates the location alias map
protected static Map<String, String> createLocationMap() {
Map<String, String> tmpMap = new HashMap<>();
List<ServiceLocation> locationsList = null;
try {
locationsList = ServiceConfigUtil.getServiceEngine().getServiceLocations();
} catch (GenericConfigException e) {
// FIXME: Refactor API so exceptions can be thrown and caught.
Debug.logError(e, module);
throw new RuntimeException(e.getMessage());
}
for (ServiceLocation e : locationsList) {
tmpMap.put(e.getName(), e.getLocation());
}
Debug.logInfo("Loaded Service Locations: " + tmpMap, module);
return Collections.unmodifiableMap(tmpMap);
}
use of org.apache.ofbiz.base.config.GenericConfigException in project ofbiz-framework by apache.
the class JNDITransactionFactory method getJndiConnection.
public static Connection getJndiConnection(String jndiName, String jndiServerName) throws SQLException, GenericEntityException {
DataSource ds = dsCache.get(jndiName);
if (ds != null) {
if (ds instanceof XADataSource) {
XADataSource xads = (XADataSource) ds;
return TransactionUtil.enlistConnection(xads.getXAConnection());
}
return ds.getConnection();
}
try {
if (Debug.infoOn()) {
Debug.logInfo("Doing JNDI lookup for name " + jndiName, module);
}
InitialContext ic = JNDIContextFactory.getInitialContext(jndiServerName);
if (ic != null) {
ds = (DataSource) ic.lookup(jndiName);
} else {
Debug.logWarning("Initial Context returned was NULL for server name " + jndiServerName, module);
}
if (ds != null) {
if (Debug.verboseOn()) {
Debug.logVerbose("Got a Datasource object.", module);
}
dsCache.putIfAbsent(jndiName, ds);
ds = dsCache.get(jndiName);
Connection con;
if (ds instanceof XADataSource) {
if (Debug.infoOn()) {
Debug.logInfo("Got XADataSource for name " + jndiName, module);
}
XADataSource xads = (XADataSource) ds;
XAConnection xac = xads.getXAConnection();
con = TransactionUtil.enlistConnection(xac);
} else {
if (Debug.infoOn()) {
Debug.logInfo("Got DataSource for name " + jndiName, module);
}
con = ds.getConnection();
}
return con;
}
Debug.logError("Datasource returned was NULL.", module);
} catch (NamingException ne) {
Debug.logWarning(ne, "Failed to find DataSource named " + jndiName + " in JNDI server with name " + jndiServerName + ". Trying normal database.", module);
} catch (GenericConfigException gce) {
throw new GenericEntityException("Problems with the JNDI configuration.", gce.getNested());
}
return null;
}
Aggregations