001/** 002 * Powerunit - A JDK1.8 test framework 003 * Copyright (C) 2014 Mathieu Boretti. 004 * 005 * This file is part of Powerunit 006 * 007 * Powerunit is free software: you can redistribute it and/or modify 008 * it under the terms of the GNU General Public License as published by 009 * the Free Software Foundation, either version 3 of the License, or 010 * (at your option) any later version. 011 * 012 * Powerunit is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 015 * GNU General Public License for more details. 016 * 017 * You should have received a copy of the GNU General Public License 018 * along with Powerunit. If not, see <http://www.gnu.org/licenses/>. 019 */ 020package ch.powerunit.extensions.async.lang; 021 022import static java.util.Objects.requireNonNull; 023 024import java.time.Duration; 025import java.util.concurrent.CompletableFuture; 026import java.util.concurrent.TimeUnit; 027 028/** 029 * Fourth Step of the builder of {@link CompletableFuture} to specify the amount 030 * of time between the retry. 031 * 032 * @param <T> 033 * The type of result of the {@link CompletableFuture} 034 * 035 */ 036public interface WaitResultBuilder4<T> { 037 /** 038 * Specify the amount of time between retry. 039 * 040 * @param value 041 * the ms delay 042 * @return {@link WaitResultBuilder5 the next step of the builder} 043 * @since 1.0.0 044 */ 045 WaitResultBuilder5<T> everyMs(long value); 046 047 /** 048 * Specify to retry every minute. 049 * 050 * @return {@link WaitResultBuilder5 the next step of the builder} 051 * @since 1.0.0 052 */ 053 default WaitResultBuilder5<T> everyMinute() { 054 return every(Duration.ofMinutes(1)); 055 } 056 057 /** 058 * Specify to retry every second. 059 * 060 * @return {@link WaitResultBuilder5 the next step of the builder} 061 * @since 1.0.0 062 */ 063 default WaitResultBuilder5<T> everySecond() { 064 return every(Duration.ofSeconds(1)); 065 } 066 067 /** 068 * Specify the amount of time between retry. 069 * 070 * @param value 071 * the amount 072 * @param unit 073 * the time unit 074 * @return {@link WaitResultBuilder5 the next step of the builder} 075 * @see TimeUnit 076 */ 077 default WaitResultBuilder5<T> every(int value, TimeUnit unit) { 078 return everyMs(requireNonNull(unit, "unit can't be null").toMillis(value)); 079 } 080 081 /** 082 * Specify the amount of time between retry. 083 * 084 * @param delay 085 * the duration to be used 086 * @return {@link WaitResultBuilder5 the next step of the builder} 087 * @since 1.0.0 088 * @see Duration 089 */ 090 default WaitResultBuilder5<T> every(Duration delay) { 091 return everyMs(requireNonNull(delay, "delay can't be null").toMillis()); 092 } 093 094 /** 095 * Repeat as fast as possible. 096 * 097 * @return {@link WaitResultBuilder5 the next step of the builder} 098 * @since 1.0.0 099 */ 100 default WaitResultBuilder5<T> asFastAsPossible() { 101 return everyMs(1); 102 } 103 104}