fix #435 : suppress error messages
This commit is contained in:
parent
7b860ca073
commit
b6458875aa
26 changed files with 194 additions and 73 deletions
|
@ -23,7 +23,6 @@ import org.codelibs.fess.helper.SystemHelper;
|
|||
import org.codelibs.fess.job.JobExecutor;
|
||||
import org.codelibs.fess.job.ScheduledJobException;
|
||||
import org.codelibs.fess.util.ComponentUtil;
|
||||
import org.lastaflute.di.core.SingletonLaContainer;
|
||||
import org.lastaflute.job.JobManager;
|
||||
import org.lastaflute.job.LaJob;
|
||||
import org.lastaflute.job.LaJobRuntime;
|
||||
|
@ -94,7 +93,7 @@ public class ScriptExecutorJob implements LaJob {
|
|||
}
|
||||
|
||||
private void storeJobLog(final JobLog jobLog) {
|
||||
final JobLogService jobLogService = SingletonLaContainer.getComponent(JobLogService.class);
|
||||
final JobLogService jobLogService = ComponentUtil.getComponent(JobLogService.class);
|
||||
jobLogService.store(jobLog);
|
||||
}
|
||||
|
||||
|
|
|
@ -41,7 +41,6 @@ import org.codelibs.fess.util.ComponentUtil;
|
|||
import org.dbflute.cbean.result.ListResultBean;
|
||||
import org.dbflute.cbean.result.PagingResultBean;
|
||||
import org.dbflute.optional.OptionalEntity;
|
||||
import org.lastaflute.di.core.SingletonLaContainer;
|
||||
|
||||
public class FailureUrlService implements Serializable {
|
||||
|
||||
|
@ -180,7 +179,7 @@ public class FailureUrlService implements Serializable {
|
|||
}
|
||||
|
||||
public void store(final CrawlingConfig crawlingConfig, final String errorName, final String url, final Throwable e) {
|
||||
final FailureUrlBhv bhv = SingletonLaContainer.getComponent(FailureUrlBhv.class);
|
||||
final FailureUrlBhv bhv = ComponentUtil.getComponent(FailureUrlBhv.class);
|
||||
FailureUrl failureUrl = bhv.selectEntity(cb -> {
|
||||
cb.query().setUrl_Equal(url);
|
||||
if (crawlingConfig != null) {
|
||||
|
|
|
@ -38,6 +38,7 @@ import org.codelibs.fess.crawler.entity.UrlQueue;
|
|||
import org.codelibs.fess.crawler.log.LogType;
|
||||
import org.codelibs.fess.es.client.FessEsClient;
|
||||
import org.codelibs.fess.es.config.exentity.CrawlingConfig;
|
||||
import org.codelibs.fess.exception.ContainerNotAvailableException;
|
||||
import org.codelibs.fess.helper.CrawlingConfigHelper;
|
||||
import org.codelibs.fess.helper.CrawlingInfoHelper;
|
||||
import org.codelibs.fess.helper.IndexingHelper;
|
||||
|
@ -75,7 +76,8 @@ public class FessCrawlerThread extends CrawlerThread {
|
|||
final Map<String, Object> dataMap = new HashMap<String, Object>();
|
||||
dataMap.put(fessConfig.getIndexFieldUrl(), url);
|
||||
final List<String> roleTypeList = new ArrayList<String>();
|
||||
for (final String roleType : crawlingConfig.getRoleTypeValues()) {
|
||||
final String[] roleTypeValues = crawlingConfig.getRoleTypeValues();
|
||||
for (final String roleType : roleTypeValues) {
|
||||
roleTypeList.add(roleType);
|
||||
}
|
||||
if (url.startsWith("smb://")) {
|
||||
|
@ -184,8 +186,15 @@ public class FessCrawlerThread extends CrawlerThread {
|
|||
protected void storeChildUrlsToQueue(final UrlQueue<?> urlQueue, final Set<RequestData> childUrlSet) {
|
||||
if (childUrlSet != null) {
|
||||
// add an url
|
||||
storeChildUrls(childUrlSet.stream().filter(rd -> StringUtil.isNotBlank(rd.getUrl())).collect(Collectors.toSet()),
|
||||
urlQueue.getUrl(), urlQueue.getDepth() != null ? urlQueue.getDepth() + 1 : 1);
|
||||
try {
|
||||
storeChildUrls(childUrlSet.stream().filter(rd -> StringUtil.isNotBlank(rd.getUrl())).collect(Collectors.toSet()),
|
||||
urlQueue.getUrl(), urlQueue.getDepth() != null ? urlQueue.getDepth() + 1 : 1);
|
||||
} catch (Throwable t) {
|
||||
if (!ComponentUtil.available()) {
|
||||
throw new ContainerNotAvailableException(t);
|
||||
}
|
||||
throw t;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,6 @@ import org.codelibs.fess.crawler.extractor.Extractor;
|
|||
import org.codelibs.fess.exception.FessSystemException;
|
||||
import org.codelibs.fess.mylasta.direction.FessConfig;
|
||||
import org.codelibs.fess.util.ComponentUtil;
|
||||
import org.lastaflute.di.core.SingletonLaContainer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -46,7 +45,7 @@ public class FessTikaTransformer extends AbstractFessFileTransformer {
|
|||
|
||||
@Override
|
||||
protected Extractor getExtractor(final ResponseData responseData) {
|
||||
final Extractor extractor = SingletonLaContainer.getComponent("tikaExtractor");
|
||||
final Extractor extractor = ComponentUtil.getComponent("tikaExtractor");
|
||||
if (extractor == null) {
|
||||
throw new FessSystemException("Could not find tikaExtractor.");
|
||||
}
|
||||
|
|
|
@ -38,8 +38,8 @@ import org.codelibs.fess.ds.DataStoreCrawlingException;
|
|||
import org.codelibs.fess.ds.DataStoreException;
|
||||
import org.codelibs.fess.ds.IndexUpdateCallback;
|
||||
import org.codelibs.fess.es.config.exentity.DataConfig;
|
||||
import org.codelibs.fess.util.ComponentUtil;
|
||||
import org.codelibs.fess.util.StreamUtil;
|
||||
import org.lastaflute.di.core.SingletonLaContainer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -261,11 +261,11 @@ public class CsvDataStoreImpl extends AbstractDataStoreImpl {
|
|||
} else {
|
||||
url = csvFile.getAbsolutePath() + ":" + csvReader.getLineNumber();
|
||||
}
|
||||
final FailureUrlService failureUrlService = SingletonLaContainer.getComponent(FailureUrlService.class);
|
||||
final FailureUrlService failureUrlService = ComponentUtil.getComponent(FailureUrlService.class);
|
||||
failureUrlService.store(dataConfig, errorName, url, target);
|
||||
} catch (final Exception e) {
|
||||
final String url = csvFile.getAbsolutePath() + ":" + csvReader.getLineNumber();
|
||||
final FailureUrlService failureUrlService = SingletonLaContainer.getComponent(FailureUrlService.class);
|
||||
final FailureUrlService failureUrlService = ComponentUtil.getComponent(FailureUrlService.class);
|
||||
failureUrlService.store(dataConfig, e.getClass().getCanonicalName(), url, e);
|
||||
|
||||
logger.warn("Crawling Access Exception at : " + dataMap, e);
|
||||
|
|
|
@ -38,7 +38,6 @@ import org.codelibs.fess.mylasta.direction.FessConfig;
|
|||
import org.codelibs.fess.util.ComponentUtil;
|
||||
import org.codelibs.fess.util.ParameterUtil;
|
||||
import org.dbflute.cbean.result.ListResultBean;
|
||||
import org.lastaflute.di.core.SingletonLaContainer;
|
||||
|
||||
/**
|
||||
* @author FreeGen
|
||||
|
@ -251,7 +250,7 @@ public class FileConfig extends BsFileConfig implements CrawlingConfig {
|
|||
|
||||
@Override
|
||||
public void initializeClientFactory(final CrawlerClientFactory clientFactory) {
|
||||
final FileAuthenticationService fileAuthenticationService = SingletonLaContainer.getComponent(FileAuthenticationService.class);
|
||||
final FileAuthenticationService fileAuthenticationService = ComponentUtil.getComponent(FileAuthenticationService.class);
|
||||
|
||||
// Parameters
|
||||
final Map<String, Object> paramMap = new HashMap<String, Object>();
|
||||
|
|
|
@ -38,7 +38,6 @@ import org.codelibs.fess.mylasta.direction.FessConfig;
|
|||
import org.codelibs.fess.util.ComponentUtil;
|
||||
import org.codelibs.fess.util.ParameterUtil;
|
||||
import org.dbflute.cbean.result.ListResultBean;
|
||||
import org.lastaflute.di.core.SingletonLaContainer;
|
||||
|
||||
/**
|
||||
* @author FreeGen
|
||||
|
@ -255,8 +254,8 @@ public class WebConfig extends BsWebConfig implements CrawlingConfig {
|
|||
|
||||
@Override
|
||||
public void initializeClientFactory(final CrawlerClientFactory clientFactory) {
|
||||
final WebAuthenticationService webAuthenticationService = SingletonLaContainer.getComponent(WebAuthenticationService.class);
|
||||
final RequestHeaderService requestHeaderService = SingletonLaContainer.getComponent(RequestHeaderService.class);
|
||||
final WebAuthenticationService webAuthenticationService = ComponentUtil.getComponent(WebAuthenticationService.class);
|
||||
final RequestHeaderService requestHeaderService = ComponentUtil.getComponent(RequestHeaderService.class);
|
||||
|
||||
// HttpClient Parameters
|
||||
final Map<String, Object> paramMap = new HashMap<String, Object>();
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
package org.codelibs.fess.exception;
|
||||
|
||||
public class ContainerNotAvailableException extends FessSystemException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public ContainerNotAvailableException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
}
|
|
@ -36,6 +36,7 @@ import org.codelibs.fess.app.service.CrawlingInfoService;
|
|||
import org.codelibs.fess.app.service.PathMappingService;
|
||||
import org.codelibs.fess.crawler.client.EsClient;
|
||||
import org.codelibs.fess.es.client.FessEsClient;
|
||||
import org.codelibs.fess.exception.ContainerNotAvailableException;
|
||||
import org.codelibs.fess.helper.CrawlingInfoHelper;
|
||||
import org.codelibs.fess.helper.DataIndexHelper;
|
||||
import org.codelibs.fess.helper.DuplicateHostHelper;
|
||||
|
@ -49,7 +50,6 @@ import org.kohsuke.args4j.CmdLineException;
|
|||
import org.kohsuke.args4j.CmdLineParser;
|
||||
import org.kohsuke.args4j.Option;
|
||||
import org.lastaflute.core.mail.Postbox;
|
||||
import org.lastaflute.di.core.SingletonLaContainer;
|
||||
import org.lastaflute.di.core.factory.SingletonLaContainerFactory;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -194,17 +194,25 @@ public class Crawler implements Serializable {
|
|||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Destroying LaContainer..");
|
||||
}
|
||||
SingletonLaContainerFactory.destroy();
|
||||
destroyContainer();
|
||||
}
|
||||
|
||||
};
|
||||
Runtime.getRuntime().addShutdownHook(shutdownCallback);
|
||||
|
||||
exitCode = process(options);
|
||||
} catch (final ContainerNotAvailableException e) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Crawler is stopped.", e);
|
||||
} else if (logger.isInfoEnabled()) {
|
||||
logger.info("Crawler is stopped.");
|
||||
}
|
||||
exitCode = Constants.EXIT_FAIL;
|
||||
} catch (final Throwable t) {
|
||||
logger.error("Crawler does not work correctly.", t);
|
||||
exitCode = Constants.EXIT_FAIL;
|
||||
} finally {
|
||||
SingletonLaContainerFactory.destroy();
|
||||
destroyContainer();
|
||||
}
|
||||
|
||||
if (exitCode != Constants.EXIT_OK) {
|
||||
|
@ -212,8 +220,14 @@ public class Crawler implements Serializable {
|
|||
}
|
||||
}
|
||||
|
||||
private static void destroyContainer() {
|
||||
synchronized (SingletonLaContainerFactory.class) {
|
||||
SingletonLaContainerFactory.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
private static int process(final Options options) {
|
||||
final Crawler crawler = SingletonLaContainer.getComponent(Crawler.class);
|
||||
final Crawler crawler = ComponentUtil.getComponent(Crawler.class);
|
||||
|
||||
if (StringUtil.isBlank(options.sessionId)) {
|
||||
// use a default session id
|
||||
|
|
|
@ -30,12 +30,12 @@ import org.codelibs.core.misc.DynamicProperties;
|
|||
import org.codelibs.fess.Constants;
|
||||
import org.codelibs.fess.crawler.client.EsClient;
|
||||
import org.codelibs.fess.es.client.FessEsClient;
|
||||
import org.codelibs.fess.exception.ContainerNotAvailableException;
|
||||
import org.codelibs.fess.helper.SuggestHelper;
|
||||
import org.codelibs.fess.util.ComponentUtil;
|
||||
import org.kohsuke.args4j.CmdLineException;
|
||||
import org.kohsuke.args4j.CmdLineParser;
|
||||
import org.kohsuke.args4j.Option;
|
||||
import org.lastaflute.di.core.SingletonLaContainer;
|
||||
import org.lastaflute.di.core.factory.SingletonLaContainerFactory;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -112,22 +112,35 @@ public class SuggestCreator implements Serializable {
|
|||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Destroying LaContainer..");
|
||||
}
|
||||
SingletonLaContainerFactory.destroy();
|
||||
destroyContainer();
|
||||
}
|
||||
};
|
||||
Runtime.getRuntime().addShutdownHook(shutdownCallback);
|
||||
exitCode = process(options);
|
||||
} catch (final ContainerNotAvailableException e) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Crawler is stopped.", e);
|
||||
} else if (logger.isInfoEnabled()) {
|
||||
logger.info("Crawler is stopped.");
|
||||
}
|
||||
exitCode = Constants.EXIT_FAIL;
|
||||
} catch (final Throwable t) {
|
||||
logger.error("Suggest creator does not work correctly.", t);
|
||||
exitCode = Constants.EXIT_FAIL;
|
||||
} finally {
|
||||
SingletonLaContainerFactory.destroy();
|
||||
destroyContainer();
|
||||
}
|
||||
|
||||
logger.info("Finished suggestCreator.");
|
||||
System.exit(exitCode);
|
||||
}
|
||||
|
||||
private static void destroyContainer() {
|
||||
synchronized (SingletonLaContainerFactory.class) {
|
||||
SingletonLaContainerFactory.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
private static int process(final Options options) {
|
||||
final DynamicProperties systemProperties = ComponentUtil.getSystemProperties();
|
||||
|
||||
|
@ -146,7 +159,7 @@ public class SuggestCreator implements Serializable {
|
|||
}
|
||||
}
|
||||
|
||||
final SuggestCreator creator = SingletonLaContainer.getComponent(SuggestCreator.class);
|
||||
final SuggestCreator creator = ComponentUtil.getComponent(SuggestCreator.class);
|
||||
final LocalDateTime startTime = LocalDateTime.now();
|
||||
int ret = creator.create();
|
||||
if (ret == 0) {
|
||||
|
|
|
@ -22,8 +22,8 @@ import org.codelibs.fess.crawler.exception.MultipleCrawlingAccessException;
|
|||
import org.codelibs.fess.crawler.helper.impl.LogHelperImpl;
|
||||
import org.codelibs.fess.crawler.log.LogType;
|
||||
import org.codelibs.fess.es.config.exentity.CrawlingConfig;
|
||||
import org.codelibs.fess.exception.ContainerNotAvailableException;
|
||||
import org.codelibs.fess.util.ComponentUtil;
|
||||
import org.lastaflute.di.core.SingletonLaContainer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -32,6 +32,12 @@ public class CrawlerLogHelper extends LogHelperImpl {
|
|||
|
||||
@Override
|
||||
public void log(final LogType key, final Object... objs) {
|
||||
if (!ComponentUtil.available()) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("container was destroyed.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
try {
|
||||
switch (key) {
|
||||
case CRAWLING_ACCESS_EXCEPTION: {
|
||||
|
@ -66,7 +72,18 @@ public class CrawlerLogHelper extends LogHelperImpl {
|
|||
default:
|
||||
break;
|
||||
}
|
||||
} catch (final ContainerNotAvailableException e) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("container was destroyed.");
|
||||
}
|
||||
return;
|
||||
} catch (final Exception e) {
|
||||
if (!ComponentUtil.available()) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("container was destroyed.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
logger.warn("Failed to store a failure url.", e);
|
||||
}
|
||||
|
||||
|
@ -78,7 +95,7 @@ public class CrawlerLogHelper extends LogHelperImpl {
|
|||
final CrawlingConfig crawlingConfig = getCrawlingConfig(crawlerContext.getSessionId());
|
||||
final String url = urlQueue.getUrl();
|
||||
|
||||
final FailureUrlService failureUrlService = SingletonLaContainer.getComponent(FailureUrlService.class);
|
||||
final FailureUrlService failureUrlService = ComponentUtil.getComponent(FailureUrlService.class);
|
||||
failureUrlService.store(crawlingConfig, errorName, url, e);
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ import org.codelibs.fess.app.service.FileConfigService;
|
|||
import org.codelibs.fess.app.service.WebConfigService;
|
||||
import org.codelibs.fess.es.config.exentity.CrawlingConfig;
|
||||
import org.codelibs.fess.es.config.exentity.CrawlingConfig.ConfigType;
|
||||
import org.lastaflute.di.core.SingletonLaContainer;
|
||||
import org.codelibs.fess.util.ComponentUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -71,13 +71,13 @@ public class CrawlingConfigHelper implements Serializable {
|
|||
}
|
||||
switch (configType) {
|
||||
case WEB:
|
||||
final WebConfigService webConfigService = SingletonLaContainer.getComponent(WebConfigService.class);
|
||||
final WebConfigService webConfigService = ComponentUtil.getComponent(WebConfigService.class);
|
||||
return webConfigService.getWebConfig(id).get();
|
||||
case FILE:
|
||||
final FileConfigService fileConfigService = SingletonLaContainer.getComponent(FileConfigService.class);
|
||||
final FileConfigService fileConfigService = ComponentUtil.getComponent(FileConfigService.class);
|
||||
return fileConfigService.getFileConfig(id).get();
|
||||
case DATA:
|
||||
final DataConfigService dataConfigService = SingletonLaContainer.getComponent(DataConfigService.class);
|
||||
final DataConfigService dataConfigService = ComponentUtil.getComponent(DataConfigService.class);
|
||||
return dataConfigService.getDataConfig(id).get();
|
||||
default:
|
||||
return null;
|
||||
|
|
|
@ -40,7 +40,6 @@ import org.elasticsearch.search.aggregations.bucket.terms.Terms;
|
|||
import org.elasticsearch.search.aggregations.bucket.terms.Terms.Bucket;
|
||||
import org.elasticsearch.search.aggregations.bucket.terms.Terms.Order;
|
||||
import org.elasticsearch.search.aggregations.bucket.terms.TermsBuilder;
|
||||
import org.lastaflute.di.core.SingletonLaContainer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -58,7 +57,7 @@ public class CrawlingInfoHelper implements Serializable {
|
|||
public int maxSessionIdsInList;
|
||||
|
||||
protected CrawlingInfoService getCrawlingInfoService() {
|
||||
return SingletonLaContainer.getComponent(CrawlingInfoService.class);
|
||||
return ComponentUtil.getComponent(CrawlingInfoService.class);
|
||||
}
|
||||
|
||||
public String getCanonicalSessionId(final String sessionId) {
|
||||
|
|
|
@ -37,7 +37,6 @@ import org.codelibs.fess.mylasta.direction.FessConfig;
|
|||
import org.codelibs.fess.util.ComponentUtil;
|
||||
import org.elasticsearch.index.query.QueryBuilder;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.lastaflute.di.core.SingletonLaContainer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -103,7 +102,7 @@ public class DataIndexHelper implements Serializable {
|
|||
|
||||
final long startTime = System.currentTimeMillis();
|
||||
|
||||
final IndexUpdateCallback indexUpdateCallback = SingletonLaContainer.getComponent(IndexUpdateCallback.class);
|
||||
final IndexUpdateCallback indexUpdateCallback = ComponentUtil.getComponent(IndexUpdateCallback.class);
|
||||
|
||||
final List<String> sessionIdList = new ArrayList<String>();
|
||||
final Map<String, String> initParamMap = new HashMap<String, String>();
|
||||
|
|
|
@ -23,7 +23,7 @@ import javax.annotation.PostConstruct;
|
|||
|
||||
import org.codelibs.fess.app.service.DuplicateHostService;
|
||||
import org.codelibs.fess.es.config.exentity.DuplicateHost;
|
||||
import org.lastaflute.di.core.SingletonLaContainer;
|
||||
import org.codelibs.fess.util.ComponentUtil;
|
||||
|
||||
public class DuplicateHostHelper implements Serializable {
|
||||
|
||||
|
@ -36,7 +36,7 @@ public class DuplicateHostHelper implements Serializable {
|
|||
if (duplicateHostList == null) {
|
||||
duplicateHostList = new ArrayList<DuplicateHost>();
|
||||
}
|
||||
final DuplicateHostService duplicateHostService = SingletonLaContainer.getComponent(DuplicateHostService.class);
|
||||
final DuplicateHostService duplicateHostService = ComponentUtil.getComponent(DuplicateHostService.class);
|
||||
duplicateHostList.addAll(duplicateHostService.getDuplicateHostList());
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,6 @@ import org.elasticsearch.index.query.QueryBuilders;
|
|||
import org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder;
|
||||
import org.elasticsearch.index.query.functionscore.ScoreFunctionBuilder;
|
||||
import org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders;
|
||||
import org.lastaflute.di.core.SingletonLaContainer;
|
||||
|
||||
public class KeyMatchHelper {
|
||||
protected volatile Map<String, Pair<QueryBuilder, ScoreFunctionBuilder>> keyMatchQueryMap = Collections.emptyMap();
|
||||
|
@ -56,7 +55,7 @@ public class KeyMatchHelper {
|
|||
|
||||
protected void reload(final long interval) {
|
||||
final FessConfig fessConfig = ComponentUtil.getFessConfig();
|
||||
final KeyMatchService keyMatchService = SingletonLaContainer.getComponent(KeyMatchService.class);
|
||||
final KeyMatchService keyMatchService = ComponentUtil.getComponent(KeyMatchService.class);
|
||||
final Map<String, Pair<QueryBuilder, ScoreFunctionBuilder>> keyMatchQueryMap = new HashMap<>();
|
||||
keyMatchService
|
||||
.getAvailableKeyMatchList()
|
||||
|
|
|
@ -32,7 +32,7 @@ import org.codelibs.core.lang.StringUtil;
|
|||
import org.codelibs.fess.Constants;
|
||||
import org.codelibs.fess.app.service.LabelTypeService;
|
||||
import org.codelibs.fess.es.config.exentity.LabelType;
|
||||
import org.lastaflute.di.core.SingletonLaContainer;
|
||||
import org.codelibs.fess.util.ComponentUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -49,7 +49,7 @@ public class LabelTypeHelper implements Serializable {
|
|||
protected volatile List<LabelTypePattern> labelTypePatternList;
|
||||
|
||||
protected LabelTypeService getLabelTypeService() {
|
||||
return SingletonLaContainer.getComponent(LabelTypeService.class);
|
||||
return ComponentUtil.getComponent(LabelTypeService.class);
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
|
|
|
@ -28,7 +28,6 @@ import org.codelibs.fess.Constants;
|
|||
import org.codelibs.fess.es.config.exbhv.PathMappingBhv;
|
||||
import org.codelibs.fess.es.config.exentity.PathMapping;
|
||||
import org.codelibs.fess.util.ComponentUtil;
|
||||
import org.lastaflute.di.core.SingletonLaContainer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -49,7 +48,7 @@ public class PathMappingHelper implements Serializable {
|
|||
ptList.add(Constants.PROCESS_TYPE_BOTH);
|
||||
|
||||
try {
|
||||
final PathMappingBhv pathMappingBhv = SingletonLaContainer.getComponent(PathMappingBhv.class);
|
||||
final PathMappingBhv pathMappingBhv = ComponentUtil.getComponent(PathMappingBhv.class);
|
||||
cachedPathMappingList = pathMappingBhv.selectList(cb -> {
|
||||
cb.query().addOrderBy_SortOrder_Asc();
|
||||
cb.query().setProcessType_InScope(ptList);
|
||||
|
|
|
@ -40,7 +40,14 @@ public class ProcessHelper {
|
|||
@PreDestroy
|
||||
public void destroy() {
|
||||
for (final String sessionId : runningProcessMap.keySet()) {
|
||||
destroyProcess(sessionId);
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Stopping process " + sessionId);
|
||||
}
|
||||
if (destroyProcess(sessionId)) {
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Stopped process " + sessionId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,16 +65,16 @@ public class ProcessHelper {
|
|||
}
|
||||
}
|
||||
|
||||
public void destroyProcess(final String sessionId) {
|
||||
public boolean destroyProcess(final String sessionId) {
|
||||
final JobProcess jobProcess = runningProcessMap.remove(sessionId);
|
||||
destroyProcess(jobProcess);
|
||||
return destroyProcess(jobProcess);
|
||||
}
|
||||
|
||||
public boolean isProcessRunning() {
|
||||
return !runningProcessMap.isEmpty();
|
||||
}
|
||||
|
||||
protected void destroyProcess(final JobProcess jobProcess) {
|
||||
protected boolean destroyProcess(final JobProcess jobProcess) {
|
||||
if (jobProcess != null) {
|
||||
final InputStreamThread ist = jobProcess.getInputStreamThread();
|
||||
try {
|
||||
|
@ -104,10 +111,12 @@ public class ProcessHelper {
|
|||
}
|
||||
try {
|
||||
process.destroy();
|
||||
return true;
|
||||
} catch (final Exception e) {
|
||||
logger.error("Could not destroy a process correctly.", e);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Set<String> getRunningSessionIdSet() {
|
||||
|
|
|
@ -51,7 +51,6 @@ import org.codelibs.fess.util.StreamUtil;
|
|||
import org.dbflute.optional.OptionalThing;
|
||||
import org.elasticsearch.action.update.UpdateRequest;
|
||||
import org.elasticsearch.script.Script;
|
||||
import org.lastaflute.di.core.SingletonLaContainer;
|
||||
import org.lastaflute.web.util.LaRequestUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -219,7 +218,7 @@ public class SearchLogHelper {
|
|||
if (!userInfoMap.isEmpty()) {
|
||||
final List<UserInfo> insertList = new ArrayList<>(userInfoMap.values());
|
||||
final List<UserInfo> updateList = new ArrayList<>();
|
||||
final UserInfoBhv userInfoBhv = SingletonLaContainer.getComponent(UserInfoBhv.class);
|
||||
final UserInfoBhv userInfoBhv = ComponentUtil.getComponent(UserInfoBhv.class);
|
||||
userInfoBhv.selectList(cb -> {
|
||||
cb.query().setId_InScope(userInfoMap.keySet());
|
||||
cb.fetchFirst(userInfoMap.size());
|
||||
|
@ -268,7 +267,7 @@ public class SearchLogHelper {
|
|||
final List<ClickLog> clickLogList = new ArrayList<>();
|
||||
for (final ClickLog clickLog : queue) {
|
||||
try {
|
||||
final SearchLogBhv searchLogBhv = SingletonLaContainer.getComponent(SearchLogBhv.class);
|
||||
final SearchLogBhv searchLogBhv = ComponentUtil.getComponent(SearchLogBhv.class);
|
||||
searchLogBhv.selectEntity(cb -> {
|
||||
cb.query().setQueryId_Equal(clickLog.getQueryId());
|
||||
}).ifPresent(entity -> {
|
||||
|
@ -290,7 +289,7 @@ public class SearchLogHelper {
|
|||
}
|
||||
if (!clickLogList.isEmpty()) {
|
||||
try {
|
||||
final ClickLogBhv clickLogBhv = SingletonLaContainer.getComponent(ClickLogBhv.class);
|
||||
final ClickLogBhv clickLogBhv = ComponentUtil.getComponent(ClickLogBhv.class);
|
||||
clickLogBhv.batchInsert(clickLogList);
|
||||
} catch (final Exception e) {
|
||||
logger.warn("Failed to insert: " + clickLogList, e);
|
||||
|
|
|
@ -62,7 +62,6 @@ import org.codelibs.fess.mylasta.direction.FessConfig;
|
|||
import org.codelibs.fess.util.ComponentUtil;
|
||||
import org.codelibs.fess.util.DocumentUtil;
|
||||
import org.codelibs.fess.util.ResourceUtil;
|
||||
import org.lastaflute.di.core.SingletonLaContainer;
|
||||
import org.lastaflute.taglib.function.LaFunctions;
|
||||
import org.lastaflute.web.response.StreamResponse;
|
||||
import org.lastaflute.web.util.LaRequestUtil;
|
||||
|
@ -502,20 +501,20 @@ public class ViewHelper implements Serializable {
|
|||
logger.debug("configType: " + configType + ", configId: " + configId);
|
||||
}
|
||||
if (ConfigType.WEB == configType) {
|
||||
final WebConfigService webConfigService = SingletonLaContainer.getComponent(WebConfigService.class);
|
||||
final WebConfigService webConfigService = ComponentUtil.getComponent(WebConfigService.class);
|
||||
config = webConfigService.getWebConfig(crawlingConfigHelper.getId(configId)).get();
|
||||
} else if (ConfigType.FILE == configType) {
|
||||
final FileConfigService fileConfigService = SingletonLaContainer.getComponent(FileConfigService.class);
|
||||
final FileConfigService fileConfigService = ComponentUtil.getComponent(FileConfigService.class);
|
||||
config = fileConfigService.getFileConfig(crawlingConfigHelper.getId(configId)).get();
|
||||
} else if (ConfigType.DATA == configType) {
|
||||
final DataConfigService dataConfigService = SingletonLaContainer.getComponent(DataConfigService.class);
|
||||
final DataConfigService dataConfigService = ComponentUtil.getComponent(DataConfigService.class);
|
||||
config = dataConfigService.getDataConfig(crawlingConfigHelper.getId(configId)).get();
|
||||
}
|
||||
if (config == null) {
|
||||
throw new FessSystemException("No crawlingConfig: " + configId);
|
||||
}
|
||||
final String url = DocumentUtil.getValue(doc, fessConfig.getIndexFieldUrl(), String.class);
|
||||
final CrawlerClientFactory crawlerClientFactory = SingletonLaContainer.getComponent(CrawlerClientFactory.class);
|
||||
final CrawlerClientFactory crawlerClientFactory = ComponentUtil.getComponent(CrawlerClientFactory.class);
|
||||
config.initializeClientFactory(crawlerClientFactory);
|
||||
final CrawlerClient client = crawlerClientFactory.getClient(url);
|
||||
if (client == null) {
|
||||
|
|
|
@ -41,7 +41,6 @@ import org.codelibs.fess.es.config.exentity.WebConfig;
|
|||
import org.codelibs.fess.indexer.IndexUpdater;
|
||||
import org.codelibs.fess.mylasta.direction.FessConfig;
|
||||
import org.codelibs.fess.util.ComponentUtil;
|
||||
import org.lastaflute.di.core.SingletonLaContainer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -147,7 +146,7 @@ public class WebFsIndexHelper implements Serializable {
|
|||
final String sid = crawlingConfigHelper.store(sessionId, webConfig);
|
||||
|
||||
// create crawler
|
||||
final Crawler crawler = SingletonLaContainer.getComponent(Crawler.class);
|
||||
final Crawler crawler = ComponentUtil.getComponent(Crawler.class);
|
||||
crawler.setSessionId(sid);
|
||||
sessionIdList.add(sid);
|
||||
|
||||
|
@ -251,7 +250,7 @@ public class WebFsIndexHelper implements Serializable {
|
|||
final String sid = crawlingConfigHelper.store(sessionId, fileConfig);
|
||||
|
||||
// create crawler
|
||||
final Crawler crawler = SingletonLaContainer.getComponent(Crawler.class);
|
||||
final Crawler crawler = ComponentUtil.getComponent(Crawler.class);
|
||||
crawler.setSessionId(sid);
|
||||
sessionIdList.add(sid);
|
||||
|
||||
|
@ -469,9 +468,13 @@ public class WebFsIndexHelper implements Serializable {
|
|||
crawlingInfoHelper.putToInfoMap(Constants.WEB_FS_INDEX_EXEC_TIME, Long.toString(indexUpdater.getExecuteTime()));
|
||||
crawlingInfoHelper.putToInfoMap(Constants.WEB_FS_INDEX_SIZE, Long.toString(indexUpdater.getDocumentSize()));
|
||||
|
||||
final EsUrlFilterService urlFilterService = SingletonLaContainer.getComponent(EsUrlFilterService.class);
|
||||
final EsUrlQueueService urlQueueService = SingletonLaContainer.getComponent(EsUrlQueueService.class);
|
||||
final EsDataService dataService = SingletonLaContainer.getComponent(EsDataService.class);
|
||||
if (systemHelper.isForceStop()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final EsUrlFilterService urlFilterService = ComponentUtil.getComponent(EsUrlFilterService.class);
|
||||
final EsUrlQueueService urlQueueService = ComponentUtil.getComponent(EsUrlQueueService.class);
|
||||
final EsDataService dataService = ComponentUtil.getComponent(EsDataService.class);
|
||||
for (final String sid : sessionIdList) {
|
||||
// remove config
|
||||
crawlingConfigHelper.remove(sid);
|
||||
|
|
|
@ -21,6 +21,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import javax.annotation.PreDestroy;
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.codelibs.core.lang.StringUtil;
|
||||
|
@ -50,7 +51,6 @@ import org.elasticsearch.action.search.SearchRequestBuilder;
|
|||
import org.elasticsearch.index.query.QueryBuilder;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.search.sort.SortOrder;
|
||||
import org.lastaflute.di.core.SingletonLaContainer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -105,6 +105,16 @@ public class IndexUpdater extends Thread {
|
|||
// nothing
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
public void destroy() {
|
||||
if (!finishCrawling) {
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Stopping all crawler.");
|
||||
}
|
||||
forceStop();
|
||||
}
|
||||
}
|
||||
|
||||
public void addFinishedSessionId(final String sessionId) {
|
||||
synchronized (finishedSessionIdList) {
|
||||
finishedSessionIdList.add(sessionId);
|
||||
|
@ -251,13 +261,23 @@ public class IndexUpdater extends Thread {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
if (!ComponentUtil.available()) {
|
||||
logger.info("IndexUpdater is terminated.");
|
||||
forceStop();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Finished indexUpdater.");
|
||||
}
|
||||
} catch (final Throwable t) {
|
||||
logger.error("IndexUpdater is terminated.", t);
|
||||
if (ComponentUtil.available()) {
|
||||
logger.error("IndexUpdater is terminated.", t);
|
||||
} else if (logger.isInfoEnabled()) {
|
||||
logger.info("IndexUpdater is terminated.");
|
||||
}
|
||||
forceStop();
|
||||
} finally {
|
||||
intervalControlHelper.setCrawlerRunning(true);
|
||||
|
@ -303,7 +323,7 @@ public class IndexUpdater extends Thread {
|
|||
if (accessResultData != null) {
|
||||
accessResult.setAccessResultData(null);
|
||||
try {
|
||||
final Transformer transformer = SingletonLaContainer.getComponent(accessResultData.getTransformerName());
|
||||
final Transformer transformer = ComponentUtil.getComponent(accessResultData.getTransformerName());
|
||||
if (transformer == null) {
|
||||
// no transformer
|
||||
logger.warn("No transformer: " + accessResultData.getTransformerName());
|
||||
|
|
|
@ -37,7 +37,6 @@ import org.codelibs.fess.util.ComponentUtil;
|
|||
import org.codelibs.fess.util.InputStreamThread;
|
||||
import org.codelibs.fess.util.JobProcess;
|
||||
import org.codelibs.fess.util.StreamUtil;
|
||||
import org.lastaflute.di.core.SingletonLaContainer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -121,7 +120,7 @@ public class SuggestJob {
|
|||
protected void executeSuggestCreator() {
|
||||
final List<String> cmdList = new ArrayList<>();
|
||||
final String cpSeparator = SystemUtils.IS_OS_WINDOWS ? ";" : ":";
|
||||
final ServletContext servletContext = SingletonLaContainer.getComponent(ServletContext.class);
|
||||
final ServletContext servletContext = ComponentUtil.getComponent(ServletContext.class);
|
||||
final ProcessHelper processHelper = ComponentUtil.getJobHelper();
|
||||
final FessConfig fessConfig = ComponentUtil.getFessConfig();
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ import org.codelibs.fess.crawler.service.DataService;
|
|||
import org.codelibs.fess.dict.DictionaryManager;
|
||||
import org.codelibs.fess.ds.DataStoreFactory;
|
||||
import org.codelibs.fess.es.client.FessEsClient;
|
||||
import org.codelibs.fess.exception.ContainerNotAvailableException;
|
||||
import org.codelibs.fess.helper.ActivityHelper;
|
||||
import org.codelibs.fess.helper.CrawlingConfigHelper;
|
||||
import org.codelibs.fess.helper.CrawlingInfoHelper;
|
||||
|
@ -54,6 +55,7 @@ import org.codelibs.fess.mylasta.direction.FessConfig;
|
|||
import org.lastaflute.core.message.MessageManager;
|
||||
import org.lastaflute.di.core.SingletonLaContainer;
|
||||
import org.lastaflute.di.core.factory.SingletonLaContainerFactory;
|
||||
import org.lastaflute.di.core.smart.hot.HotdeployUtil;
|
||||
import org.lastaflute.job.JobManager;
|
||||
import org.lastaflute.web.servlet.request.RequestManager;
|
||||
|
||||
|
@ -134,6 +136,12 @@ public final class ComponentUtil {
|
|||
|
||||
private static final String ELASTICSEARCH_CLIENT = FESS_ES_CLIENT;
|
||||
|
||||
private static IndexingHelper indexingHelper;
|
||||
|
||||
private static CrawlingConfigHelper crawlingConfigHelper;
|
||||
|
||||
private static SystemHelper systemHelper;
|
||||
|
||||
private ComponentUtil() {
|
||||
}
|
||||
|
||||
|
@ -154,7 +162,10 @@ public final class ComponentUtil {
|
|||
}
|
||||
|
||||
public static SystemHelper getSystemHelper() {
|
||||
return SingletonLaContainer.getComponent(SYSTEM_HELPER);
|
||||
if (systemHelper == null || HotdeployUtil.isHotdeploy()) {
|
||||
systemHelper = SingletonLaContainer.getComponent(SYSTEM_HELPER);
|
||||
}
|
||||
return systemHelper;
|
||||
}
|
||||
|
||||
public static ViewHelper getViewHelper() {
|
||||
|
@ -178,7 +189,10 @@ public final class ComponentUtil {
|
|||
}
|
||||
|
||||
public static CrawlingConfigHelper getCrawlingConfigHelper() {
|
||||
return SingletonLaContainer.getComponent(CRAWLING_CONFIG_HELPER);
|
||||
if (crawlingConfigHelper == null || HotdeployUtil.isHotdeploy()) {
|
||||
crawlingConfigHelper = SingletonLaContainer.getComponent(CRAWLING_CONFIG_HELPER);
|
||||
}
|
||||
return crawlingConfigHelper;
|
||||
}
|
||||
|
||||
public static CrawlingInfoHelper getCrawlingInfoHelper() {
|
||||
|
@ -242,7 +256,10 @@ public final class ComponentUtil {
|
|||
}
|
||||
|
||||
public static IndexingHelper getIndexingHelper() {
|
||||
return SingletonLaContainer.getComponent(INDEXING_HELPER);
|
||||
if (indexingHelper == null || HotdeployUtil.isHotdeploy()) {
|
||||
indexingHelper = SingletonLaContainer.getComponent(INDEXING_HELPER);
|
||||
}
|
||||
return indexingHelper;
|
||||
}
|
||||
|
||||
public static UserInfoHelper getUserInfoHelper() {
|
||||
|
@ -306,11 +323,32 @@ public final class ComponentUtil {
|
|||
}
|
||||
|
||||
public static <T> T getComponent(final Class<T> clazz) {
|
||||
return SingletonLaContainer.getComponent(clazz);
|
||||
try {
|
||||
return SingletonLaContainer.getComponent(clazz);
|
||||
} catch (NullPointerException e) {
|
||||
throw new ContainerNotAvailableException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> T getComponent(final String componentName) {
|
||||
try {
|
||||
return SingletonLaContainer.getComponent(componentName);
|
||||
} catch (NullPointerException e) {
|
||||
throw new ContainerNotAvailableException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean hasQueryHelper() {
|
||||
return SingletonLaContainerFactory.getContainer().hasComponentDef(QUERY_HELPER);
|
||||
}
|
||||
|
||||
public static boolean available() {
|
||||
try {
|
||||
return SingletonLaContainer.getComponent(SYSTEM_HELPER) != null;
|
||||
} catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -28,7 +28,6 @@ import javax.servlet.ServletContext;
|
|||
import org.codelibs.core.lang.StringUtil;
|
||||
import org.codelibs.fess.Constants;
|
||||
import org.codelibs.fess.mylasta.direction.FessConfig;
|
||||
import org.lastaflute.di.core.SingletonLaContainer;
|
||||
import org.lastaflute.web.util.LaServletContextUtil;
|
||||
|
||||
public class ResourceUtil {
|
||||
|
@ -76,7 +75,7 @@ public class ResourceUtil {
|
|||
protected static Path getPath(final String base, final String... names) {
|
||||
|
||||
try {
|
||||
final ServletContext servletContext = SingletonLaContainer.getComponent(ServletContext.class);
|
||||
final ServletContext servletContext = ComponentUtil.getComponent(ServletContext.class);
|
||||
final String webinfPath = servletContext.getRealPath("/WEB-INF/" + base);
|
||||
if (webinfPath != null) {
|
||||
if (Files.exists(Paths.get(webinfPath))) {
|
||||
|
|
Loading…
Add table
Reference in a new issue