Example usage for java.util.concurrent TimeUnit toString

List of usage examples for java.util.concurrent TimeUnit toString

Introduction

In this page you can find the example usage for java.util.concurrent TimeUnit toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:org.apache.hadoop.hbase.client.locking.EntityLock.java

/**
 * @param timeout in milliseconds. If set to 0, waits indefinitely.
 * @return true if lock was acquired; and false if waiting time elapsed before lock could be
 * acquired./* w w  w.  ja  v  a  2 s .c om*/
 */
public boolean await(long timeout, TimeUnit timeUnit) throws InterruptedException {
    final boolean result = latch.await(timeout, timeUnit);
    String lockRequestStr = lockRequest.toString().replace("\n", ", ");
    if (result) {
        LOG.info("Acquired " + lockRequestStr);
    } else {
        LOG.info(String.format("Failed acquire in %s %s of %s", timeout, timeUnit.toString(), lockRequestStr));
    }
    return result;
}

From source file:org.apache.sling.commons.metrics.internal.MetricWebConsolePlugin.java

private static String calculateRateUnit(TimeUnit unit) {
    final String s = unit.toString().toLowerCase(Locale.US);
    return s.substring(0, s.length() - 1);
}

From source file:org.apache.tajo.util.metrics.reporter.TajoMetricsScheduledReporter.java

private String calculateRateUnit(TimeUnit unit) {
    final String s = unit.toString().toLowerCase(Locale.US);
    return s.substring(0, s.length() - 1);
}

From source file:org.cloudifysource.utilitydomain.admin.TimedAdmin.java

/**
 * Validates the given action timeout is not shorter than the admin timeout, and issues a warning if it is.
 *//*from  www .j  a  v  a2  s  .  c  om*/
private void validateTimeout(final long timeout, final TimeUnit timeunit, final String actionDescription) {
    if (timeunit.toMillis(timeout) >= MAX_IDLE_TIME_MILLIS) {
        logger.warning("Admin object might expire prematurely! The specified timeout for " + actionDescription
                + " was set to " + timeout + " " + timeunit.toString() + " while the admin timeout is "
                + MAX_IDLE_TIME_MILLIS / 1000 + " seconds");
    }
}

From source file:org.codice.ddf.admin.common.PrioritizedBatchExecutor.java

private Optional<R> pollRemainingBatches(long totalWaitTime, TimeUnit timeUnit,
        CompletionService<T> completionService, int currentBatchSize, int index) {
    Future<T> taskFuture;//from  w w  w . jav  a2 s . c o m
    String timeUnitString = timeUnit.toString();
    LOGGER.debug("\tExceeded max wait time of {} {}. Polling remaining batches.", totalWaitTime,
            timeUnitString);

    while ((taskFuture = completionService.poll()) != null) {
        Optional<R> result = handleTaskResult(taskFuture);
        if (result.isPresent()) {
            LOGGER.debug("\tReturning valid task result {} of {} tasks.", index + 1, currentBatchSize);

            return result;
        }
    }
    return Optional.empty();
}

From source file:org.commonjava.maven.galley.cache.infinispan.FastLocalCacheProvider.java

private <K> K tryLockAnd(ConcreteResource resource, long timeout, TimeUnit unit, TransferLockTask<K> task)
        throws IOException {
    ReentrantLock lock = getTransferLock(resource);
    boolean locked = false;
    try {/* w w  w . j av a2  s .c o m*/
        if (timeout > 0) {
            locked = lock.tryLock(timeout, unit);
            if (locked) {
                return task.execute(resource);
            } else {
                throw new IOException(
                        String.format("Did not get lock for resource %s in %d %s, timeout happened.", resource,
                                timeout, unit.toString()));
            }
        } else {
            lock.lockInterruptibly();
            return task.execute(resource);
        }

    } catch (InterruptedException e) {
        logger.warn("Interrupted for the transfer lock with resource: {}", resource);
        return null;
    } finally {
        if (timeout <= 0 || locked) {
            lock.unlock();
        }
    }
}

From source file:org.openspaces.admin.internal.pu.statistics.StatisticsObjectList.java

private Double getDeltaPerTimeunit(TimeUnit timeUnit) {
    if (notNumberClass != null) {
        throw new ClassCastException(notNumberClass + " cannot be cast to a Number");
    }/*from www.jav  a  2s  . c om*/
    if (values.size() < 2) {
        return null;
    }

    Long timeWindowInTimeunit = timeUnit.convert(lastTimeStampMillis - firstTimeStampMillis,
            TimeUnit.MILLISECONDS);
    double lastValue = ((Number) last).doubleValue();
    double firstValue = ((Number) first).doubleValue();

    double deltaValuePerTimeunit = (lastValue - firstValue) / timeWindowInTimeunit;

    if (logger.isDebugEnabled()) {
        logger.debug("deltaValuePer" + timeUnit.toString() + "(" + toString() + ")=" + "(" + lastValue + "-"
                + firstValue + ")/" + timeWindowInTimeunit + "=" + deltaValuePerTimeunit);
    }
    return deltaValuePerTimeunit;
}

From source file:org.pentaho.di.ui.trans.steps.elasticsearchbulk.LabelTimeComposite.java

private String[] getTimeUnits() {
    ArrayList<String> timeUnits = new ArrayList<String>();
    for (TimeUnit timeUnit : TimeUnit.values()) {
        timeUnits.add(timeUnit.toString());
    }//from   w  ww  .  j av  a2 s .co  m
    return timeUnits.toArray(new String[timeUnits.size()]);
}

From source file:org.pentaho.di.ui.trans.steps.elasticsearchbulk.LabelTimeComposite.java

public void setTimeUnit(TimeUnit tu) {
    for (int i = 0; i < wTimeUnit.getItemCount(); i++) {
        if (tu.toString().equals(wTimeUnit.getItem(i))) {
            wTimeUnit.select(i);//from ww w  .j  a  v a  2  s. co  m
            break;
        }
    }
}

From source file:org.qe4j.web.OpenWebDriver.java

/**
 * Shortcut method to set implicit wait time.
 *
 * @param wait/*w ww.  j a va2s .  com*/
 * @param timeUnit
 */
public void setImplicitWaitTime(int wait, TimeUnit timeUnit) {
    log.trace("setting implicit wait time to {} {}", wait, timeUnit.toString());
    webDriver.manage().timeouts().implicitlyWait(wait, timeUnit);
}