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.nuxeo.ecm.core.redis.contribs.RedisBlockingQueue.java

@Override
public Runnable poll(long timeout, TimeUnit unit) throws InterruptedException {
    long nanos = unit.toNanos(timeout);
    nanos = awaitActivation(nanos);/*from   ww  w  .ja v a  2s.  c o m*/
    if (nanos <= 0) {
        return null;
    }
    long end = System.currentTimeMillis() + TimeUnit.NANOSECONDS.toMillis(nanos);
    for (;;) {
        Runnable r = poll();
        if (r != null) {
            return r;
        }
        if (timeUntil(end) == 0) {
            return null;
        }
        // TODO replace by wakeup when an element is added
        Thread.sleep(100);
    }
}

From source file:org.nuxeo.ecm.core.work.WorkManagerImpl.java

@Override
public boolean awaitCompletion(String queueId, long duration, TimeUnit unit) throws InterruptedException {
    return getExecutor(queueId).completionSynchronizer.await(unit.toNanos(duration)) > 0;
}

From source file:org.nuxeo.ecm.core.work.WorkManagerImpl.java

@Override
public boolean awaitCompletion(long duration, TimeUnit unit) throws InterruptedException {
    return completionSynchronizer.await(unit.toNanos(duration)) > 0;
}

From source file:org.springframework.integration.store.MessageGroupQueue.java

public Message<?> poll(long timeout, TimeUnit unit) throws InterruptedException {
    Message<?> message = null;//w  w  w . j a v a 2 s.co m
    long timeoutInNanos = unit.toNanos(timeout);
    final Lock storeLock = this.storeLock;
    storeLock.lockInterruptibly();

    try {
        while (this.size() == 0 && timeoutInNanos > 0) {
            timeoutInNanos = this.messageStoreNotEmpty.awaitNanos(timeoutInNanos);
        }
        message = this.doPoll();

    } finally {
        storeLock.unlock();
    }
    return message;
}

From source file:org.springframework.integration.store.MessageGroupQueue.java

public boolean offer(Message<?> message, long timeout, TimeUnit unit) throws InterruptedException {
    long timeoutInNanos = unit.toNanos(timeout);
    boolean offered = false;

    final Lock storeLock = this.storeLock;
    storeLock.lockInterruptibly();//from w  ww.ja v  a  2s . c  o  m
    try {
        if (capacity != Integer.MAX_VALUE) {
            while (this.size() == capacity && timeoutInNanos > 0) {
                timeoutInNanos = this.messageStoreNotFull.awaitNanos(timeoutInNanos);
            }
        }
        if (timeoutInNanos > 0) {
            offered = this.doOffer(message);
        }
    } finally {
        storeLock.unlock();
    }
    return offered;
}