本文整理汇总了Java中java.time.Duration.isNegative方法的典型用法代码示例。如果您正苦于以下问题:Java Duration.isNegative方法的具体用法?Java Duration.isNegative怎么用?Java Duration.isNegative使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.Duration
的用法示例。
在下文中一共展示了Duration.isNegative方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import java.time.Duration; //导入方法依赖的package包/类
default void execute(int retryCounter) {
Duration timeout = timeout(retryCounter);
if (timeout == null || timeout.isNegative()) {
throw new IllegalArgumentException("Retry timeout cannot be null or negative.");
}
long startTime = System.currentTimeMillis();
long endTime = startTime + timeout.toMillis();
// we are in a while loop here to protect against spurious interrupts
while (!Thread.currentThread().isInterrupted()) {
long now = System.currentTimeMillis();
if (now >= endTime) {
break;
}
try {
Thread.sleep(endTime - now);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
// we should probably quit if we are interrupted?
return;
}
}
}
示例2: checkIfBackoffDelayNeeded
import java.time.Duration; //导入方法依赖的package包/类
void checkIfBackoffDelayNeeded() {
Duration delay = backoffStrategy.getDelayTime(failureAverage.getAverage());
if (!delay.isZero() && !delay.isNegative()) {
backoffEndTime = Clock.systemUTC().instant().plus(delay);
manager.scheduleTask(new UpdateTimerTask(), delay);
}
}
示例3: isPositive
import java.time.Duration; //导入方法依赖的package包/类
/**
* Asserts that the given duration is positive (non-negative and non-zero).
*
* @param duration Number to validate
* @param fieldName Field name to display in exception message if not positive.
* @return Duration if positive.
*/
public static Duration isPositive(Duration duration, String fieldName) {
if (duration == null) {
throw new IllegalArgumentException(String.format("%s cannot be null", fieldName));
}
if (duration.isNegative() || duration.isZero()) {
throw new IllegalArgumentException(String.format("%s must be positive", fieldName));
}
return duration;
}
示例4: isNotNegative
import java.time.Duration; //导入方法依赖的package包/类
/**
* Asserts that the given duration is positive (non-negative and non-zero).
*
* @param duration Number to validate
* @param fieldName Field name to display in exception message if not positive.
* @return Duration if positive.
*/
public static Duration isNotNegative(Duration duration, String fieldName) {
if (duration == null) {
throw new IllegalArgumentException(String.format("%s cannot be null", fieldName));
}
if (duration.isNegative()) {
throw new IllegalArgumentException(String.format("%s must not be negative", fieldName));
}
return duration;
}
示例5: assertIsPositive
import java.time.Duration; //导入方法依赖的package包/类
/**
* Asserts that the given duration is positive (non-negative and non-zero).
*
* @param duration Number to validate
* @param fieldName Field name to display in exception message if not positive.
* @return Duration if positive.
*/
public static Duration assertIsPositive(Duration duration, String fieldName) {
assertNotNull(duration, fieldName);
if (duration.isNegative() || duration.isZero()) {
throw new IllegalArgumentException(String.format("%s must be positive", fieldName));
}
return duration;
}
示例6: timeout
import java.time.Duration; //导入方法依赖的package包/类
@Override
public HttpRequest.Builder timeout(Duration duration) {
requireNonNull(duration);
if (duration.isNegative() || Duration.ZERO.equals(duration))
throw new IllegalArgumentException("Invalid duration: " + duration);
this.duration = duration;
return this;
}
示例7: Timeout
import java.time.Duration; //导入方法依赖的package包/类
public Timeout(Instant start, Duration duration, Runnable run_after_timeout) {
this.start = start;
this.duration = duration.isNegative() ? null : duration;
this.run_after_timeout = run_after_timeout;
}
示例8: timeoutStreamOf
import java.time.Duration; //导入方法依赖的package包/类
private static Flowable<?> timeoutStreamOf(Duration timeout) {
if (timeout.isNegative()) {
return never();
}
return timer(timeout.toMillis(), MILLISECONDS);
}
示例9: validate
import java.time.Duration; //导入方法依赖的package包/类
@Override
public void validate(Duration value, @Nullable Node node) throws InvalidXMLException {
if(value.isNegative()) {
throw new InvalidXMLException("Time cannot be negative", node);
}
}
示例10: check
import java.time.Duration; //导入方法依赖的package包/类
private static void check(Duration timeSpanFromNow) {
requireNonNull(timeSpanFromNow, "timeSpanFromNow");
if (timeSpanFromNow.isNegative()) {
throw new IllegalArgumentException("negative time span");
}
}
示例11: isExpired
import java.time.Duration; //导入方法依赖的package包/类
@Override
public boolean isExpired(SqsMessage<?> sqsMessage) {
Duration timeUntilExpiration = maxAge.minus(sqsMessage.getMessageAge());
return timeUntilExpiration.isNegative();
}
示例12: getCostFailDay
import java.time.Duration; //导入方法依赖的package包/类
public int getCostFailDay()
{
final Duration failDay = Duration.between(Instant.ofEpochMilli(getPaidUntil()), Instant.now());
return failDay.isNegative() ? 0 : (int) failDay.toDays();
}
示例13: calculateConfidence
import java.time.Duration; //导入方法依赖的package包/类
@VisibleForTesting
BigDecimal calculateConfidence(Instant time, Instant now) {
Duration duration = Duration.between(time, now);
if (duration.isZero() || duration.isNegative()) {
return ONE;
}
// Number from 0 to 29 (= 100 years)
double scaled = Math.log(duration.toMillis());
// Number from 0.00 to 0.79
double multiplied = scaled * Math.E / 100;
// Number from 100.00 to 0.21
double confidence = 1 - multiplied;
// Sanitize in case if +3000 years...
return BigDecimal.valueOf(confidence).max(ZERO).setScale(SCALE, HALF_UP);
}
示例14: LongRunningMessageHandler
import java.time.Duration; //导入方法依赖的package包/类
LongRunningMessageHandler(@NonNull ScheduledExecutorService timeoutExtensionExecutor,
int maxNumberOfMessages, int numberOfThreads,
@NonNull MessageHandlingRunnableFactory messageHandlingRunnableFactory,
@NonNull VisibilityTimeoutExtenderFactory timeoutExtenderFactory,
@NonNull MessageWorkerWithHeaders<I, O> worker, @NonNull Queue queue,
@NonNull FinishedMessageCallback<I, O> finishedMessageCallback,
@NonNull Duration timeUntilVisibilityTimeoutExtension,
@NonNull Duration awaitShutDown) {
if (timeUntilVisibilityTimeoutExtension.isZero() || timeUntilVisibilityTimeoutExtension
.isNegative()) {
throw new IllegalArgumentException("the timeout has to be > 0");
}
this.timeoutExtensionExecutor = timeoutExtensionExecutor;
this.messageHandlingRunnableFactory = messageHandlingRunnableFactory;
this.timeoutExtenderFactory = timeoutExtenderFactory;
this.worker = worker;
this.queue = queue;
this.finishedMessageCallback = finishedMessageCallback;
this.timeUntilVisibilityTimeoutExtension = timeUntilVisibilityTimeoutExtension;
messageProcessingExecutor = new ThreadPoolTaskExecutor();
messageProcessingExecutor.setMaxPoolSize(numberOfThreads);
messageProcessingExecutor.setCorePoolSize(numberOfThreads);
/*
* Since we only accept new messages if one slot in the messagesInProcessing-Set
* / executor is free we can schedule at least one message for instant execution
* while (maxNumberOfMessages - 1) will be put into the queue
*/
messageProcessingExecutor.setQueueCapacity(maxNumberOfMessages - 1);
messageProcessingExecutor.setAwaitTerminationSeconds((int) awaitShutDown.getSeconds());
if (awaitShutDown.getSeconds() > 0) {
Runtime.getRuntime().addShutdownHook(new Thread(messageProcessingExecutor::shutdown));
}
messageProcessingExecutor.afterPropertiesSet();
messagesInProcessing = new SetWithUpperBound<>(numberOfThreads);
if (queue.getDefaultVisibilityTimeout().minusSeconds(5).compareTo(
timeUntilVisibilityTimeoutExtension) < 0) {
throw new IllegalStateException("The extension interval of "
+ timeUntilVisibilityTimeoutExtension.getSeconds()
+ " is too close to the VisibilityTimeout of " + queue
.getDefaultVisibilityTimeout().getSeconds()
+ " seconds of the queue, has to be at least 5 seconds less.");
}
}