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:io.wcm.wcm.commons.caching.CacheHeaderTest.java

@Test
public void testSetExpiresSeconds() {
    doAnswer(new ValidateDateHeaderAnswer(200 * DateUtils.MILLIS_PER_SECOND)).when(response)
            .setHeader(eq(CacheHeader.HEADER_EXPIRES), anyString());
    CacheHeader.setExpiresSeconds(response, 200);
}

From source file:de.tor.tribes.ui.windows.ClockFrame.java

public void addTimer(Attack pAttack, int pSecondsBefore) {
    if (pAttack == null) {
        return;//www  . j  a v  a 2  s.co m
    }
    String name = pAttack.getSource() + " -> " + pAttack.getTarget();

    jTimerName.setText(name);
    dateTimeField1.setDate(
            new Date(pAttack.getSendTime().getTime() - (DateUtils.MILLIS_PER_SECOND * pSecondsBefore)));
    if (jComboBox1.getSelectedItem() == null) {
        jComboBox1.setSelectedIndex(0);
    }

    addTimer();
}

From source file:gov.nih.nci.firebird.selenium2.scalability.tests.TimedAction.java

public T time() {
    Stopwatch stopwatch = new Stopwatch();
    stopwatch.start();//w  w w  .j av  a 2 s  . c  om
    T result;
    try {
        result = perform();
    } catch (Exception e) {
        throw new RuntimeException("Unexpected Exception in execution of " + actionName, e);
    }
    stopwatch.stop();
    long elapsedMillis = stopwatch.elapsed(TimeUnit.MILLISECONDS);
    System.out.println(actionName + " \t" + elapsedMillis);
    String timeoutMessage = "Exeuction time of " + elapsedMillis + " milliseconds exceeded timeout of "
            + timeoutSeconds + " for " + actionName;
    assertTrue(timeoutMessage, elapsedMillis <= timeoutSeconds * DateUtils.MILLIS_PER_SECOND);
    return result;
}

From source file:de.tor.tribes.types.FarmInformation.java

public void refreshRuntime() {
    if (lastRuntimeUpdate < System.currentTimeMillis() - DateUtils.MILLIS_PER_SECOND * 5) {
        getRuntimeInformation();
    }
}

From source file:io.wcm.wcm.commons.caching.CacheHeader.java

/**
 * Compares the "If-Modified-Since header" of the incoming request with the last modification date of an aggregated
 * resource. If the resource was not modified since the client retrieved the resource, a 304-redirect is send to the
 * response (and the method returns true). If the resource has changed (or the client didn't) supply the
 * "If-Modified-Since" header a "Last-Modified" header is set so future requests can be cached.
 * @param dateProvider abstraction layer that calculates the last-modification time of an aggregated resource
 * @param request Request//  w ww  . j  a va  2  s . c om
 * @param response Response
 * @param setExpiresHeader Set expires header to -1 to ensure the browser checks for a new version on every request.
 * @return true if the method send a 304 redirect, so that the caller shouldn't write any output to the response
 *         stream
 * @throws IOException
 */
public static boolean isNotModified(ModificationDateProvider dateProvider, SlingHttpServletRequest request,
        SlingHttpServletResponse response, boolean setExpiresHeader) throws IOException {

    // assume the resource *was* modified until we know better
    boolean isModified = true;

    // get the modification date of the resource(s) in question
    Date lastModificationDate = dateProvider.getModificationDate();

    // get the date of the version from the client's cache
    String ifModifiedSince = request.getHeader(HEADER_IF_MODIFIED_SINCE);

    // only compare if both resource modification date and If-Modified-Since header is available
    if (lastModificationDate != null && StringUtils.isNotBlank(ifModifiedSince)) {
        try {
            Date clientModificationDate = parseDate(ifModifiedSince);

            // resource is considered modified if it's modification date is *after* the client's modification date
            isModified = lastModificationDate.getTime() - DateUtils.MILLIS_PER_SECOND > clientModificationDate
                    .getTime();
        } catch (ParseException ex) {
            log.warn("Failed to parse value '" + ifModifiedSince + "' of If-Modified-Since header.", ex);
        }
    }

    // if resource wasn't modified: send a 304 and return true so the caller knows it shouldn't go on writing the response
    if (!isModified) {
        response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
        return true;
    }

    // set last modified header so future requests can be cached
    if (lastModificationDate != null) {
        response.setHeader(HEADER_LAST_MODIFIED, formatDate(lastModificationDate));
        if (setExpiresHeader) {
            // by setting an expires header we force the browser to always check for updated versions (only on author)
            response.setHeader(HEADER_EXPIRES, "-1");
        }
    }

    // tell the caller it should go on writing the response as no 304-header was send
    return false;
}

From source file:br.com.autonomiccs.apacheCloudStack.client.ApacheCloudStackClientTest.java

private void testRequestConfig(final RequestConfig config, final int timeout) {
    Assert.assertEquals(config.getConnectTimeout(), timeout * (int) DateUtils.MILLIS_PER_SECOND);
    Assert.assertEquals(config.getConnectionRequestTimeout(), timeout * (int) DateUtils.MILLIS_PER_SECOND);
    Assert.assertEquals(config.getSocketTimeout(), timeout * (int) DateUtils.MILLIS_PER_SECOND);
}

From source file:io.wcm.maven.plugins.contentpackage.AbstractContentPackageMojo.java

/**
 * Execute HTTP call with automatic retry as configured for the MOJO.
 * @param call HTTP call//  w ww  .  j av  a2 s  . com
 * @param runCount Number of runs this call was already executed
 * @throws MojoExecutionException Mojo execution exception
 */
private <T> T executeHttpCallWithRetry(HttpCall<T> call, int runCount) throws MojoExecutionException {
    try {
        return call.execute();
    } catch (MojoExecutionException ex) {
        // retry again if configured so...
        if (runCount < this.retryCount) {
            getLog().info("ERROR: " + ex.getMessage());
            getLog().debug("HTTP call failed.", ex);
            getLog().info("---------------");

            String msg = "HTTP call failed, try again (" + (runCount + 1) + "/" + this.retryCount + ")";
            if (this.retryDelay > 0) {
                msg += " after " + this.retryDelay + " second(s)";
            }
            msg += "...";
            getLog().info(msg);
            if (this.retryDelay > 0) {
                try {
                    Thread.sleep(this.retryDelay * DateUtils.MILLIS_PER_SECOND);
                } catch (InterruptedException ex1) {
                    // ignore
                }
            }
            return executeHttpCallWithRetry(call, runCount + 1);
        } else {
            throw ex;
        }
    }
}

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

@Scheduled(fixedDelay = 10 * DateUtils.MILLIS_PER_SECOND)
@Transactional(propagation = Propagation.NOT_SUPPORTED)
@Override/*from w w  w .  ja  v  a 2s .co m*/
public synchronized void pollForNewUndeliveredResourcesScheduler() {
    if (getConfig().isSchedulingDisabled()) {
        return;
    }
    pollForNewUndeliveredResources();
}

From source file:com.norconex.committer.core.AbstractFileQueueCommitter.java

private void deleteEmptyOldDirs(File parentDir) {
    final long someTimeAgo = System.currentTimeMillis()
            - (DateUtils.MILLIS_PER_SECOND * EMPTY_DIRS_SECONDS_LIMIT);
    Date date = new Date(someTimeAgo);
    int dirCount = FileUtil.deleteEmptyDirs(parentDir, date);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Deleted " + dirCount + " empty directories under " + parentDir);
    }//from ww w.j av a 2  s .  com
}

From source file:io.wcm.maven.plugins.contentpackage.AbstractContentPackageMojo.java

/**
 * Wait up to 10 min for bundles to become active.
 * @param httpClient Http client//from   ww w.  j a  v a  2  s  . c  om
 * @throws MojoExecutionException Mojo execution exception
 */
protected void waitForBundlesActivation(CloseableHttpClient httpClient) throws MojoExecutionException {
    if (StringUtils.isBlank(bundleStatusURL)) {
        getLog().debug("Skipping check for bundle activation state because no bundleStatusURL is defined.");
        return;
    }

    final int WAIT_INTERVAL_SEC = 3;
    final long CHECK_RETRY_COUNT = bundleStatusWaitLimit / WAIT_INTERVAL_SEC;

    getLog().info("Check bundle activation states...");
    for (int i = 1; i <= CHECK_RETRY_COUNT; i++) {
        BundleStatusCall call = new BundleStatusCall(httpClient, bundleStatusURL, getLog());
        BundleStatus bundleStatus = executeHttpCallWithRetry(call, 0);
        if (bundleStatus.isAllBundlesRunning()) {
            return;
        }
        getLog().info(bundleStatus.getStatusLine());
        getLog().info("Bundles are currently starting/stopping - wait " + WAIT_INTERVAL_SEC + " seconds "
                + "(max. " + bundleStatusWaitLimit + " seconds) ...");
        try {
            Thread.sleep(WAIT_INTERVAL_SEC * DateUtils.MILLIS_PER_SECOND);
        } catch (InterruptedException e) {
            // ignore
        }
    }
}