use of java.util.concurrent.TimeUnit in project hazelcast by hazelcast.
the class ClientScheduledExecutorProxy method scheduleOnMember.
private <V> IScheduledFuture<V> scheduleOnMember(String name, Member member, TaskDefinition definition) {
TimeUnit unit = definition.getUnit();
Data commandData = getSerializationService().toData(definition.getCommand());
ClientMessage request = ScheduledExecutorSubmitToAddressCodec.encodeRequest(getName(), member.getAddress(), definition.getType().getId(), definition.getName(), commandData, unit.toMillis(definition.getInitialDelay()), unit.toMillis(definition.getPeriod()));
try {
new ClientInvocation(getClient(), request, member.getAddress()).invoke().get();
} catch (Exception e) {
throw rethrow(e);
}
return createFutureProxy(member.getAddress(), name);
}
use of java.util.concurrent.TimeUnit in project gitblit by gitblit.
the class LdapAuthProvider method getSynchronizationPeriodInMilliseconds.
private long getSynchronizationPeriodInMilliseconds() {
String period = settings.getString(Keys.realm.ldap.syncPeriod, null);
if (StringUtils.isEmpty(period)) {
period = settings.getString("realm.ldap.ldapCachePeriod", null);
if (StringUtils.isEmpty(period)) {
period = "5 MINUTES";
} else {
logger.warn("realm.ldap.ldapCachePeriod is obsolete!");
logger.warn(MessageFormat.format("Please set {0}={1} in gitblit.properties!", Keys.realm.ldap.syncPeriod, period));
settings.overrideSetting(Keys.realm.ldap.syncPeriod, period);
}
}
try {
final String[] s = period.split(" ", 2);
long duration = Math.abs(Long.parseLong(s[0]));
TimeUnit timeUnit = TimeUnit.valueOf(s[1]);
return timeUnit.toMillis(duration);
} catch (RuntimeException ex) {
throw new IllegalArgumentException(Keys.realm.ldap.syncPeriod + " must have format '<long> <TimeUnit>' where <TimeUnit> is one of 'MILLISECONDS', 'SECONDS', 'MINUTES', 'HOURS', 'DAYS'");
}
}
use of java.util.concurrent.TimeUnit in project gephi by gephi.
the class DynamicSettingsPanel method refreshWindowTimeUnit.
private void refreshWindowTimeUnit() {
TimeUnit tu = getSelectedTimeUnit(windowTimeUnitCombo.getModel());
try {
Integer value = Integer.parseInt(windowTextField.getText());
long newValue = tu.convert(value, windowTimeUnit);
windowTextField.setText("" + newValue);
windowTimeUnit = tu;
} catch (Exception e) {
}
}
use of java.util.concurrent.TimeUnit in project guava by google.
the class Futures method lazyTransform.
/**
* Like {@link #transform(ListenableFuture, Function)} except that the transformation {@code
* function} is invoked on each call to {@link Future#get() get()} on the returned future.
*
* <p>The returned {@code Future} reflects the input's cancellation state directly, and any
* attempt to cancel the returned Future is likewise passed through to the input Future.
*
* <p>Note that calls to {@linkplain Future#get(long, TimeUnit) timed get} only apply the timeout
* to the execution of the underlying {@code Future}, <em>not</em> to the execution of the
* transformation function.
*
* <p>The primary audience of this method is callers of {@code transform} who don't have a {@code
* ListenableFuture} available and do not mind repeated, lazy function evaluation.
*
* @param input The future to transform
* @param function A Function to transform the results of the provided future to the results of
* the returned future.
* @return A future that returns the result of the transformation.
* @since 10.0
*/
// TODO
@GwtIncompatible
public static <I, O> Future<O> lazyTransform(final Future<I> input, final Function<? super I, ? extends O> function) {
checkNotNull(input);
checkNotNull(function);
return new Future<O>() {
@Override
public boolean cancel(boolean mayInterruptIfRunning) {
return input.cancel(mayInterruptIfRunning);
}
@Override
public boolean isCancelled() {
return input.isCancelled();
}
@Override
public boolean isDone() {
return input.isDone();
}
@Override
public O get() throws InterruptedException, ExecutionException {
return applyTransformation(input.get());
}
@Override
public O get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
return applyTransformation(input.get(timeout, unit));
}
private O applyTransformation(I input) throws ExecutionException {
try {
return function.apply(input);
} catch (Throwable t) {
throw new ExecutionException(t);
}
}
};
}
use of java.util.concurrent.TimeUnit in project guava by google.
the class Stopwatch method toString.
/** Returns a string representation of the current elapsed time. */
@Override
public String toString() {
long nanos = elapsedNanos();
TimeUnit unit = chooseUnit(nanos);
double value = (double) nanos / NANOSECONDS.convert(1, unit);
// Too bad this functionality is not exposed as a regular method call
return Platform.formatCompact4Digits(value) + " " + abbreviate(unit);
}
Aggregations