Search in sources :

Example 86 with TimeUnit

use of java.util.concurrent.TimeUnit in project wildfly by wildfly.

the class StatefulTimeoutAnnotationInformationFactory method fromAnnotation.

@Override
protected StatefulTimeoutInfo fromAnnotation(final AnnotationInstance annotationInstance, final PropertyReplacer propertyReplacer) {
    final long value = annotationInstance.value().asLong();
    final AnnotationValue unitValue = annotationInstance.value("unit");
    final TimeUnit unit;
    if (unitValue != null) {
        unit = TimeUnit.valueOf(unitValue.asEnum());
    } else {
        unit = TimeUnit.MINUTES;
    }
    return new StatefulTimeoutInfo(value, unit);
}
Also used : StatefulTimeoutInfo(org.jboss.as.ejb3.component.stateful.StatefulTimeoutInfo) AnnotationValue(org.jboss.jandex.AnnotationValue) TimeUnit(java.util.concurrent.TimeUnit)

Example 87 with TimeUnit

use of java.util.concurrent.TimeUnit in project wildfly by wildfly.

the class TransactionTimeoutAnnotationInformationFactory method fromAnnotation.

@Override
protected Integer fromAnnotation(final AnnotationInstance annotationInstance, final PropertyReplacer propertyReplacer) {
    final long timeout = annotationInstance.value().asLong();
    AnnotationValue unitAnnVal = annotationInstance.value("unit");
    final TimeUnit unit = unitAnnVal != null ? TimeUnit.valueOf(unitAnnVal.asEnum()) : TimeUnit.SECONDS;
    return (int) unit.toSeconds(timeout);
}
Also used : AnnotationValue(org.jboss.jandex.AnnotationValue) TimeUnit(java.util.concurrent.TimeUnit)

Example 88 with TimeUnit

use of java.util.concurrent.TimeUnit in project wildfly by wildfly.

the class BeanExpirationScheduler method schedule.

@Override
public void schedule(I id) {
    Time timeout = this.expiration.getTimeout();
    long value = timeout.getValue();
    if (value >= 0) {
        TimeUnit unit = timeout.getUnit();
        InfinispanEjbLogger.ROOT_LOGGER.tracef("Scheduling stateful session bean %s to expire in %d %s", id, value, unit);
        Runnable task = new ExpirationTask(id);
        // Make sure the expiration future map insertion happens before map removal (during task execution).
        synchronized (task) {
            this.expirationFutures.put(id, this.expiration.getExecutor().schedule(task, value, unit));
        }
    }
}
Also used : TimeUnit(java.util.concurrent.TimeUnit) Time(org.wildfly.clustering.ejb.Time)

Example 89 with TimeUnit

use of java.util.concurrent.TimeUnit in project gerrit by GerritCodeReview.

the class ConfigUtil method getTimeUnit.

/**
   * Parse a numerical time unit, such as "1 minute", from a string.
   *
   * @param valueString the string to parse.
   * @param defaultValue default value to return if no value was set in the configuration file.
   * @param wantUnit the units of {@code defaultValue} and the return value, as well as the units to
   *     assume if the value does not contain an indication of the units.
   * @return the setting, or {@code defaultValue} if not set, expressed in {@code units}.
   */
public static long getTimeUnit(final String valueString, long defaultValue, TimeUnit wantUnit) {
    Matcher m = Pattern.compile("^(0|[1-9][0-9]*)\\s*(.*)$").matcher(valueString);
    if (!m.matches()) {
        return defaultValue;
    }
    String digits = m.group(1);
    String unitName = m.group(2).trim();
    TimeUnit inputUnit;
    int inputMul;
    if ("".equals(unitName)) {
        inputUnit = wantUnit;
        inputMul = 1;
    } else if (match(unitName, "ms", "milliseconds")) {
        inputUnit = TimeUnit.MILLISECONDS;
        inputMul = 1;
    } else if (match(unitName, "s", "sec", "second", "seconds")) {
        inputUnit = TimeUnit.SECONDS;
        inputMul = 1;
    } else if (match(unitName, "m", "min", "minute", "minutes")) {
        inputUnit = TimeUnit.MINUTES;
        inputMul = 1;
    } else if (match(unitName, "h", "hr", "hour", "hours")) {
        inputUnit = TimeUnit.HOURS;
        inputMul = 1;
    } else if (match(unitName, "d", "day", "days")) {
        inputUnit = TimeUnit.DAYS;
        inputMul = 1;
    } else if (match(unitName, "w", "week", "weeks")) {
        inputUnit = TimeUnit.DAYS;
        inputMul = 7;
    } else if (match(unitName, "mon", "month", "months")) {
        inputUnit = TimeUnit.DAYS;
        inputMul = 30;
    } else if (match(unitName, "y", "year", "years")) {
        inputUnit = TimeUnit.DAYS;
        inputMul = 365;
    } else {
        throw notTimeUnit(valueString);
    }
    try {
        return wantUnit.convert(Long.parseLong(digits) * inputMul, inputUnit);
    } catch (NumberFormatException nfe) {
        throw notTimeUnit(valueString);
    }
}
Also used : Matcher(java.util.regex.Matcher) TimeUnit(java.util.concurrent.TimeUnit)

Example 90 with TimeUnit

use of java.util.concurrent.TimeUnit in project android by JetBrains.

the class InstantRunBuilderTest method setUp.

@Before
public void setUp() throws Exception {
    myDevice = mock(IDevice.class);
    when(myDevice.getSerialNumber()).thenReturn("device1-serial");
    myInstalledPatchCache = new InstalledPatchCache();
    myInstantRunContext = mock(InstantRunContext.class);
    when(myInstantRunContext.getInstantRunBuildInfo()).thenReturn(InstantRunBuildInfo.get(BUILD_INFO)).thenReturn(InstantRunBuildInfo.get(BUILD_INFO_RELOAD_DEX));
    when(myInstantRunContext.getApplicationId()).thenReturn(APPLICATION_ID);
    when(myInstantRunContext.getInstalledPatchCache()).thenReturn(myInstalledPatchCache);
    myRunConfigContext = new AndroidRunConfigContext();
    myRunConfigContext.setTargetDevices(DeviceFutures.forDevices(Collections.singletonList(myDevice)));
    myTasksProvider = mock(InstantRunTasksProvider.class);
    when(myTasksProvider.getFullBuildTasks()).thenReturn(ASSEMBLE_TASKS);
    when(myTasksProvider.getCleanAndGenerateSourcesTasks()).thenReturn(CLEAN_TASKS);
    myInstalledApkCache = new InstalledApkCache() {

        @Override
        protected String executeShellCommand(@NotNull IDevice device, @NotNull String cmd, long timeout, @NotNull TimeUnit timeUnit) throws TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException, IOException, InterruptedException {
            return myDumpsysPackageOutput;
        }
    };
    myApk = FileUtil.createTempFile("foo", "apk");
    myTaskRunner = new RecordingTaskRunner();
    myInstantRunClientDelegate = createInstantRunClientDelegate();
    myBuilder = new InstantRunBuilder(myDevice, myInstantRunContext, myRunConfigContext, myTasksProvider, false, myInstalledApkCache, myInstantRunClientDelegate);
}
Also used : AndroidRunConfigContext(com.android.tools.idea.run.AndroidRunConfigContext) IDevice(com.android.ddmlib.IDevice) IOException(java.io.IOException) InstalledPatchCache(com.android.tools.idea.run.InstalledPatchCache) InstalledApkCache(com.android.tools.idea.run.InstalledApkCache) ShellCommandUnresponsiveException(com.android.ddmlib.ShellCommandUnresponsiveException) AdbCommandRejectedException(com.android.ddmlib.AdbCommandRejectedException) TimeUnit(java.util.concurrent.TimeUnit) TimeoutException(com.android.ddmlib.TimeoutException) Before(org.junit.Before)

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