当前位置: 首页>>代码示例>>Java>>正文


Java Duration.isNegative方法代码示例

本文整理汇总了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;
        }
    }
}
 
开发者ID:Sixt,项目名称:ja-micro,代码行数:25,代码来源:RetryBackOffFunction.java

示例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);
    }
}
 
开发者ID:Bandwidth,项目名称:async-sqs,代码行数:8,代码来源:SqsConsumer.java

示例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;
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:18,代码来源:Validate.java

示例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;
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:19,代码来源:Validate.java

示例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;
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:15,代码来源:ValidationUtils.java

示例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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:HttpRequestBuilderImpl.java

示例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;
}
 
开发者ID:Panzer1119,项目名称:Supreme-Bot,代码行数:6,代码来源:Timeout.java

示例8: timeoutStreamOf

import java.time.Duration; //导入方法依赖的package包/类
private static Flowable<?> timeoutStreamOf(Duration timeout) {
    if (timeout.isNegative()) {
        return never();
    }
    return timer(timeout.toMillis(), MILLISECONDS);
}
 
开发者ID:streamingpool,项目名称:streamingpool-core,代码行数:7,代码来源:BufferSpecification.java

示例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);
    }
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:7,代码来源:DurationIs.java

示例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");
    }
}
 
开发者ID:openmicroscopy,项目名称:omero-ms-queue,代码行数:7,代码来源:FutureTimepoint.java

示例11: isExpired

import java.time.Duration; //导入方法依赖的package包/类
@Override
public boolean isExpired(SqsMessage<?> sqsMessage) {
    Duration timeUntilExpiration = maxAge.minus(sqsMessage.getMessageAge());
    return timeUntilExpiration.isNegative();
}
 
开发者ID:Bandwidth,项目名称:async-sqs,代码行数:6,代码来源:ConstantExpirationStrategy.java

示例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();
}
 
开发者ID:rubenswagner,项目名称:L2J-Global,代码行数:6,代码来源:ClanHall.java

示例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);

}
 
开发者ID:after-the-sunrise,项目名称:cryptotrader,代码行数:23,代码来源:LastEstimator.java

示例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.");
    }
}
 
开发者ID:Mercateo,项目名称:sqs-utils,代码行数:47,代码来源:LongRunningMessageHandler.java


注:本文中的java.time.Duration.isNegative方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。