當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。