Search in sources :

Example 51 with TimeUnit

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);
}
Also used : TimeUnit(java.util.concurrent.TimeUnit) Data(com.hazelcast.nio.serialization.Data) ClientInvocation(com.hazelcast.client.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage)

Example 52 with TimeUnit

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'");
    }
}
Also used : TimeUnit(java.util.concurrent.TimeUnit)

Example 53 with TimeUnit

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) {
    }
}
Also used : TimeUnit(java.util.concurrent.TimeUnit)

Example 54 with TimeUnit

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);
            }
        }
    };
}
Also used : ImmediateFailedFuture(com.google.common.util.concurrent.ImmediateFuture.ImmediateFailedFuture) ImmediateFailedCheckedFuture(com.google.common.util.concurrent.ImmediateFuture.ImmediateFailedCheckedFuture) ImmediateSuccessfulFuture(com.google.common.util.concurrent.ImmediateFuture.ImmediateSuccessfulFuture) ImmediateCancelledFuture(com.google.common.util.concurrent.ImmediateFuture.ImmediateCancelledFuture) Future(java.util.concurrent.Future) ListFuture(com.google.common.util.concurrent.CollectionFuture.ListFuture) ImmediateSuccessfulCheckedFuture(com.google.common.util.concurrent.ImmediateFuture.ImmediateSuccessfulCheckedFuture) TimeUnit(java.util.concurrent.TimeUnit) ExecutionException(java.util.concurrent.ExecutionException) GwtIncompatible(com.google.common.annotations.GwtIncompatible)

Example 55 with TimeUnit

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);
}
Also used : TimeUnit(java.util.concurrent.TimeUnit)

Aggregations

TimeUnit (java.util.concurrent.TimeUnit)190 Test (org.junit.Test)28 ExecutionException (java.util.concurrent.ExecutionException)16 IOException (java.io.IOException)11 TimeoutException (java.util.concurrent.TimeoutException)11 Future (java.util.concurrent.Future)10 HashMap (java.util.HashMap)7 TimeSpec (com.linkedin.thirdeye.api.TimeSpec)6 ArrayList (java.util.ArrayList)6 TimeValue (org.elasticsearch.common.unit.TimeValue)6 DataType (com.linkedin.pinot.common.data.FieldSpec.DataType)5 File (java.io.File)5 HashSet (java.util.HashSet)5 Matcher (java.util.regex.Matcher)5 WaitUntilGatewaySenderFlushedCoordinatorJUnitTest (org.apache.geode.internal.cache.wan.WaitUntilGatewaySenderFlushedCoordinatorJUnitTest)5 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)5 TimeGranularity (com.linkedin.thirdeye.api.TimeGranularity)4 GwtIncompatible (com.google.common.annotations.GwtIncompatible)3 RestException (com.linkedin.r2.message.rest.RestException)3 Map (java.util.Map)3