Example usage for java.util.concurrent TimeUnit toMillis

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

Introduction

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

Prototype

public long toMillis(long duration) 

Source Link

Document

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

Usage

From source file:com.reactivetechnologies.platform.analytics.WekaMessagingChannel.java

/**
 * //from www .  j a  v a 2  s.c  o m
 * @param duration
 * @param unit
 * @return
 * @throws InterruptedException
 */
private boolean signalAndAwait(long duration, TimeUnit unit) throws InterruptedException {
    synchronized (this) {
        mCount.set(hzService.size());
        processing = true;
        try {
            sendMessage(DUMP_MODEL_REQ);
            wait(unit.toMillis(duration));

        } finally {
            processing = false;
        }
    }
    return mCount.get() == 0;

}

From source file:org.modeshape.jcr.value.binary.CassandraBinaryStore.java

@Override
public void removeValuesUnusedLongerThan(long minimumAge, TimeUnit unit) throws BinaryStoreException {
    try {/*w  w  w  . j  a  va2s.  c  o  m*/
        Date deadline = new Date(new Date().getTime() - unit.toMillis(minimumAge));
        // When querying using 2nd indexes, Cassandra
        // (it's not CQL specific) requires that you use an '=' for at least one of
        // the indexed column in the where clause. This is a limitation of Cassandra.
        // So we have to do some tricks here
        ResultSet rs = session.execute("SELECT cid from modeshape.binary where usage=0 and usage_time < "
                + deadline.getTime() + " allow filtering;");

        Iterator<Row> rows = rs.iterator();
        while (rows.hasNext()) {
            session.execute("DELETE from modeshape.binary where cid = '" + rows.next().getString("cid") + "';");
        }

        rs = session.execute("SELECT cid from modeshape.binary where usage=1 and usage_time < "
                + deadline.getTime() + " allow filtering;");
        rows = rs.iterator();
        while (rows.hasNext()) {
            session.execute("DELETE from modeshape.binary where cid = '" + rows.next().getString("cid") + "';");
        }
    } catch (RuntimeException e) {
        throw new BinaryStoreException(e);
    }
}

From source file:com.google.acre.appengine.script.AppEngineAsyncUrlfetch.java

public void wait_on_result(long time, TimeUnit tunit) {
    int i = 0;//w  w  w  .j  a v a  2 s.  c om
    long endtime = System.currentTimeMillis() + tunit.toMillis(time);

    Context ctx = Context.getCurrentContext();
    while (_requests.size() > 0) {
        long pass_start_time = System.currentTimeMillis();

        if (i > _requests.size() - 1)
            i = 0;

        if (time != -1 && endtime <= System.currentTimeMillis()) {
            for (AsyncRequest r : _requests) {
                r.request.cancel(true);
            }
            throw new JSURLTimeoutError("Time limit exceeded").newJSException(_scope);
        }

        AsyncRequest asyncreq = _requests.get(i);
        Future<HTTPResponse> futr = asyncreq.request;
        Function callback = asyncreq.callback;
        if (futr.isCancelled()) {
            JSURLError jse = new JSURLError("Request cancelled");

            callback.call(ctx, _scope, null, new Object[] { asyncreq.url.toString(), jse.toJSError(_scope) });
            _requests.remove(i);
            continue;
        }

        try {
            HTTPResponse res = futr.get(10, TimeUnit.MILLISECONDS);
            callback.call(ctx, _scope, null,
                    new Object[] { asyncreq.url.toString(), callback_result(asyncreq, res) });
            _requests.remove(i);
            continue;
        } catch (TimeoutException e) {
            // This is timeout on the futr.get() call, not a request timeout
        } catch (CancellationException e) {
            // pass, handled by isCancelled
        } catch (ExecutionException e) {
            JSURLError jse = new JSURLError(e.getMessage());

            callback.call(ctx, _scope, null, new Object[] { asyncreq.url.toString(), jse.toJSError(_scope) });
            _requests.remove(i);
            continue;
        } catch (InterruptedException e) {
            JSURLError jse = new JSURLError(e.getMessage());

            callback.call(ctx, _scope, null, new Object[] { asyncreq.url.toString(), jse.toJSError(_scope) });
            _requests.remove(i);
            continue;
        }

        _costCollector.collect("auub", System.currentTimeMillis() - pass_start_time);
        i++;
    }
}

From source file:io.fluo.api.config.FluoConfiguration.java

public void setTransactionRollbackTime(long time, TimeUnit tu) {
    setProperty(TRANSACTION_ROLLBACK_TIME_PROP, tu.toMillis(time));
}

From source file:org.apache.http2.impl.conn.BasicClientConnectionManager.java

public void closeIdleConnections(long idletime, TimeUnit tunit) {
    if (tunit == null) {
        throw new IllegalArgumentException("Time unit must not be null.");
    }/*from   ww  w.ja  va 2  s . co  m*/
    synchronized (this) {
        assertNotShutdown();
        long time = tunit.toMillis(idletime);
        if (time < 0) {
            time = 0;
        }
        long deadline = System.currentTimeMillis() - time;
        if (this.poolEntry != null && this.poolEntry.getUpdated() <= deadline) {
            this.poolEntry.close();
            this.poolEntry.getTracker().reset();
        }
    }
}

From source file:org.apache.metron.profiler.client.window.WindowProcessor.java

/**
 * We've set a time interval, which is a value along with a unit.
 * @param ctx//from w  w  w. j a  v a  2  s .c  om
 */
@Override
public void exitTimeInterval(
        org.apache.metron.profiler.client.window.generated.WindowParser.TimeIntervalContext ctx) {
    if (checkForException(ctx)) {
        return;
    }
    Token<?> timeUnit = stack.pop();
    Token<?> timeDuration = stack.pop();
    long duration = ConversionUtils.convert(timeDuration.getValue(), Long.class);
    TimeUnit unit = (TimeUnit) timeUnit.getValue();
    stack.push(new Token<>(unit.toMillis(duration), Long.class));
}

From source file:org.apache.http2.impl.conn.tsccm.AbstractConnPool.java

/**
 * Closes idle connections./*from   w w  w.  j  a  v  a 2s. c o  m*/
 *
 * @param idletime  the time the connections should have been idle
 *                  in order to be closed now
 * @param tunit     the unit for the <code>idletime</code>
 */
public void closeIdleConnections(long idletime, TimeUnit tunit) {

    // idletime can be 0 or negative, no problem there
    if (tunit == null) {
        throw new IllegalArgumentException("Time unit must not be null.");
    }

    poolLock.lock();
    try {
        idleConnHandler.closeIdleConnections(tunit.toMillis(idletime));
    } finally {
        poolLock.unlock();
    }
}

From source file:org.panthercode.arctic.core.processing.modules.impl.Repeater.java

/**
 * Set a new delay time the object is associated with. The value must be greater than or equals zero.
 *
 * @param unit     time unit of duration
 * @param duration new timeout value//w w  w .j a  va  2 s . c om
 * @throws IllegalArgumentException Is thrown if value of duration is less than zero.
 * @throws NullPointerException
 */
public synchronized void setDelayTime(TimeUnit unit, long duration)
        throws NullPointerException, IllegalArgumentException {
    ArgumentUtils.assertNotNull(unit, "time unit");

    this.setDelayTime(unit.toMillis(duration));
}

From source file:com.epam.reportportal.apache.http.impl.conn.BasicHttpClientConnectionManager.java

public synchronized void closeIdleConnections(final long idletime, final TimeUnit tunit) {
    Args.notNull(tunit, "Time unit");
    if (this.shutdown) {
        return;/*  w  ww  . ja v a 2 s  . c o  m*/
    }
    if (!this.leased) {
        long time = tunit.toMillis(idletime);
        if (time < 0) {
            time = 0;
        }
        final long deadline = System.currentTimeMillis() - time;
        if (this.updated <= deadline) {
            closeConnection();
        }
    }
}

From source file:org.springframework.ide.eclipse.boot.dash.test.mocks.MockCloudFoundryClientFactory.java

public void setAppStartDelay(TimeUnit timeUnit, int howMany) {
    startDelay = timeUnit.toMillis(howMany);
}