/** {@inheritDoc} */ @SuppressWarnings("unchecked") protected <COMPONENT> COMPONENT getComponent(String name) { // user method return (COMPONENT) SingletonLaContainer.getComponent(name); }
/** {@inheritDoc} */ protected boolean hasComponent(Class<?> type) { // user method try { SingletonLaContainer.getComponent(type); return true; } catch (ComponentNotFoundException ignored) { return false; } }
/** {@inheritDoc} */ protected boolean hasComponent(Class<?> type) { // user method try { SingletonLaContainer.getComponent(type); return true; } catch (ComponentNotFoundException ignored) { return false; } }
/** * @param componentName The component name to find. (NotNull) * @return The found component. (NotNull) * @throws ComponentNotFoundException When the component is not found by the type. * @throws TooManyRegistrationComponentException When the component key is related to plural components. * @throws CyclicReferenceComponentException When the components refers each other. */ public static <COMPONENT> COMPONENT pickupComponentByName(String componentName) { final COMPONENT component = SingletonLaContainer.getComponent(componentName); // variable for generic return component; }
/** {@inheritDoc} */ protected <COMPONENT> COMPONENT getComponent(Class<COMPONENT> type) { // user method return SingletonLaContainer.getComponent(type); }
/** * @param componentType The component type to find. (NotNull) * @return The found component. (NotNull) * @throws ComponentNotFoundException When the component is not found by the type. * @throws TooManyRegistrationComponentException When the component key is related to plural components. * @throws CyclicReferenceComponentException When the components refers each other. */ public static <COMPONENT> COMPONENT getComponent(Class<COMPONENT> componentType) { // most frequently used return (COMPONENT) SingletonLaContainer.getComponent(componentType); }
/** * @param componentName The component name to find. (NotNull) * @return The found component. (NotNull) * @throws ComponentNotFoundException When the component is not found by the type. * @throws TooManyRegistrationComponentException When the component key is related to plural components. * @throws CyclicReferenceComponentException When the components refers each other. */ public static <COMPONENT> COMPONENT pickupComponentByName(String componentName) { final COMPONENT component = SingletonLaContainer.getComponent(componentName); // variable for generic return component; }
/** {@inheritDoc} */ @SuppressWarnings("unchecked") protected <COMPONENT> COMPONENT getComponent(String name) { // user method return (COMPONENT) SingletonLaContainer.getComponent(name); }
/** {@inheritDoc} */ protected boolean hasComponent(String name) { // user method try { SingletonLaContainer.getComponent(name); return true; } catch (ComponentNotFoundException ignored) { return false; } }
/** {@inheritDoc} */ protected boolean hasComponent(String name) { // user method try { SingletonLaContainer.getComponent(name); return true; } catch (ComponentNotFoundException ignored) { return false; } }
/** * @param componentType The component type to find. (NotNull) * @return The found component. (NotNull) * @throws ComponentNotFoundException When the component is not found by the type. * @throws TooManyRegistrationComponentException When the component key is related to plural components. * @throws CyclicReferenceComponentException When the components refers each other. */ public static <COMPONENT> COMPONENT getComponent(Class<COMPONENT> componentType) { // most frequently used return (COMPONENT) SingletonLaContainer.getComponent(componentType); }
/** {@inheritDoc} */ protected <COMPONENT> COMPONENT getComponent(Class<COMPONENT> type) { // user method return SingletonLaContainer.getComponent(type); }
@PostConstruct public void init() { esClient = SingletonLaContainer.getComponent(EsClient.class); riverConfigManager = SingletonLaContainer.getComponent(RiverConfigManager.class); }
private Object executeScript(final String lang, final String script, final String scriptTypeValue, final Map<String, Object> vars) { ScriptType scriptType; if (ScriptType.FILE.toString().equalsIgnoreCase(scriptTypeValue)) { scriptType = ScriptType.FILE; } else if (ScriptType.INDEXED.toString().equalsIgnoreCase(scriptTypeValue)) { scriptType = ScriptType.INDEXED; } else { scriptType = ScriptType.INLINE; } vars.put("logger", logger); final ScriptService scriptService = SingletonLaContainer.getComponent(ScriptService.class); return scriptService.execute(lang, script, scriptType, vars); }
protected String loadCharset(final InputStream inputStream, final int preloadSize) { BufferedInputStream bis = null; String encoding = null; try { bis = new BufferedInputStream(inputStream); final byte[] buffer = new byte[preloadSize]; final int size = bis.read(buffer); if (size != -1) { final String content = new String(buffer, 0, size); encoding = parseCharset(content); } } catch (final IOException e) { throw new CrawlingAccessException("Could not load a content.", e); } try { final EncodingHelper encodingHelper = SingletonLaContainer.getComponent(EncodingHelper.class); encoding = encodingHelper.normalize(encoding); } catch (final Exception e) { // NOP } return encoding; }
public static Object execute(final Map<String, Object> scriptSettings, final String target, final Consumer<Map<String, Object>> vars) { final String script = SettingsUtils.get(scriptSettings, target); final String lang = SettingsUtils.get(scriptSettings, "lang", WebRiverConstants.DEFAULT_SCRIPT_LANG); final String scriptTypeValue = SettingsUtils.get(scriptSettings, "script_type", "inline"); ScriptType scriptType; if (ScriptType.FILE.toString().equalsIgnoreCase(scriptTypeValue)) { scriptType = ScriptType.FILE; } else if (ScriptType.INDEXED.toString().equalsIgnoreCase(scriptTypeValue)) { scriptType = ScriptType.INDEXED; } else { scriptType = ScriptType.INLINE; } if (StringUtil.isNotBlank(script)) { final Map<String, Object> localVars = new HashMap<String, Object>(); vars.accept(localVars); try { final ScriptService scriptService = SingletonLaContainer.getComponent(ScriptService.class); final Object result = scriptService.execute(lang, script, scriptType, localVars); if (logger.isDebugEnabled()) { logger.debug("[{}] \"{}\" => {}", target, script, result); } return result; } catch (final Exception e) { logger.warn("Failed to execute script: " + script, e); } } return null; }
public static void main(final String[] args) { Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { synchronized (this) { SingletonLaContainerFactory.destroy(); } } }); SingletonLaContainerFactory.init(); final RiverWeb riverWeb = SingletonLaContainer.getComponent(RiverWeb.class); final CmdLineParser parser = new CmdLineParser(riverWeb, ParserProperties.defaults().withUsageWidth(80)); try { parser.parseArgument(args); } catch (final Exception e) { parser.printUsage(System.out); exitMethod.accept(1); return; } try { exitMethod.accept(riverWeb.execute()); } catch (final Exception e) { riverWeb.print(e.getMessage()); exitMethod.accept(1); logger.error("Failed to process your request.", e); } finally { SingletonLaContainerFactory.destroy(); } }
return crawl(SingletonLaContainer.getComponent(Crawler.class), configId, sessionId); } else { final String configIndex = config.getConfigIndex(); print("Config %s is started with Session %s.", configId, sessionId); try { crawl(SingletonLaContainer.getComponent(Crawler.class), configId.toString(), sessionId); } finally { print("Config %s is finished.", configId);
@Override protected boolean isContentUpdated(final CrawlerClient client, final UrlQueue<?> urlQueue) { final RiverConfigManager riverConfigManager = SingletonLaContainer.getComponent(RiverConfigManager.class); final RiverConfig riverConfig = riverConfigManager.get(crawlerContext.getSessionId()); if (riverConfig.isIncremental()) { final EsClient esClient = SingletonLaContainer.getComponent(EsClient.class); try { final SearchResponse response = esClient.prepareSearch(riverConfig.getIndex()).setTypes(riverConfig.getType()) .setQuery(QueryBuilders.termQuery("url", urlQueue.getUrl())).addField("lastModified") .addSort("lastModified", SortOrder.DESC).execute().actionGet(); final SearchHits hits = response.getHits(); if (hits.getTotalHits() > 0) { final SearchHitField lastModifiedField = hits.getAt(0).getFields().get("lastModified"); if (lastModifiedField != null) { final Date lastModified = ConversionUtil.convert(lastModifiedField.getValue(), Date.class); if (lastModified != null) { urlQueue.setLastModified(lastModified.getTime()); } } } } catch (final Exception e) { logger.debug("Failed to retrieve lastModified.", e); } } return super.isContentUpdated(client, urlQueue); } }
final List<String> wdUrlList = (List<String>) crawlSettings.get("web_driver_urls"); if (wdUrlList != null) { CrawlerClient client = SingletonLaContainer.getComponent("webDriverClient"); wdUrlList.stream().forEach(regex -> clientFactory.addClient(regex, client, 0)); final EsUrlFilterService urlFilterService = SingletonLaContainer.getComponent(EsUrlFilterService.class); final EsUrlQueueService urlQueueService = SingletonLaContainer.getComponent(EsUrlQueueService.class); final EsDataService dataService = SingletonLaContainer.getComponent(EsDataService.class);