Example usage for org.apache.commons.lang3.time DateUtils MILLIS_PER_SECOND

List of usage examples for org.apache.commons.lang3.time DateUtils MILLIS_PER_SECOND

Introduction

In this page you can find the example usage for org.apache.commons.lang3.time DateUtils MILLIS_PER_SECOND.

Prototype

long MILLIS_PER_SECOND

To view the source code for org.apache.commons.lang3.time DateUtils MILLIS_PER_SECOND.

Click Source Link

Document

Number of milliseconds in a standard second.

Usage

From source file:com.yahoo.parsec.clients.ParsecAsyncProgressTimer.java

/**
 * progress time.//from  ww  w  . ja v  a  2  s  . co m
 * @param progress progress data object
 * @param opCode operation code
 */
public static void progressTime(ParsecAsyncProgress progress, TimerOpCode opCode) {
    //
    // time in microsecond
    //
    long now = System.nanoTime() / DateUtils.MILLIS_PER_SECOND;
    switch (opCode) {
    case TIMER_STARTSINGLE:
        progress.setStartSingleTime(now);
        break;
    case TIMER_NAMELOOKUP:
        progress.setNsLookupTime(now - progress.getStartSingleTime());
        break;
    case TIMER_CONNECT:
        progress.setConnectTime(now - progress.getStartSingleTime());
        break;
    case TIMER_STARTTRANSFER:
        progress.setStartTransferTime(now - progress.getStartSingleTime());
        break;
    case TIMER_PRETRANSFER:
        progress.setPreTransferTime(now - progress.getStartSingleTime());
        break;
    case TIMER_TOTAL:
        progress.setTotalTime(now - progress.getStartSingleTime());
        break;
    default:
        LOGGER.warn("opcode=" + opCode + " is not defined");
        break;
    }
}

From source file:com.nridge.core.base.std.Sleep.java

public static void forSeconds(int aSeconds) {
    forMilliseconds(aSeconds * DateUtils.MILLIS_PER_SECOND);
}

From source file:com.yahoo.parsec.clients.ParsecClientProfilingLogUtil.java

/**
 * log remote profiling log./*from ww w  . ja  v  a2 s  .c  o  m*/
 *
 * @param request ning http request
 * @param response ning http response
 * @param requestStatus request status
 * @param progress parsec async progress do
 * @param msgMap additional log msg in key=String, value=String format
 */
public static void logRemoteRequest(final Request request, final Response response, final String requestStatus,
        final ParsecAsyncProgress progress, final Map<String, String> msgMap) {
    if (!PROF_LOGGER.isTraceEnabled()) {
        return;
    }

    //
    // prepare log data
    //
    long now = System.currentTimeMillis();
    BigDecimal timeInSecond = new BigDecimal(now).divide(BigDecimal.valueOf(DateUtils.MILLIS_PER_SECOND));
    String contentLength = "";
    String origin = "";
    int respCode = -1;

    String reqUrl = request.getUri().toUrl();
    String reqMethod = request.getMethod();
    String reqHostHeader = request.getHeaders().getFirstValue(ParsecClientDefine.HEADER_HOST);

    if (response != null) {
        contentLength = response.getHeader(ParsecClientDefine.HEADER_CONTENT_LENGTH);
        respCode = response.getStatusCode();
    }

    try {
        String executeInfo = OBJECT_MAPPER.writeValueAsString(progress);

        //
        // FIXME: should implement a servlet filter to set $_SERVER['REQUEST_URI']
        //
        String srcUrl = "";

        StringBuilder stringBuilder = new StringBuilder().append("time=").append(timeInSecond).append(", ")
                .append("req_url=").append(reqUrl).append(", ").append("req_host_header=").append(reqHostHeader)
                .append(", ").append("req_method=").append(reqMethod).append(", ").append("exec_info=")
                .append(executeInfo).append(", ").append("resp_code=").append(respCode).append(", ")
                .append("src_url=").append(srcUrl).append(", ").append("req_status=").append(requestStatus)
                .append(", ").append("content_length=").append(contentLength).append(", ").append("origin=")
                .append(origin).append(", ");

        if (msgMap != null) {
            for (Map.Entry<String, String> entry : msgMap.entrySet()) {
                stringBuilder.append(entry.getKey()).append("=").append(entry.getValue()).append(", ");
            }
        }

        String logMsg = stringBuilder.toString();

        //logging
        PROF_LOGGER.trace(logMsg);
    } catch (JsonProcessingException e) {
        throw new RuntimeException(e);
    }
}

From source file:ca.uhn.fhir.jpa.search.StaleSearchDeletingSvc.java

@Scheduled(fixedDelay = 10 * DateUtils.MILLIS_PER_SECOND)
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public synchronized void pollForStaleSearches() {
    Date cutoff = new Date(System.currentTimeMillis() - myDaoConfig.getExpireSearchResultsAfterMillis());
    ourLog.debug("Searching for searches which are before {}", cutoff);

    Collection<Search> toDelete = mySearchDao.findWhereCreatedBefore(cutoff);
    if (toDelete.isEmpty()) {
        return;//from www  . ja v a 2  s .co  m
    }

    TransactionTemplate tt = new TransactionTemplate(myTransactionManager);
    for (final Search next : toDelete) {
        tt.execute(new TransactionCallbackWithoutResult() {
            @Override
            protected void doInTransactionWithoutResult(TransactionStatus theArg0) {
                Search searchToDelete = mySearchDao.findOne(next.getId());
                ourLog.info("Expiring stale search {} / {}", searchToDelete.getId(), searchToDelete.getUuid());
                mySearchIncludeDao.deleteForSearch(searchToDelete.getId());
                mySearchResultDao.deleteForSearch(searchToDelete.getId());
                mySearchDao.delete(searchToDelete);
            }
        });
    }

    ourLog.info("Deleted {} searches, {} remaining", toDelete.size(), mySearchDao.count());

}

From source file:net.larry1123.util.api.time.StringTime.java

/**
 * Takes just a number or a set of numbers with a D, H, M or, S fallowing it
 * The letters can be upper or lower case
 * 15h 50m 5s/* w w  w.java 2s. c o  m*/
 *
 * @param string Whole String to decode into parts
 *
 * @return the amount of time in milliseconds that the time string Decodes to
 */
public static long millisecondsFromString(String string) {
    if (string == null) {
        throw new NullPointerException("String can not be null");
    }
    string = string.trim();
    long ret = 0;
    try {
        ret = Long.parseLong(string);
    } catch (NumberFormatException e) {
        for (String part : string.split(" ")) {
            if (part.length() >= 2) {
                String time = part.substring(part.length() - 1);
                switch (Part.getFromString(time)) {
                case DAYS:
                    try {
                        Long days = Long.parseLong(part.substring(0, part.length() - 1));
                        ret += days * DateUtils.MILLIS_PER_DAY;
                    } catch (NumberFormatException error) {
                        // DO nothing right now
                    }
                    break;
                case HOUR:
                    try {
                        Long hours = Long.parseLong(part.substring(0, part.length() - 1));
                        ret += hours * DateUtils.MILLIS_PER_HOUR;
                    } catch (NumberFormatException error) {
                        // DO nothing right now
                    }
                    break;
                case MINUTES:
                    try {
                        Long minutes = Long.parseLong(part.substring(0, part.length() - 1));
                        ret += minutes * DateUtils.MILLIS_PER_MINUTE;
                    } catch (NumberFormatException error) {
                        // DO nothing right now
                    }
                    break;
                case SECONDS:
                    try {
                        Long seconds = Long.parseLong(part.substring(0, part.length() - 1));
                        ret += seconds * DateUtils.MILLIS_PER_SECOND;
                    } catch (NumberFormatException error) {
                        // DO nothing right now
                    }
                    break;
                default:
                    // Something is malformed just let it fly by and keep going
                    break;
                }
            } else if (part.length() == 1) {
                switch (Part.getFromString("" + part.charAt(1))) {
                case DAYS:
                    ret += DateUtils.MILLIS_PER_DAY;
                    break;
                case HOUR:
                    ret += DateUtils.MILLIS_PER_HOUR;
                    break;
                case MINUTES:
                    ret += DateUtils.MILLIS_PER_MINUTE;
                    break;
                case SECONDS:
                    ret += DateUtils.MILLIS_PER_SECOND;
                    break;
                default:
                    // Something is malformed just let it fly by and keep going
                    break;
                }
            }
        }
    }
    return ret;
}

From source file:ca.uhn.fhir.jpa.dao.dstu3.FhirResourceDaoSearchParameterDstu3.java

/**
 * This method is called once per minute to perform any required re-indexing. During most passes this will
 * just check and find that there are no resources requiring re-indexing. In that case the method just returns
 * immediately. If the search finds that some resources require reindexing, the system will do a bunch of
 * reindexing and then return./*ww w.  ja  v a2 s .  com*/
 */
@Override
@Scheduled(fixedDelay = DateUtils.MILLIS_PER_MINUTE)
public void performReindexingPass() {
    if (getConfig().isSchedulingDisabled()) {
        return;
    }

    int count = mySystemDao.performReindexingPass(100);
    for (int i = 0; i < 50 && count != 0; i++) {
        count = mySystemDao.performReindexingPass(100);
        try {
            Thread.sleep(DateUtils.MILLIS_PER_SECOND);
        } catch (InterruptedException e) {
            break;
        }
    }

}

From source file:ca.uhn.fhir.jpa.search.StaleSearchDeletingSvcImpl.java

@Scheduled(fixedDelay = 10 * DateUtils.MILLIS_PER_SECOND)
@Transactional(propagation = Propagation.NOT_SUPPORTED)
@Override/*from   w ww. java 2 s . co m*/
public synchronized void schedulePollForStaleSearches() {
    if (!myDaoConfig.isSchedulingDisabled()) {
        if (myDaoConfig.isExpireSearchResults()) {
            pollForStaleSearchesAndDeleteThem();
        }
    }
}

From source file:com.norconex.commons.lang.time.DurationUtil.java

private static String format(Locale locale, long duration, boolean islong, int maxUnits) {
    int max = Integer.MAX_VALUE;
    if (maxUnits > 0) {
        max = maxUnits;//  ww  w  .  j ava 2s.  c  om
    }
    long days = duration / DateUtils.MILLIS_PER_DAY;
    long accountedMillis = days * DateUtils.MILLIS_PER_DAY;
    long hours = (duration - accountedMillis) / DateUtils.MILLIS_PER_HOUR;
    accountedMillis += (hours * DateUtils.MILLIS_PER_HOUR);
    long mins = (duration - accountedMillis) / DateUtils.MILLIS_PER_MINUTE;
    accountedMillis += (mins * DateUtils.MILLIS_PER_MINUTE);
    long secs = (duration - accountedMillis) / DateUtils.MILLIS_PER_SECOND;
    StringBuilder b = new StringBuilder();
    int unitCount = 0;
    // days
    if (days > 0) {
        b.append(getString(locale, days, "day", islong));
        unitCount++;
    }
    // hours
    if ((hours > 0 || b.length() > 0) && unitCount < max) {
        b.append(getString(locale, hours, "hour", islong));
        unitCount++;
    }
    // minutes
    if ((mins > 0 || b.length() > 0) && unitCount < max) {
        b.append(getString(locale, mins, "minute", islong));
        unitCount++;
    }
    // seconds
    if (unitCount < max) {
        b.append(getString(locale, secs, "second", islong));
    }
    return b.toString().trim();
}

From source file:io.wcm.dam.assetservice.impl.dataversion.ChecksumDataVersionStrategy.java

/**
 * @param damPath DAM root path// w w  w . ja  v a2s  .c  o m
 * @param dataVersionUpdateIntervalSec Data version update interval
 * @param resourceResolverFactory Resource resolver factory
 * @param executor Shared executor service instance
 */
public ChecksumDataVersionStrategy(String damPath, int dataVersionUpdateIntervalSec,
        ResourceResolverFactory resourceResolverFactory, ScheduledExecutorService executor) {
    super(damPath);

    this.dataVersionUpdateIntervalMs = dataVersionUpdateIntervalSec * DateUtils.MILLIS_PER_SECOND;
    this.resourceResolverFactory = resourceResolverFactory;
    this.executor = executor;
    this.dataVersionQueryString = buildDataVersionQueryString(damPath);

    this.dataVersion = DATAVERSION_NOT_CALCULATED;

    if (dataVersionUpdateIntervalSec <= 0) {
        log.warn("{} - Invalid data version update interval: {} sec", damPath, dataVersionUpdateIntervalSec);
    } else {
        Runnable task = new UpdateDataVersionTask();
        this.executor.scheduleWithFixedDelay(task, 0, dataVersionUpdateIntervalSec, TimeUnit.SECONDS);
    }
}

From source file:com.bitplan.vzjava.resources.PowerPlotResource.java

/**
 * http://stackoverflow.com/a/10257341/1497139
 * Sends the file if modified and "not modified" if not modified
 * future work may put each file with a unique id in a separate folder in
 * tomcat/*  w w  w .jav a 2s  . co  m*/
 * * use that static URL for each file
 * * if file is modified, URL of file changes
 * * -> client always fetches correct file
 * 
 * method header for calling method public Response
 * getXY(@HeaderParam("If-Modified-Since") String modified) {
 * 
 * @param file
 *          to send
 * @param modified
 *          - HeaderField "If-Modified-Since" - may be "null"
 * @return Response to be sent to the client
 */
public static Response returnFile(File file, String modified) {
    if (!file.exists()) {
        return Response.status(Status.NOT_FOUND).build();
    }

    // do we really need to send the file or can send "not modified"?
    if (modified != null) {
        Date modifiedDate = null;

        // we have to switch the locale to ENGLISH as parseDate parses in the
        // default locale
        Locale old = Locale.getDefault();
        Locale.setDefault(Locale.ENGLISH);
        try {
            modifiedDate = DateUtils.parseDate(modified, DEFAULT_PATTERNS);
        } catch (ParseException e) {
            LOGGER.log(Level.WARNING, e.getMessage());
        }
        Locale.setDefault(old);

        if (modifiedDate != null) {
            // modifiedDate does not carry milliseconds, but fileDate does
            // therefore we have to do a range-based comparison
            // 1000 milliseconds = 1 second
            if (file.lastModified() - modifiedDate.getTime() < DateUtils.MILLIS_PER_SECOND) {
                return Response.status(Status.NOT_MODIFIED).build();
            }
        }
    }
    // we really need to send the file

    try {
        Date fileDate = new Date(file.lastModified());
        return Response.ok(new FileInputStream(file)).lastModified(fileDate).build();
    } catch (FileNotFoundException e) {
        return Response.status(Status.NOT_FOUND).build();
    }
}