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);
}
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);
}
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));
}
}
}
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);
}
}
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);
}
Aggregations