Example usage for java.time Clock millis

List of usage examples for java.time Clock millis

Introduction

In this page you can find the example usage for java.time Clock millis.

Prototype

public long millis() 

Source Link

Document

Gets the current millisecond instant of the clock.

Usage

From source file:Main.java

public static void main(String[] args) {
    Clock clock = Clock.systemUTC();
    System.out.println(clock.millis());
}

From source file:org.codelibs.fess.web.IndexAction.java

protected String doSearchInternal() {
    final StringBuilder queryBuf = new StringBuilder(255);
    if (StringUtil.isNotBlank(indexForm.query)) {
        queryBuf.append(indexForm.query);
    }/* w  w w  . jav  a2s. c o  m*/
    if (StringUtil.isNotBlank(indexForm.op)) {
        request.setAttribute(Constants.DEFAULT_OPERATOR, indexForm.op);
    }
    if (queryBuf.indexOf(" OR ") >= 0) {
        queryBuf.insert(0, '(').append(')');
    }
    if (indexForm.additional != null) {
        final Set<String> fieldSet = new HashSet<String>();
        for (final String additional : indexForm.additional) {
            if (StringUtil.isNotBlank(additional) && additional.length() < 1000
                    && !hasFieldInQuery(fieldSet, additional)) {
                queryBuf.append(' ').append(additional);
            }
        }
    }
    if (!indexForm.fields.isEmpty()) {
        for (final Map.Entry<String, String[]> entry : indexForm.fields.entrySet()) {
            final List<String> valueList = new ArrayList<String>();
            final String[] values = entry.getValue();
            if (values != null) {
                for (final String v : values) {
                    valueList.add(v);
                }
            }
            if (valueList.size() == 1) {
                queryBuf.append(' ').append(entry.getKey()).append(":\"").append(valueList.get(0)).append('\"');
            } else if (valueList.size() > 1) {
                queryBuf.append(" (");
                for (int i = 0; i < valueList.size(); i++) {
                    if (i != 0) {
                        queryBuf.append(" OR");
                    }
                    queryBuf.append(' ').append(entry.getKey()).append(":\"").append(valueList.get(i))
                            .append('\"');
                }
                queryBuf.append(')');
            }

        }
    }
    if (StringUtil.isNotBlank(indexForm.sort)) {
        queryBuf.append(" sort:").append(indexForm.sort);
    }
    if (indexForm.lang != null) {
        final Set<String> langSet = new HashSet<>();
        for (final String lang : indexForm.lang) {
            if (StringUtil.isNotBlank(lang) && lang.length() < 1000) {
                if (Constants.ALL_LANGUAGES.equalsIgnoreCase(lang)) {
                    langSet.add(Constants.ALL_LANGUAGES);
                } else {
                    final String normalizeLang = systemHelper.normalizeLang(lang);
                    if (normalizeLang != null) {
                        langSet.add(normalizeLang);
                    }
                }
            }
        }
        if (langSet.size() > 1 && langSet.contains(Constants.ALL_LANGUAGES)) {
            langSet.clear();
            indexForm.lang = new String[] { Constants.ALL_LANGUAGES };
        } else {
            langSet.remove(Constants.ALL_LANGUAGES);
        }
        appendLangQuery(queryBuf, langSet);
    } else if (Constants.TRUE.equals(
            crawlerProperties.getProperty(Constants.USE_BROWSER_LOCALE_FOR_SEARCH_PROPERTY, Constants.FALSE))) {
        final Set<String> langSet = new HashSet<>();
        final Enumeration<Locale> locales = request.getLocales();
        if (locales != null) {
            while (locales.hasMoreElements()) {
                final Locale locale = locales.nextElement();
                final String normalizeLang = systemHelper.normalizeLang(locale.toString());
                if (normalizeLang != null) {
                    langSet.add(normalizeLang);
                }
            }
            if (!langSet.isEmpty()) {
                appendLangQuery(queryBuf, langSet);
            }
        }
    }

    final String query = queryBuf.toString().trim();

    // init pager
    if (StringUtil.isBlank(indexForm.start)) {
        indexForm.start = String.valueOf(DEFAULT_START_COUNT);
    } else {
        try {
            Long.parseLong(indexForm.start);
        } catch (final NumberFormatException e) {
            indexForm.start = String.valueOf(DEFAULT_START_COUNT);
        }
    }
    if (StringUtil.isBlank(indexForm.num)) {
        indexForm.num = String.valueOf(getDefaultPageSize());
    }
    normalizePageNum();

    final int pageStart = Integer.parseInt(indexForm.start);
    final int pageNum = Integer.parseInt(indexForm.num);
    try {
        documentItems = searchService.getDocumentList(query, pageStart, pageNum, indexForm.facet, indexForm.geo,
                indexForm.mlt, queryHelper.getResponseFields(), queryHelper.getResponseDocValuesFields());
    } catch (final SolrLibQueryException e) {
        if (logger.isDebugEnabled()) {
            logger.debug(e.getMessage(), e);
        }
        throw new SSCActionMessagesException(e, "errors.invalid_query_unknown");
    } catch (final InvalidQueryException e) {
        if (logger.isDebugEnabled()) {
            logger.debug(e.getMessage(), e);
        }
        throw new SSCActionMessagesException(e, e.getMessageCode());
    } catch (final ResultOffsetExceededException e) {
        if (logger.isDebugEnabled()) {
            logger.debug(e.getMessage(), e);
        }
        throw new SSCActionMessagesException(e, "errors.result_size_exceeded");
    }
    // search
    final QueryResponseList queryResponseList = (QueryResponseList) documentItems;
    facetResponse = queryResponseList.getFacetResponse();
    moreLikeThisResponse = queryResponseList.getMoreLikeThisResponse();
    final NumberFormat nf = NumberFormat.getInstance(RequestUtil.getRequest().getLocale());
    nf.setMaximumIntegerDigits(2);
    nf.setMaximumFractionDigits(2);
    try {
        execTime = nf.format((double) queryResponseList.getExecTime() / 1000);
    } catch (final Exception e) {
        // ignore
    }

    final Clock clock = Clock.systemDefaultZone();
    indexForm.rt = Long.toString(clock.millis());

    // favorite
    if (favoriteSupport || screenShotManager != null) {
        indexForm.queryId = userInfoHelper.generateQueryId(query, documentItems);
        if (screenShotManager != null) {
            screenShotManager.storeRequest(indexForm.queryId, documentItems);
            screenShotSupport = true;
        }
    }

    // search log
    if (searchLogSupport) {
        final LocalDateTime now = systemHelper.getCurrentTime();

        final SearchLogHelper searchLogHelper = ComponentUtil.getSearchLogHelper();
        final SearchLog searchLog = new SearchLog();

        String userCode = null;
        if (Constants.TRUE
                .equals(crawlerProperties.getProperty(Constants.USER_INFO_PROPERTY, Constants.TRUE))) {
            userCode = userInfoHelper.getUserCode();
            if (StringUtil.isNotBlank(userCode)) {
                final UserInfo userInfo = new UserInfo();
                userInfo.setCode(userCode);
                userInfo.setCreatedTime(now);
                userInfo.setUpdatedTime(now);
                searchLog.setUserInfo(OptionalEntity.of(userInfo));
            }
        }

        searchLog.setHitCount(queryResponseList.getAllRecordCount());
        searchLog.setResponseTime(Integer.valueOf((int) queryResponseList.getExecTime()));
        searchLog.setSearchWord(StringUtils.abbreviate(query, 1000));
        searchLog.setSearchQuery(StringUtils.abbreviate(queryResponseList.getSearchQuery(), 1000));
        searchLog.setSolrQuery(StringUtils.abbreviate(queryResponseList.getSolrQuery(), 1000));
        searchLog.setRequestedTime(now);
        searchLog.setQueryOffset(pageStart);
        searchLog.setQueryPageSize(pageNum);

        searchLog.setClientIp(StringUtils.abbreviate(request.getRemoteAddr(), 50));
        searchLog.setReferer(StringUtils.abbreviate(request.getHeader("referer"), 1000));
        searchLog.setUserAgent(StringUtils.abbreviate(request.getHeader("user-agent"), 255));
        if (userCode != null) {
            searchLog.setUserSessionId(userCode);
        }
        final Object accessType = request.getAttribute(Constants.SEARCH_LOG_ACCESS_TYPE);
        if (accessType instanceof CDef.AccessType) {
            switch ((CDef.AccessType) accessType) {
            case Json:
                searchLog.setAccessType_Json();
                searchLog.setAccessType_Others();
                searchLog.setAccessType_Xml();
                break;
            case Xml:
                searchLog.setAccessType_Xml();
                break;
            case Others:
                searchLog.setAccessType_Others();
                break;
            default:
                searchLog.setAccessType_Web();
                break;
            }
        } else {
            searchLog.setAccessType_Web();
        }

        @SuppressWarnings("unchecked")
        final Map<String, List<String>> fieldLogMap = (Map<String, List<String>>) request
                .getAttribute(Constants.FIELD_LOGS);
        if (fieldLogMap != null) {
            for (final Map.Entry<String, List<String>> logEntry : fieldLogMap.entrySet()) {
                for (final String value : logEntry.getValue()) {
                    searchLog.addSearchFieldLogValue(logEntry.getKey(), StringUtils.abbreviate(value, 1000));
                }
            }
        }

        searchLogHelper.addSearchLog(searchLog);
    }

    final String[] highlightQueries = (String[]) request.getAttribute(Constants.HIGHLIGHT_QUERIES);
    if (highlightQueries != null) {
        final StringBuilder buf = new StringBuilder(100);
        for (final String q : highlightQueries) {
            buf.append("&hq=").append(q);
        }
        appendHighlightQueries = buf.toString();
    }

    Beans.copy(documentItems, this)
            .includes("pageSize", "currentPageNumber", "allRecordCount", "allPageCount", "existNextPage",
                    "existPrevPage", "currentStartRecordNumber", "currentEndRecordNumber", "pageNumberList",
                    "partialResults", "queryTime", "searchTime")
            .execute();

    return query;
}