fix #2799 Refactor to centralize current time retrieval using systemHelper.getCurrentTimeAsLong()

This commit is contained in:
Shinsuke Sugaya 2024-01-21 14:18:15 +09:00
parent b133ef5ca8
commit 633789fd78
27 changed files with 114 additions and 82 deletions

View file

@ -66,7 +66,7 @@ public class AllJobScheduler implements LaJobScheduler {
@Override
public void schedule(final LaCron cron) {
schedulerTime = System.currentTimeMillis();
schedulerTime = systemHelper.getCurrentTimeAsLong();
scheduledJobService.start(cron);
final String myName = fessConfig.getSchedulerTargetName();
@ -81,7 +81,7 @@ public class AllJobScheduler implements LaJobScheduler {
if (logger.isDebugEnabled()) {
logger.debug("Updating scheduled jobs. time:{}", schedulerTime);
}
final long now = System.currentTimeMillis();
final long now = systemHelper.getCurrentTimeAsLong();
scheduledJobService.getScheduledJobListAfter(schedulerTime).forEach(scheduledJob -> {
if (logger.isDebugEnabled()) {
logger.debug("Updating job schedule:{}", scheduledJob.getName());

View file

@ -104,15 +104,16 @@ public class AdminEsreqAction extends FessAdminAction {
}
throw e1;
}
return asStream("es_" + System.currentTimeMillis() + ".json").contentTypeOctetStream().stream(out -> {
try (final InputStream in = new FileInputStream(tempFile)) {
out.write(in);
} finally {
if (tempFile.exists() && !tempFile.delete()) {
logger.warn("Failed to delete {}", tempFile.getAbsolutePath());
}
}
});
return asStream("es_" + ComponentUtil.getSystemHelper().getCurrentTimeAsLong() + ".json").contentTypeOctetStream()
.stream(out -> {
try (final InputStream in = new FileInputStream(tempFile)) {
out.write(in);
} finally {
if (tempFile.exists() && !tempFile.delete()) {
logger.warn("Failed to delete {}", tempFile.getAbsolutePath());
}
}
});
} catch (final Exception e) {
logger.warn("Failed to process request file: {}", form.requestFile.getFileName(), e);
throwValidationError(messages -> messages.addErrorsInvalidHeaderForRequestFile(GLOBAL, e.getMessage()),

View file

@ -116,7 +116,7 @@ public class AzureAdCredential implements LoginCredential, FessCredential {
@Override
public boolean refresh() {
if (authResult.getExpiresAfter() < System.currentTimeMillis()) {
if (authResult.getExpiresAfter() < ComponentUtil.getSystemHelper().getCurrentTimeAsLong()) {
return false;
}
final AzureAdAuthenticator authenticator = ComponentUtil.getComponent(AzureAdAuthenticator.class);

View file

@ -53,6 +53,7 @@ import org.codelibs.fess.helper.CrawlingInfoHelper;
import org.codelibs.fess.helper.DuplicateHostHelper;
import org.codelibs.fess.helper.IndexingHelper;
import org.codelibs.fess.helper.PermissionHelper;
import org.codelibs.fess.helper.SystemHelper;
import org.codelibs.fess.mylasta.direction.FessConfig;
import org.codelibs.fess.util.ComponentUtil;
import org.codelibs.fess.util.DocumentUtil;
@ -69,7 +70,8 @@ public class FessCrawlerThread extends CrawlerThread {
protected boolean isContentUpdated(final CrawlerClient client, final UrlQueue<?> urlQueue) {
if (ComponentUtil.getFessConfig().isIncrementalCrawling()) {
final long startTime = System.currentTimeMillis();
final SystemHelper systemHelper = ComponentUtil.getSystemHelper();
final long startTime = systemHelper.getCurrentTimeAsLong();
final FessConfig fessConfig = ComponentUtil.getFessConfig();
final CrawlingConfigHelper crawlingConfigHelper = ComponentUtil.getCrawlingConfigHelper();
@ -119,7 +121,7 @@ public class FessCrawlerThread extends CrawlerThread {
}
final Date expires = DocumentUtil.getValue(document, fessConfig.getIndexFieldExpires(), Date.class);
if (expires != null && expires.getTime() < System.currentTimeMillis()) {
if (expires != null && expires.getTime() < systemHelper.getCurrentTimeAsLong()) {
final Object idValue = document.get(fessConfig.getIndexFieldId());
if (idValue != null && !indexingHelper.deleteDocument(searchEngineClient, idValue.toString())) {
logger.debug("Failed to delete expired document: {}", url);
@ -160,7 +162,7 @@ public class FessCrawlerThread extends CrawlerThread {
log(logHelper, LogType.NOT_MODIFIED, crawlerContext, urlQueue);
responseData.setExecutionTime(System.currentTimeMillis() - startTime);
responseData.setExecutionTime(systemHelper.getCurrentTimeAsLong() - startTime);
responseData.setParentUrl(urlQueue.getParentUrl());
responseData.setSessionId(crawlerContext.getSessionId());
responseData.setHttpStatusCode(org.codelibs.fess.crawler.Constants.NOT_MODIFIED_STATUS);

View file

@ -37,6 +37,7 @@ import org.apache.logging.log4j.Logger;
import org.codelibs.core.lang.StringUtil;
import org.codelibs.fess.Constants;
import org.codelibs.fess.helper.PluginHelper;
import org.codelibs.fess.util.ComponentUtil;
import org.codelibs.fess.util.ResourceUtil;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
@ -71,7 +72,7 @@ public class DataStoreFactory {
}
public String[] getDataStoreNames() {
final long now = System.currentTimeMillis();
final long now = ComponentUtil.getSystemHelper().getCurrentTimeAsLong();
if (now - lastLoadedTime > 60000L) {
final List<String> nameList = loadDataStoreNameList();
dataStoreNames = nameList.toArray(n -> new String[nameList.size()]);

View file

@ -54,6 +54,7 @@ import org.codelibs.fess.helper.CrawlerStatsHelper;
import org.codelibs.fess.helper.CrawlerStatsHelper.StatsAction;
import org.codelibs.fess.helper.CrawlerStatsHelper.StatsKeyObject;
import org.codelibs.fess.helper.IndexingHelper;
import org.codelibs.fess.helper.SystemHelper;
import org.codelibs.fess.mylasta.direction.FessConfig;
import org.codelibs.fess.util.ComponentUtil;
import org.lastaflute.di.core.SingletonLaContainer;
@ -212,14 +213,15 @@ public class FileListIndexUpdateCallbackImpl implements IndexUpdateCallback {
protected String processRequest(final DataStoreParams paramMap, final Map<String, Object> dataMap, final String url,
final CrawlerClient client) {
final long startTime = System.currentTimeMillis();
final SystemHelper systemHelper = ComponentUtil.getSystemHelper();
final long startTime = systemHelper.getCurrentTimeAsLong();
final CrawlerStatsHelper crawlerStatsHelper = ComponentUtil.getCrawlerStatsHelper();
final StatsKeyObject keyObj = paramMap.get(Constants.CRAWLER_STATS_KEY) instanceof final StatsKeyObject sko ? sko : null;
try (final ResponseData responseData = client.execute(RequestDataBuilder.newRequestData().get().url(url).build())) {
if (responseData.getRedirectLocation() != null) {
return responseData.getRedirectLocation();
}
responseData.setExecutionTime(System.currentTimeMillis() - startTime);
responseData.setExecutionTime(systemHelper.getCurrentTimeAsLong() - startTime);
if (dataMap.containsKey(Constants.SESSION_ID)) {
responseData.setSessionId((String) dataMap.get(Constants.SESSION_ID));
} else {

View file

@ -75,7 +75,7 @@ public class IndexUpdateCallbackImpl implements IndexUpdateCallback {
final SystemHelper systemHelper = ComponentUtil.getSystemHelper();
systemHelper.calibrateCpuLoad();
final long startTime = System.currentTimeMillis();
final long startTime = systemHelper.getCurrentTimeAsLong();
final FessConfig fessConfig = ComponentUtil.getFessConfig();
final SearchEngineClient searchEngineClient = ComponentUtil.getSearchEngineClient();
@ -122,7 +122,7 @@ public class IndexUpdateCallbackImpl implements IndexUpdateCallback {
docList.add(ingest(paramMap, dataMap));
final long contentSize = indexingHelper.calculateDocumentSize(dataMap);
docList.addContentSize(contentSize);
final long processingTime = System.currentTimeMillis() - startTime;
final long processingTime = systemHelper.getCurrentTimeAsLong() - startTime;
docList.addProcessingTime(processingTime);
if (logger.isDebugEnabled()) {
logger.debug("Added the document({}, {}ms). The number of a document cache is {}.",

View file

@ -69,6 +69,7 @@ import org.codelibs.fess.exception.ResultOffsetExceededException;
import org.codelibs.fess.exception.SearchQueryException;
import org.codelibs.fess.helper.DocumentHelper;
import org.codelibs.fess.helper.QueryHelper;
import org.codelibs.fess.helper.SystemHelper;
import org.codelibs.fess.mylasta.direction.FessConfig;
import org.codelibs.fess.query.QueryFieldConfig;
import org.codelibs.fess.util.BooleanFunction;
@ -755,7 +756,8 @@ public class SearchEngineClient implements Client {
protected void waitForYellowStatus(final FessConfig fessConfig) {
Exception cause = null;
final long startTime = System.currentTimeMillis();
final SystemHelper systemHelper = ComponentUtil.getSystemHelper();
final long startTime = systemHelper.getCurrentTimeAsLong();
for (int i = 0; i < maxEsStatusRetry; i++) {
try {
final ClusterHealthResponse response = client.admin().cluster().prepareHealth().setWaitForYellowStatus().execute()
@ -784,7 +786,7 @@ public class SearchEngineClient implements Client {
}
final String message =
"Fesen (" + SystemUtil.getSearchEngineHttpAddress() + ") is not available. Check the state of your Fesen cluster ("
+ clusterName + ") in " + (System.currentTimeMillis() - startTime) + "ms.";
+ clusterName + ") in " + (systemHelper.getCurrentTimeAsLong() - startTime) + "ms.";
throw new ContainerInitFailureException(message, cause);
}
@ -924,21 +926,23 @@ public class SearchEngineClient implements Client {
protected <T> T get(final String index, final String id, final SearchCondition<GetRequestBuilder> condition,
final SearchResult<T, GetRequestBuilder, GetResponse> searchResult) {
final long startTime = System.currentTimeMillis();
final SystemHelper systemHelper = ComponentUtil.getSystemHelper();
final long startTime = systemHelper.getCurrentTimeAsLong();
GetResponse response = null;
final GetRequestBuilder requestBuilder = client.prepareGet(index, id);
if (condition.build(requestBuilder)) {
response = requestBuilder.execute().actionGet(ComponentUtil.getFessConfig().getIndexSearchTimeout());
}
final long execTime = System.currentTimeMillis() - startTime;
final long execTime = systemHelper.getCurrentTimeAsLong() - startTime;
return searchResult.build(requestBuilder, execTime, OptionalEntity.ofNullable(response, () -> {}));
}
public <T> T search(final String index, final SearchCondition<SearchRequestBuilder> condition,
final SearchResult<T, SearchRequestBuilder, SearchResponse> searchResult) {
final long startTime = System.currentTimeMillis();
final SystemHelper systemHelper = ComponentUtil.getSystemHelper();
final long startTime = systemHelper.getCurrentTimeAsLong();
SearchResponse searchResponse = null;
final SearchRequestBuilder searchRequestBuilder = client.prepareSearch(index);
@ -966,7 +970,7 @@ public class SearchEngineClient implements Client {
"Failed query: " + searchRequestBuilder, e);
}
}
final long execTime = System.currentTimeMillis() - startTime;
final long execTime = systemHelper.getCurrentTimeAsLong() - startTime;
return searchResult.build(searchRequestBuilder, execTime, OptionalEntity.ofNullable(searchResponse, () -> {}));
}

View file

@ -56,6 +56,7 @@ import org.codelibs.fess.helper.DataIndexHelper;
import org.codelibs.fess.helper.DuplicateHostHelper;
import org.codelibs.fess.helper.NotificationHelper;
import org.codelibs.fess.helper.PathMappingHelper;
import org.codelibs.fess.helper.SystemHelper;
import org.codelibs.fess.helper.WebFsIndexHelper;
import org.codelibs.fess.mylasta.direction.FessConfig;
import org.codelibs.fess.mylasta.mail.CrawlerPostcard;
@ -471,8 +472,8 @@ public class Crawler {
}
final PathMappingHelper pathMappingHelper = ComponentUtil.getPathMappingHelper();
final long totalTime = System.currentTimeMillis();
final SystemHelper systemHelper = ComponentUtil.getSystemHelper();
final long totalTime = systemHelper.getCurrentTimeAsLong();
final CrawlingInfoHelper crawlingInfoHelper = ComponentUtil.getCrawlingInfoHelper();
@ -494,8 +495,8 @@ public class Crawler {
}
// delete expired sessions
crawlingInfoService.deleteSessionIdsBefore(options.sessionId, options.name,
ComponentUtil.getSystemHelper().getCurrentTimeAsLong());
SystemHelper systemHelper2 = ComponentUtil.getSystemHelper();
crawlingInfoService.deleteSessionIdsBefore(options.sessionId, options.name, systemHelper2.getCurrentTimeAsLong());
final List<String> webConfigIdList = options.getWebConfigIdList();
final List<String> fileConfigIdList = options.getFileConfigIdList();
@ -544,7 +545,7 @@ public class Crawler {
errors.stream().map(s -> s.replace(" ", StringUtil.EMPTY)).collect(Collectors.joining(" ")));
}
writeTimeToSessionInfo(crawlingInfoHelper, Constants.CRAWLER_END_TIME);
crawlingInfoHelper.putToInfoMap(Constants.CRAWLER_EXEC_TIME, Long.toString(System.currentTimeMillis() - totalTime));
crawlingInfoHelper.putToInfoMap(Constants.CRAWLER_EXEC_TIME, Long.toString(systemHelper.getCurrentTimeAsLong() - totalTime));
}
}

View file

@ -28,6 +28,7 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.codelibs.fess.crawler.entity.UrlQueue;
import org.codelibs.fess.taglib.FessFunctions;
import org.codelibs.fess.util.ComponentUtil;
import org.dbflute.optional.OptionalThing;
import com.google.common.cache.CacheBuilder;
@ -85,7 +86,7 @@ public class CrawlerStatsHelper {
try {
statsCache.get(key);
} catch (final Exception e) {
final StringBuilder buf = createStringBuffer(keyObj, System.currentTimeMillis());
final StringBuilder buf = createStringBuffer(keyObj, getCurrentTimeMillis());
buf.append('\t').append("action:begin");
buf.append('\t').append("error:").append(escapeValue(e.getLocalizedMessage()).replaceAll("\\s", " "));
log(buf);
@ -102,10 +103,10 @@ public class CrawlerStatsHelper {
try {
final StatsObject data = statsCache.getIfPresent(key);
if (data != null) {
data.put(escapeValue(action), System.currentTimeMillis());
data.put(escapeValue(action), getCurrentTimeMillis());
}
} catch (final Exception e) {
final StringBuilder buf = createStringBuffer(keyObj, System.currentTimeMillis());
final StringBuilder buf = createStringBuffer(keyObj, getCurrentTimeMillis());
buf.append('\t').append("action:record");
buf.append('\t').append("error:").append(escapeValue(e.getLocalizedMessage()).replaceAll("\\s", " "));
log(buf);
@ -125,7 +126,7 @@ public class CrawlerStatsHelper {
}
}
} catch (final Exception e) {
final StringBuilder buf = createStringBuffer(keyObj, System.currentTimeMillis());
final StringBuilder buf = createStringBuffer(keyObj, getCurrentTimeMillis());
buf.append('\t').append("action:done");
buf.append('\t').append("error:").append(escapeValue(e.getLocalizedMessage()).replaceAll("\\s", " "));
log(buf);
@ -141,7 +142,7 @@ public class CrawlerStatsHelper {
statsCache.invalidate(key);
}
} catch (final Exception e) {
final StringBuilder buf = createStringBuffer(keyObj, System.currentTimeMillis());
final StringBuilder buf = createStringBuffer(keyObj, getCurrentTimeMillis());
buf.append('\t').append("action:done");
buf.append('\t').append("error:").append(escapeValue(e.getLocalizedMessage()).replaceAll("\\s", " "));
log(buf);
@ -152,7 +153,7 @@ public class CrawlerStatsHelper {
protected void printStats(final Object keyObj, final StatsObject data, final long begin, final boolean done) {
final StringBuilder buf = createStringBuffer(keyObj, begin);
if (done) {
buf.append('\t').append("done:").append(System.currentTimeMillis() - begin);
buf.append('\t').append("done:").append(getCurrentTimeMillis() - begin);
}
data.entrySet().stream().map(e -> escapeValue(e.getKey()) + ":" + (e.getValue().longValue() - begin)).map(s -> "\t" + s)
.forEach(s -> buf.append(s));
@ -167,7 +168,7 @@ public class CrawlerStatsHelper {
data.increment();
}
} catch (final Exception e) {
final StringBuilder buf = createStringBuffer(keyObj, System.currentTimeMillis());
final StringBuilder buf = createStringBuffer(keyObj, getCurrentTimeMillis());
buf.append('\t').append("action:record");
buf.append('\t').append("error:").append(escapeValue(e.getLocalizedMessage()).replaceAll("\\s", " "));
log(buf);
@ -175,6 +176,10 @@ public class CrawlerStatsHelper {
});
}
protected long getCurrentTimeMillis() {
return ComponentUtil.getSystemHelper().getCurrentTimeAsLong();
}
private StringBuilder createStringBuffer(final Object keyObj, final long time) {
final StringBuilder buf = new StringBuilder(1000);
buf.append("url:").append(getUrl(keyObj));
@ -267,7 +272,7 @@ public class CrawlerStatsHelper {
protected final AtomicInteger count;
public StatsObject() {
put(BEGIN_KEY, System.currentTimeMillis());
put(BEGIN_KEY, ComponentUtil.getSystemHelper().getCurrentTimeAsLong());
count = new AtomicInteger(1);
}

View file

@ -82,7 +82,8 @@ public class DataIndexHelper {
protected void doCrawl(final String sessionId, final List<DataConfig> configList) {
final int multiprocessCrawlingCount = ComponentUtil.getFessConfig().getCrawlingThreadCount();
final long startTime = System.currentTimeMillis();
final SystemHelper systemHelper = ComponentUtil.getSystemHelper();
final long startTime = systemHelper.getCurrentTimeAsLong();
final IndexUpdateCallback indexUpdateCallback = ComponentUtil.getComponent(IndexUpdateCallback.class);
@ -107,8 +108,6 @@ public class DataIndexHelper {
}
final SystemHelper systemHelper = ComponentUtil.getSystemHelper();
int startedCrawlerNum = 0;
int activeCrawlerNum = 0;
while (startedCrawlerNum < dataCrawlingThreadList.size()) {
@ -160,7 +159,7 @@ public class DataIndexHelper {
// put cralwing info
final CrawlingInfoHelper crawlingInfoHelper = ComponentUtil.getCrawlingInfoHelper();
final long execTime = System.currentTimeMillis() - startTime;
final long execTime = systemHelper.getCurrentTimeAsLong() - startTime;
crawlingInfoHelper.putToInfoMap(Constants.DATA_CRAWLING_EXEC_TIME, Long.toString(execTime));
if (logger.isInfoEnabled()) {
logger.info("[EXEC TIME] crawling time: {}ms", execTime);

View file

@ -184,14 +184,15 @@ public class DocumentHelper {
throw new CrawlingAccessException("CrawlerClient is null for " + url);
}
final long startTime = System.currentTimeMillis();
final SystemHelper systemHelper = ComponentUtil.getSystemHelper();
final long startTime = systemHelper.getCurrentTimeAsLong();
try (final ResponseData responseData = client.execute(RequestDataBuilder.newRequestData().get().url(url).build())) {
if (responseData.getRedirectLocation() != null) {
final Set<RequestData> childUrlList = new HashSet<>();
childUrlList.add(RequestDataBuilder.newRequestData().get().url(responseData.getRedirectLocation()).build());
throw new ChildUrlsException(childUrlList, this.getClass().getName() + "#RedirectedFrom:" + url);
}
responseData.setExecutionTime(System.currentTimeMillis() - startTime);
responseData.setExecutionTime(systemHelper.getCurrentTimeAsLong() - startTime);
responseData.setSessionId(crawlingInfoId);
final RuleManager ruleManager = SingletonLaContainer.getComponent(RuleManager.class);

View file

@ -47,7 +47,8 @@ public class IndexingHelper {
return;
}
final FessConfig fessConfig = ComponentUtil.getFessConfig();
final long execTime = System.currentTimeMillis();
final SystemHelper systemHelper = ComponentUtil.getSystemHelper();
final long execTime = systemHelper.getCurrentTimeAsLong();
if (logger.isDebugEnabled()) {
logger.debug("Sending {} documents to a server.", docList.size());
}
@ -79,10 +80,10 @@ public class IndexingHelper {
if (logger.isInfoEnabled()) {
if (docList.getContentSize() > 0) {
logger.info("Sent {} docs (Doc:{process {}ms, send {}ms, size {}}, {})", docList.size(), docList.getProcessingTime(),
(System.currentTimeMillis() - execTime), MemoryUtil.byteCountToDisplaySize(docList.getContentSize()),
(systemHelper.getCurrentTimeAsLong() - execTime), MemoryUtil.byteCountToDisplaySize(docList.getContentSize()),
MemoryUtil.getMemoryUsageLog());
} else {
logger.info("Sent {} docs (Doc:{send {}ms}, {})", docList.size(), (System.currentTimeMillis() - execTime),
logger.info("Sent {} docs (Doc:{send {}ms}, {})", docList.size(), (systemHelper.getCurrentTimeAsLong() - execTime),
MemoryUtil.getMemoryUsageLog());
}
}

View file

@ -21,6 +21,7 @@ import java.util.List;
import org.codelibs.core.lang.ThreadUtil;
import org.codelibs.fess.exception.FessSystemException;
import org.codelibs.fess.util.ComponentUtil;
public class IntervalControlHelper {
@ -61,7 +62,7 @@ public class IntervalControlHelper {
protected Calendar getCurrentCal() {
final Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(System.currentTimeMillis());
cal.setTimeInMillis(ComponentUtil.getSystemHelper().getCurrentTimeAsLong());
return cal;
}

View file

@ -76,8 +76,9 @@ public class SearchHelper {
// ==============
public void search(final SearchRequestParams params, final SearchRenderData data, final OptionalThing<FessUserBean> userBean) {
final long requestedTime = ComponentUtil.getSystemHelper().getCurrentTimeAsLong();
final long startTime = System.currentTimeMillis();
final SystemHelper systemHelper = ComponentUtil.getSystemHelper();
final long startTime = systemHelper.getCurrentTimeAsLong();
final long requestedTime = startTime;
LaRequestUtil.getOptionalRequest().ifPresent(request -> {
request.setAttribute(Constants.REQUEST_LANGUAGES, params.getLanguages());
@ -112,7 +113,7 @@ public class SearchHelper {
data.setAppendHighlightParams(buf.toString());
}
queryResponseList.setExecTime(System.currentTimeMillis() - startTime);
queryResponseList.setExecTime(systemHelper.getCurrentTimeAsLong() - startTime);
final NumberFormat nf = NumberFormat.getInstance(params.getLocale());
nf.setMaximumIntegerDigits(2);
nf.setMaximumFractionDigits(2);

View file

@ -224,8 +224,8 @@ public class SuggestHelper {
reader.setLimitOfDocumentSize(fessConfig.getSuggestUpdateContentsLimitDocSizeAsInteger());
final List<FunctionScoreQueryBuilder.FilterFunctionBuilder> flist = new ArrayList<>();
flist.add(new FunctionScoreQueryBuilder.FilterFunctionBuilder(
ScoreFunctionBuilders.randomFunction().seed(System.currentTimeMillis()).setField(fessConfig.getIndexFieldDocId())));
flist.add(new FunctionScoreQueryBuilder.FilterFunctionBuilder(ScoreFunctionBuilders.randomFunction()
.seed(ComponentUtil.getSystemHelper().getCurrentTimeAsLong()).setField(fessConfig.getIndexFieldDocId())));
reader.setQuery(QueryBuilders
.functionScoreQuery(QueryBuilders.matchAllQuery(),
flist.toArray(new FunctionScoreQueryBuilder.FilterFunctionBuilder[flist.size()]))

View file

@ -640,7 +640,7 @@ public class SystemHelper {
}
protected short getSystemCpuPercent() {
final long now = System.currentTimeMillis();
final long now = getCurrentTimeAsLong();
if (now - systemCpuCheckTime > systemCpuCheckInterval) {
synchronized (this) {
if (now - systemCpuCheckTime > systemCpuCheckInterval) {

View file

@ -94,7 +94,7 @@ public class WebFsIndexHelper {
final SystemHelper systemHelper = ComponentUtil.getSystemHelper();
final FessConfig fessConfig = ComponentUtil.getFessConfig();
final long startTime = System.currentTimeMillis();
final long startTime = systemHelper.getCurrentTimeAsLong();
final List<String> sessionIdList = new ArrayList<>();
crawlerList.clear();
@ -443,7 +443,7 @@ public class WebFsIndexHelper {
// put cralwing info
final CrawlingInfoHelper crawlingInfoHelper = ComponentUtil.getCrawlingInfoHelper();
final long execTime = System.currentTimeMillis() - startTime;
final long execTime = systemHelper.getCurrentTimeAsLong() - startTime;
crawlingInfoHelper.putToInfoMap(Constants.WEB_FS_CRAWLING_EXEC_TIME, Long.toString(execTime));
if (logger.isInfoEnabled()) {
logger.info("[EXEC TIME] crawling time: {}ms", execTime);

View file

@ -188,7 +188,7 @@ public class IndexUpdater extends Thread {
final DocList docList = new DocList();
final List<EsAccessResult> accessResultList = new ArrayList<>();
long updateTime = System.currentTimeMillis();
long updateTime = systemHelper.getCurrentTimeAsLong();
int errorCount = 0;
int emptyListCount = 0;
long cleanupTime = -1;
@ -200,7 +200,7 @@ public class IndexUpdater extends Thread {
docList.clear();
accessResultList.clear();
updateTime = System.currentTimeMillis() - updateTime;
updateTime = systemHelper.getCurrentTimeAsLong() - updateTime;
final long interval = updateInterval - updateTime;
if (interval > 0) {
@ -217,7 +217,7 @@ public class IndexUpdater extends Thread {
logger.debug("Processing documents in IndexUpdater queue.");
}
updateTime = System.currentTimeMillis();
updateTime = systemHelper.getCurrentTimeAsLong();
List<EsAccessResult> arList = getAccessResultList(cb, cleanupTime);
if (arList.isEmpty()) {
@ -246,7 +246,7 @@ public class IndexUpdater extends Thread {
cleanupFinishedSessionData();
}
}
executeTime += System.currentTimeMillis() - updateTime;
executeTime += systemHelper.getCurrentTimeAsLong() - updateTime;
if (logger.isDebugEnabled()) {
logger.debug("Processed documents in IndexUpdater queue.");
@ -339,7 +339,7 @@ public class IndexUpdater extends Thread {
continue;
}
final long startTime = System.currentTimeMillis();
final long startTime = systemHelper.getCurrentTimeAsLong();
final AccessResultData<?> accessResultData = getAccessResultData(accessResult);
if (accessResultData != null) {
accessResult.setAccessResultData(null);
@ -371,7 +371,7 @@ public class IndexUpdater extends Thread {
docList.add(ingest(accessResult, map));
final long contentSize = indexingHelper.calculateDocumentSize(map);
docList.addContentSize(contentSize);
final long processingTime = System.currentTimeMillis() - startTime;
final long processingTime = systemHelper.getCurrentTimeAsLong() - startTime;
docList.addProcessingTime(processingTime);
if (logger.isDebugEnabled()) {
logger.debug("Added the document({}, {}ms). The number of a document cache is {} (size: {}).",
@ -485,11 +485,11 @@ public class IndexUpdater extends Thread {
private long cleanupAccessResults(final List<EsAccessResult> accessResultList) {
if (!accessResultList.isEmpty()) {
final long execTime = System.currentTimeMillis();
final long execTime = systemHelper.getCurrentTimeAsLong();
final int size = accessResultList.size();
dataService.update(accessResultList);
accessResultList.clear();
final long time = System.currentTimeMillis() - execTime;
final long time = systemHelper.getCurrentTimeAsLong() - execTime;
if (logger.isDebugEnabled()) {
logger.debug("Updated {} access results. The execution time is {}ms.", size, time);
}
@ -502,7 +502,7 @@ public class IndexUpdater extends Thread {
if (logger.isDebugEnabled()) {
logger.debug("Getting documents in IndexUpdater queue.");
}
final long execTime = System.currentTimeMillis();
final long execTime = systemHelper.getCurrentTimeAsLong();
final List<EsAccessResult> arList = ((EsDataService) dataService).getAccessResultList(cb);
final FessConfig fessConfig = ComponentUtil.getFessConfig();
if (!arList.isEmpty()) {
@ -522,7 +522,7 @@ public class IndexUpdater extends Thread {
} else {
buf.append("no docs in indexing queue (Doc:{access ");
}
buf.append(System.currentTimeMillis() - execTime).append("ms");
buf.append(systemHelper.getCurrentTimeAsLong() - execTime).append("ms");
if (cleanupTime >= 0) {
buf.append(", cleanup ").append(cleanupTime).append("ms");
}
@ -543,22 +543,23 @@ public class IndexUpdater extends Thread {
}
private void cleanupFinishedSessionData() {
final long execTime = System.currentTimeMillis();
final long execTime = systemHelper.getCurrentTimeAsLong();
// cleanup
for (final String sessionId : finishedSessionIdList) {
final long execTime2 = System.currentTimeMillis();
final long execTime2 = systemHelper.getCurrentTimeAsLong();
if (logger.isDebugEnabled()) {
logger.debug("Deleting document data: {}", sessionId);
}
deleteBySessionId(sessionId);
if (logger.isDebugEnabled()) {
logger.debug("Deleted {} documents. The execution time is {}ms.", sessionId, (System.currentTimeMillis() - execTime2));
logger.debug("Deleted {} documents. The execution time is {}ms.", sessionId,
(systemHelper.getCurrentTimeAsLong() - execTime2));
}
}
finishedSessionIdList.clear();
if (logger.isInfoEnabled()) {
logger.info("Deleted completed document data. The execution time is {}ms.", (System.currentTimeMillis() - execTime));
logger.info("Deleted completed document data. The execution time is {}ms.", (systemHelper.getCurrentTimeAsLong() - execTime));
}
}

View file

@ -1085,10 +1085,11 @@ public class LdapManager {
controls.setReturningAttributes(returningAttrs);
}
final long startTime = System.currentTimeMillis();
final SystemHelper systemHelper = ComponentUtil.getSystemHelper();
final long startTime = systemHelper.getCurrentTimeAsLong();
final List<SearchResult> list = Collections.list(holder.get().search(baseDn, filter, controls));
if (logger.isDebugEnabled()) {
logger.debug("LDAP search[{}ms]: {} - {}", System.currentTimeMillis() - startTime, baseDn, filter);
logger.debug("LDAP search[{}ms]: {} - {}", systemHelper.getCurrentTimeAsLong() - startTime, baseDn, filter);
}
consumer.accept(list);
} catch (final NamingException e) {

View file

@ -168,7 +168,7 @@ public class AzureAdAuthenticator implements SsoAuthenticator {
stateMap = new HashMap<>();
session.setAttribute(STATES, stateMap);
}
final StateData stateData = new StateData(nonce, System.currentTimeMillis());
final StateData stateData = new StateData(nonce, ComponentUtil.getSystemHelper().getCurrentTimeAsLong());
if (logger.isDebugEnabled()) {
logger.debug("store {} in session", stateData);
}
@ -319,7 +319,7 @@ public class AzureAdAuthenticator implements SsoAuthenticator {
@SuppressWarnings("unchecked")
final Map<String, StateData> states = (Map<String, StateData>) session.getAttribute(STATES);
if (states != null) {
final long now = System.currentTimeMillis();
final long now = ComponentUtil.getSystemHelper().getCurrentTimeAsLong();
states.entrySet().stream().filter(e -> (now - e.getValue().getExpiration()) / 1000L > getStateTtl()).map(Map.Entry::getKey)
.collect(Collectors.toList()).forEach(s -> {
if (logger.isDebugEnabled()) {

View file

@ -236,7 +236,8 @@ public class ThumbnailManager {
}
protected void process(final FessConfig fessConfig, final ThumbnailQueue entity) {
ComponentUtil.getSystemHelper().calibrateCpuLoad();
final SystemHelper systemHelper = ComponentUtil.getSystemHelper();
systemHelper.calibrateCpuLoad();
if (logger.isDebugEnabled()) {
logger.debug("Processing thumbnail: {}", entity);
@ -245,14 +246,14 @@ public class ThumbnailManager {
try {
final File outputFile = new File(baseDir, entity.getPath());
final File noImageFile = new File(outputFile.getAbsolutePath() + NOIMAGE_FILE_SUFFIX);
if (!noImageFile.isFile() || System.currentTimeMillis() - noImageFile.lastModified() > noImageExpired) {
if (!noImageFile.isFile() || systemHelper.getCurrentTimeAsLong() - noImageFile.lastModified() > noImageExpired) {
if (noImageFile.isFile() && !noImageFile.delete()) {
logger.warn("Failed to delete {}", noImageFile.getAbsolutePath());
}
final ThumbnailGenerator generator = ComponentUtil.getComponent(generatorName);
if (generator.isAvailable()) {
if (!generator.generate(entity.getThumbnailId(), outputFile)) {
new File(outputFile.getAbsolutePath() + NOIMAGE_FILE_SUFFIX).setLastModified(System.currentTimeMillis());
new File(outputFile.getAbsolutePath() + NOIMAGE_FILE_SUFFIX).setLastModified(systemHelper.getCurrentTimeAsLong());
} else {
final long interval = fessConfig.getThumbnailGeneratorIntervalAsInteger().longValue();
if (interval > 0) {
@ -448,7 +449,7 @@ public class ThumbnailManager {
@Override
public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException {
if (System.currentTimeMillis() - Files.getLastModifiedTime(file).toMillis() > expiry) {
if (ComponentUtil.getSystemHelper().getCurrentTimeAsLong() - Files.getLastModifiedTime(file).toMillis() > expiry) {
deletedFileList.add(file);
if (deletedFileList.size() > maxPurgeSize) {
deleteFiles();

View file

@ -57,7 +57,7 @@ public class CommandGenerator extends BaseThumbnailGenerator {
if (baseDir == null) {
baseDir = new File(System.getProperty("java.io.tmpdir"));
}
destoryTimer = new Timer("CommandGeneratorDestoryTimer-" + System.currentTimeMillis(), true);
destoryTimer = new Timer("CommandGeneratorDestoryTimer-" + ComponentUtil.getSystemHelper().getCurrentTimeAsLong(), true);
updateProperties();
}

View file

@ -126,7 +126,7 @@ public class GsaConfigParser extends DefaultHandler {
throw new GsaConfigException("Invalid format.");
}
if (COLLECTION.equalsIgnoreCase(qName) && COLLECTIONS.equalsIgnoreCase(tagQueue.peekLast())) {
final long now = System.currentTimeMillis();
final long now = ComponentUtil.getSystemHelper().getCurrentTimeAsLong();
final String name = attributes.getValue("Name");
labelType = new LabelType();
labelType.setName(name);
@ -165,7 +165,7 @@ public class GsaConfigParser extends DefaultHandler {
} else if (GLOBALPARAMS.equalsIgnoreCase(qName)) {
final Object startUrls = globalParams.get(START_URLS);
if (startUrls != null) {
final long now = System.currentTimeMillis();
final long now = ComponentUtil.getSystemHelper().getCurrentTimeAsLong();
final List<String> urlList = split(startUrls.toString(), "\n")
.get(stream -> stream.map(String::trim).filter(StringUtil::isNotBlank).collect(Collectors.toList()));

View file

@ -19,6 +19,7 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.codelibs.fess.helper.CrawlerStatsHelper.StatsKeyObject;
import org.codelibs.fess.unit.UnitFessTestCase;
import org.codelibs.fess.util.ComponentUtil;
public class CrawlerStatsHelperTest extends UnitFessTestCase {
@ -31,6 +32,7 @@ public class CrawlerStatsHelperTest extends UnitFessTestCase {
@Override
public void setUp() throws Exception {
super.setUp();
ComponentUtil.register(new SystemHelper(), "systemHelper");
crawlerStatsHelper = new CrawlerStatsHelper() {
@Override
protected void log(final StringBuilder buf) {

View file

@ -50,6 +50,7 @@ public class IndexingHelperTest extends UnitFessTestCase {
@Override
public void setUp() throws Exception {
super.setUp();
ComponentUtil.register(new SystemHelper(), "systemHelper");
indexingHelper = new IndexingHelper() {
@Override
protected long getDocumentSizeByQuery(final SearchEngineClient searchEngineClient, final QueryBuilder queryBuilder,

View file

@ -20,11 +20,18 @@ import java.io.InputStream;
import org.codelibs.core.io.ResourceUtil;
import org.codelibs.fess.es.config.exentity.LabelType;
import org.codelibs.fess.helper.SystemHelper;
import org.codelibs.fess.unit.UnitFessTestCase;
import org.xml.sax.InputSource;
public class GsaConfigParserTest extends UnitFessTestCase {
@Override
public void setUp() throws Exception {
super.setUp();
ComponentUtil.register(new SystemHelper(), "systemHelper");
}
public void test_parse() throws IOException {
GsaConfigParser parser = new GsaConfigParser();
try (InputStream is = ResourceUtil.getResourceAsStream("data/gsaconfig.xml")) {