List of usage examples for java.util.concurrent TimeUnit toMillis
public long toMillis(long duration)
From source file:org.panthercode.arctic.core.processing.modules.impl.Timer.java
/** * Set a new time limit.//from w w w . j av a2s. c o m * * @param unit time unit * @param duration new time limit * @throws IllegalArgumentException */ public void setMaximalDuration(TimeUnit unit, long duration) throws IllegalArgumentException { this.setMaximalDuration(unit.toMillis(duration)); }
From source file:com.alertlogic.aws.kinesis.test1.producer.HttpReferrerKinesisPutter.java
/** * Send a fixed number of HTTP Referrer pairs to Amazon Kinesis. This sends them sequentially. * If you require more throughput consider using multiple {@link HttpReferrerKinesisPutter}s. * * @param n The number of pairs to send to Amazon Kinesis. * @param delayBetweenRecords The amount of time to wait in between sending records. If this is <= 0 it will be * ignored.// ww w .ja v a2 s. c om * @param unitForDelay The unit of time to interpret the provided delay as. * * @throws InterruptedException Interrupted while waiting to send the next pair. */ public void sendPairs(long n, long delayBetweenRecords, TimeUnit unitForDelay) throws InterruptedException { for (int i = 0; i < n && !Thread.currentThread().isInterrupted(); i++) { sendPair(); Thread.sleep(unitForDelay.toMillis(delayBetweenRecords)); } }
From source file:com.alertlogic.aws.analytics.poc.RecordKinesisPutter.java
/** * Send a fixed number of records to Amazon Kinesis. This sends them sequentially. * If you require more throughput consider using multiple {@link RecordKinesisPutter}s. * * @param n The number of records to send to Amazon Kinesis. * @param delayBetweenRecords The amount of time to wait in between sending records. If this is <= 0 it will be * ignored./* w w w . j a v a 2 s . com*/ * @param unitForDelay The unit of time to interpret the provided delay as. * * @throws InterruptedException Interrupted while waiting to send the next record. */ public void sendRecords(long n, long delayBetweenRecords, TimeUnit unitForDelay) throws InterruptedException { for (int i = 0; i < n && !Thread.currentThread().isInterrupted(); i++) { sendRecord(); Thread.sleep(unitForDelay.toMillis(delayBetweenRecords)); } }
From source file:tools.devnull.boteco.client.rest.impl.DefaultRestConfiguration.java
@Override public RestConfiguration timeoutIn(int amount, TimeUnit unit) { int timeout = (int) unit.toMillis(amount); this.request.setConfig(RequestConfig.custom().setConnectionRequestTimeout(timeout) .setConnectTimeout(timeout).setSocketTimeout(timeout).build()); return this; }
From source file:com.ocean.common.concurrent.ext.BasicFuture.java
@Override public synchronized T get(final long timeout, final TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { Validate.notNull(unit, "Time unit"); 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 {// w w w . j a v a 2s . c om for (;;) { wait(waitTime); if (this.completed) { return getResult(); } else { waitTime = msecs - (System.currentTimeMillis() - startTime); if (waitTime <= 0) { throw new TimeoutException(); } } } } }
From source file:tools.devnull.boteco.client.rest.impl.DefaultRestConfiguration.java
@Override public RestConfiguration waitAfterRetry(int amount, TimeUnit unit) { this.retryInterval = (int) unit.toMillis(amount); return this; }
From source file:org.dllearner.algorithms.qtl.operations.lgg.AbstractLGGGenerator.java
@Override public void setTimeout(long timeout, TimeUnit timeoutUnits) { this.timeoutMillis = timeoutUnits.toMillis(timeout); }
From source file:com.alertlogic.aws.kinesis.test1.producer.HttpReferrerKinesisPutter.java
/** * Continuously sends HTTP Referrer pairs to Amazon Kinesis sequentially. This will only stop if interrupted. If you * require more throughput consider using multiple {@link HttpReferrerKinesisPutter}s. * * @param delayBetweenRecords The amount of time to wait in between sending records. If this is <= 0 it will be * ignored./*from w w w. ja v a2s. c om*/ * @param unitForDelay The unit of time to interpret the provided delay as. * * @throws InterruptedException Interrupted while waiting to send the next pair. */ public void sendPairsIndefinitely(long delayBetweenRecords, TimeUnit unitForDelay) throws InterruptedException { while (!Thread.currentThread().isInterrupted()) { sendPair(); if (delayBetweenRecords > 0) { Thread.sleep(unitForDelay.toMillis(delayBetweenRecords)); } } }
From source file:org.apache.pulsar.client.impl.ConsumerBuilderImpl.java
@Override public ConsumerBuilder<T> ackTimeout(long ackTimeout, TimeUnit timeUnit) { checkArgument(timeUnit.toMillis(ackTimeout) >= MIN_ACK_TIMEOUT_MILLIS, "Ack timeout should be should be greater than " + MIN_ACK_TIMEOUT_MILLIS + " ms"); conf.setAckTimeoutMillis(timeUnit.toMillis(ackTimeout)); return this; }
From source file:org.spout.api.chat.completion.CompletionFuture.java
@Override public CompletionResponse get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { if (cancelled) { return result.get(); }// ww w . j a v a 2s .c om timeout = unit.toMillis(timeout); long startTime = System.currentTimeMillis(); while (result.get() == null && System.currentTimeMillis() - timeout < startTime) { // Not completely exact, but should be close enough unless the server is running stupidly slowly. wait(timeout); } return result.get(); }