Example usage for java.util.concurrent TimeUnit toNanos

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

Introduction

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

Prototype

public long toNanos(long duration) 

Source Link

Document

Equivalent to #convert(long,TimeUnit) NANOSECONDS.convert(duration, this) .

Usage

From source file:org.apache.activemq.apollo.dto.TimeMetricDTO.java

public float max(TimeUnit unit) {
    return ((float) max) / unit.toNanos(1);
}

From source file:org.apache.activemq.apollo.dto.TimeMetricDTO.java

public float min(TimeUnit unit) {
    return ((float) min) / unit.toNanos(1);
}

From source file:org.apache.activemq.apollo.dto.TimeMetricDTO.java

public float total(TimeUnit unit) {
    return ((float) total) / unit.toNanos(1);
}

From source file:com.turbospaces.spaces.tx.TransactionModificationLock.java

boolean tryLock(final long transactionID, final long timeout, final TimeUnit unit) throws InterruptedException {
    return sync.tryAcquireNanos(transactionID, unit.toNanos(timeout));
}

From source file:com.proofpoint.stats.TimeStat.java

public void add(long value, TimeUnit timeUnit) {
    add(timeUnit.toNanos(value));
}

From source file:com.googlecode.actorom.impl.remote.RemoteActorProxy.java

public synchronized FutureResult send(Object message, long timeout, TimeUnit unit) {
    if (isConnected() && isActiveActor()) {
        String id = ProtocolUtils.generateCorrelationId();
        CompletableFutureResult future = new CoreFutureResult(unit.toNanos(timeout));
        // Put the future prior to actually send the message!
        futures.put(id, future);/*from  ww  w  . j  a  v a  2s  .co  m*/
        //
        Header header = new Header(id);
        boolean acknowledged = connector
                .send(new SendWithFutureCommand(header, address, message, unit.toNanos(timeout)));
        if (acknowledged) {
            return future;
        } else {
            futures.remove(id);
            throw new ActorInvocationException("Error while sending message to remote actor: " + address);
        }
    } else {
        throw new ActorInvocationException("Error while sending message to remote actor: " + address);
    }
}

From source file:com.datastax.driver.core.LastResultSetFuture.java

/**
 * {@inheritDoc}/* w  w  w. ja  v a2 s.c  om*/
 * <p>
 * <i>Note:</i> This method will finish executing all remaining statements
 * until one generates an error and return the result set from that last one
 * or until there is no more time left.
 *
 * @author paouelle
 *
 * @see com.google.common.util.concurrent.AbstractFuture#get(long, java.util.concurrent.TimeUnit)
 */
@Override
public ResultSet get(long timeout, TimeUnit unit)
        throws InterruptedException, TimeoutException, ExecutionException {
    final long end = System.nanoTime() + unit.toNanos(timeout);
    ResultSetFuture future;

    while (true) {
        synchronized (statements) {
            future = this.future;
            // note that our listener above will actually be executing the next
            // statements automatically
            if (!statements.hasNext()) {
                break;
            }
        }
        // note that our listener above will actually be executing the next
        // statements automatically
        // --- Future treats negative timeouts just like zero.
        future.get(end - System.nanoTime(), TimeUnit.NANOSECONDS);
    }
    return future.get(end - System.nanoTime(), TimeUnit.NANOSECONDS);
}

From source file:net.paoding.spdy.client.netty.ResponseFuture.java

public boolean awaitUninterruptibly(long timeout, TimeUnit unit) {
    try {/*  w  w  w .j  a  v  a 2s  . co  m*/
        return await0(unit.toNanos(timeout), false);
    } catch (InterruptedException e) {
        throw new InternalError();
    }
}

From source file:com.teradata.benchto.driver.listeners.benchmark.BenchmarkStatusReporter.java

public void awaitAllFutures(long timeout, TimeUnit unit) {
    processCompletedFutures();//from   w w  w  . ja va 2s .c o  m
    List<Future<?>> futures = drainFutures();

    LOG.info("Awaiting completion of {} futures", futures.size());

    Stopwatch stopwatch = Stopwatch.createStarted();
    for (Future<?> future : futures) {
        long remainingNanos = unit.toNanos(timeout) - stopwatch.elapsed(NANOSECONDS);
        remainingNanos = Math.max(remainingNanos, 0); // let Future.get handle timeout

        try {
            future.get(remainingNanos, NANOSECONDS);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            throw new RuntimeException("Interrupted when retrieving result of an already done future", e);
        } catch (ExecutionException | TimeoutException | CancellationException e) {
            throw new RuntimeException("Failure when waiting for listener completion: " + e, e);
        }
    }
}

From source file:net.paoding.spdy.client.netty.ResponseFuture.java

public boolean await(long timeout, TimeUnit unit) throws InterruptedException {
    return await0(unit.toNanos(timeout), true);
}