public void scan(Configuration configuration) { List<ScannedItemHandler> handlers = new ArrayList<ScannedItemHandler>(); for (Factory factory : factories.values()) { try { Class<?> clazz = TypeUtil.forName(factory.getClassName()); Method method = clazz.getMethod("getScannedItemHandler"); if ((Modifier.STATIC & method.getModifiers()) != 0 && method.getParameterTypes().length == 0) { ScannedItemHandler handler = (ScannedItemHandler)method.invoke(null); handlers.add(handler); } else log.warn("Factory class %s contains an unexpected signature for method: %s", factory.getClassName(), method); } catch (NoSuchMethodException e) { // ignore } catch (ClassNotFoundException e) { log.error(e, "Could not load factory class: %s", factory.getClassName()); } catch (Exception e) { log.error(e, "Error while calling %s.getScannedItemHandler() method", factory.getClassName()); } } scanConfig(configuration != null ? configuration.getFlexServicesConfigProperties() : null, handlers); }
public void scan(Configuration configuration) { List<ScannedItemHandler> handlers = new ArrayList<ScannedItemHandler>(); for (Factory factory : factories.values()) { try { Class<?> clazz = TypeUtil.forName(factory.getClassName()); Method method = clazz.getMethod("getScannedItemHandler"); if ((Modifier.STATIC & method.getModifiers()) != 0 && method.getParameterTypes().length == 0) { ScannedItemHandler handler = (ScannedItemHandler)method.invoke(null); handlers.add(handler); } else log.warn("Factory class %s contains an unexpected signature for method: %s", factory.getClassName(), method); } catch (NoSuchMethodException e) { // ignore } catch (ClassNotFoundException e) { log.error(e, "Could not load factory class: %s", factory.getClassName()); } catch (Exception e) { log.error(e, "Error while calling %s.getScannedItemHandler() method", factory.getClassName()); } } scanConfig(configuration != null ? configuration.getFlexServicesConfigProperties() : null, handlers); }
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(); } }