private static ServiceFactory getServiceFactory(Map<String, Object> cache, GraniteContext context, String factoryId, String key) { lock.lock(); try { ServiceFactory factory = (ServiceFactory)cache.get(key); if (factory == null) { log.debug(">> No cached factory for: %s", factoryId); Factory config = ((ServicesConfig)context.getServicesConfig()).findFactoryById(factoryId); if (config == null) config = getDefaultFactoryConfig(); try { Class<? extends ServiceFactory> clazz = TypeUtil.forName(config.getClassName(), ServiceFactory.class); factory = clazz.newInstance(); factory.configure(config.getProperties()); } catch (Exception e) { throw new ServiceException("Could not instantiate factory: " + factoryId + " of type " + config.getClassName(), e); } cache.put(key, factory); } else log.debug(">> Found a cached factory for: %s", factoryId); log.debug("<< Returning factory: %s", factory); return factory; } finally { lock.unlock(); } }
private static ServiceFactory getServiceFactory(Map<String, Object> cache, GraniteContext context, String factoryId, String key) { lock.lock(); try { ServiceFactory factory = (ServiceFactory)cache.get(key); if (factory == null) { log.debug(">> No cached factory for: %s", factoryId); Factory config = context.getServicesConfig().findFactoryById(factoryId); if (config == null) config = getDefaultFactoryConfig(); try { Class<? extends ServiceFactory> clazz = TypeUtil.forName(config.getClassName(), ServiceFactory.class); factory = clazz.newInstance(); factory.configure(config.getProperties()); } catch (Exception e) { throw new ServiceException("Could not instantiate factory: " + factoryId + " of type " + config.getClassName(), e); } cache.put(key, factory); } else log.debug(">> Found a cached factory for: %s", factoryId); log.debug("<< Returning factory: %s", factory); return factory; } finally { lock.unlock(); } }