List of usage examples for java.util.concurrent TimeUnit toMillis
public long toMillis(long duration)
From source file:com.github.restdriver.clientdriver.ClientDriverResponse.java
/** * Sets the amount of time to allow this response to match within. * /* w w w . j a v a 2 s . co m*/ * @param interval * The number of given unit to wait * @param unit * The unit to wait for * @return This object, so you can chain these calls. */ public ClientDriverResponse within(long interval, TimeUnit unit) { this.waitUntil = System.currentTimeMillis() + unit.toMillis(interval); return this; }
From source file:io.vertigo.dynamo.impl.search.WritableFuture.java
/** {@inheritDoc} */ @Override// ww w. j ava 2 s . co m public synchronized V get(final long timeout, final TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { Assertion.checkNotNull(unit, "Time unit was null"); //----- final long msecs = unit.toMillis(timeout); final long startTime = msecs <= 0 ? 0 : System.currentTimeMillis(); long waitTime = msecs; if (this.completed) { return getResult(); } else if (waitTime <= 0) { throw new TimeoutException(); } else { for (;;) { wait(waitTime); if (this.completed) { return getResult(); } waitTime = msecs - (System.currentTimeMillis() - startTime); if (waitTime <= 0) { throw new TimeoutException(); } } } }
From source file:ch.sourcepond.io.checksum.impl.BaseUpdateStrategy.java
/** * @param pInterval/* ww w . j ava2 s . c o m*/ * @param pUnit * @throws IOException * @throws InterruptedException */ @GuardedBy("this") protected final void wait(final long pInterval, final TimeUnit pUnit) throws IOException { if (isCancelled()) { LOG.debug("Checksum calculation cancelled by user."); } else if (pInterval > 0) { try { wait(pUnit.toMillis(pInterval)); } catch (final InterruptedException e) { currentThread().interrupt(); throw new IOException(e.getMessage(), e); } } }
From source file:com.alertlogic.aws.analytics.poc.RecordKinesisPutter.java
/** * Continuously sends records to Amazon Kinesis sequentially. This will only stop if interrupted. If you * require more throughput consider using multiple {@link RecordKinesisPutter}s. * * @param delayBetweenRecords The amount of time to wait in between sending records. If this is <= 0 it will be * ignored.//w w w. jav a 2 s. co m * @param unitForDelay The unit of time to interpret the provided delay as. * * @throws InterruptedException Interrupted while waiting to send the next record. */ public void sendRecordsIndefinitely(long delayBetweenRecords, TimeUnit unitForDelay) throws InterruptedException { while (!Thread.currentThread().isInterrupted()) { sendRecord(); if (delayBetweenRecords > 0) { Thread.sleep(unitForDelay.toMillis(delayBetweenRecords)); } } }
From source file:org.apache.metron.profiler.DefaultMessageDistributor.java
public DefaultMessageDistributor withPeriodDuration(int duration, TimeUnit units) { return withPeriodDurationMillis(units.toMillis(duration)); }
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 a 2s. 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.springframework.yarn.boot.app.AbstractApplicationTests.java
protected YarnApplicationState waitState(ApplicationId applicationId, long timeout, TimeUnit unit, YarnApplicationState... applicationStates) throws Exception { YarnApplicationState state = null;//from w ww . ja v a 2 s. c o m long end = System.currentTimeMillis() + unit.toMillis(timeout); // break label for inner loop done: do { state = findState(getYarnClient(), applicationId); if (state == null) { break; } for (YarnApplicationState stateCheck : applicationStates) { if (state.equals(stateCheck)) { break done; } } Thread.sleep(1000); } while (System.currentTimeMillis() < end); return state; }
From source file:org.springframework.data.hadoop.store.support.PollingTaskSupport.java
/** * Instantiates a new polling task support. On default a simple {@code PeriodicTrigger} is used. * * @param taskScheduler the task scheduler * @param taskExecutor the task executor * @param unit the unit//from w ww.j a va 2 s . c o m * @param duration the duration */ public PollingTaskSupport(TaskScheduler taskScheduler, TaskExecutor taskExecutor, TimeUnit unit, long duration) { this.taskScheduler = taskScheduler; this.taskExecutor = taskExecutor; this.trigger = new PeriodicTrigger(unit.toMillis(duration)); }
From source file:ws.wamp.jawampa.WampClientBuilder.java
/** * Sets the amount of time that should be waited until a reconnect attempt is performed.<br> * The default value is {@link #DEFAULT_RECONNECT_INTERVAL}. * @param interval The interval that should be waited until a reconnect attempt<br> * is performed. The interval must be bigger than {@link #MIN_RECONNECT_INTERVAL}. * @param unit The unit of the interval//from w ww .j av a 2 s. c o m * @return The {@link WampClientBuilder} object * @throws WampError If the interval is invalid */ public WampClientBuilder withReconnectInterval(int interval, TimeUnit unit) throws ApplicationError { long intervalMs = unit.toMillis(interval); if (intervalMs < MIN_RECONNECT_INTERVAL || intervalMs > Integer.MAX_VALUE) throw new ApplicationError(ApplicationError.INVALID_RECONNECT_INTERVAL); this.reconnectInterval = (int) intervalMs; return this; }
From source file:org.scribe.model.ProxyRequest.java
/** * Sets the read timeout for the underlying {@link HttpURLConnection} * /* w ww.j a v a 2s . com*/ * @param duration duration of the timeout * @param unit unit of time (milliseconds, seconds, etc) */ public void setReadTimeout(final int duration, final TimeUnit unit) { this.readTimeout = unit.toMillis(duration); }