org.lastaflute.di.core.SingletonLaContainer Java Examples
The following examples show how to use
org.lastaflute.di.core.SingletonLaContainer.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RwCrawlerThread.java From elasticsearch-river-web with Apache License 2.0 | 6 votes |
@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); }
Example #2
Source File: ComponentUtil.java From fess with Apache License 2.0 | 5 votes |
public static <T> T getComponent(final Class<T> clazz) { try { return SingletonLaContainer.getComponent(clazz); } catch (final NullPointerException e) { if (logger.isDebugEnabled()) { throw new ContainerNotAvailableException(clazz.getCanonicalName(), e); } else { throw new ContainerNotAvailableException(clazz.getCanonicalName()); } } }
Example #3
Source File: ComponentUtil.java From fess with Apache License 2.0 | 5 votes |
public static boolean available() { try { return SingletonLaContainer.getComponent(SYSTEM_HELPER) != null; } catch (final Exception e) { // ignore } return false; }
Example #4
Source File: ScriptUtils.java From elasticsearch-river-web with Apache License 2.0 | 5 votes |
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; }
Example #5
Source File: ScrapingTransformer.java From elasticsearch-river-web with Apache License 2.0 | 5 votes |
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); }
Example #6
Source File: ScrapingTransformer.java From elasticsearch-river-web with Apache License 2.0 | 4 votes |
@PostConstruct public void init() { esClient = SingletonLaContainer.getComponent(EsClient.class); riverConfigManager = SingletonLaContainer.getComponent(RiverConfigManager.class); }
Example #7
Source File: ContainerUtil.java From lastaflute with Apache License 2.0 | 2 votes |
/** * @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); }
Example #8
Source File: ContainerUtil.java From lastaflute with Apache License 2.0 | 2 votes |
/** * @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; }