@Override public String toString(Duration value) { if ( value == null ) { return null; } return String.valueOf( value.toNanos() ); }
@Override public String objectToSQLString(Duration value, Dialect dialect) throws Exception { return String.valueOf( value.toNanos() ); }
public VmPauseMonitor( Duration measureInterval, Duration stallAlertThreshold, Log log, JobScheduler jobScheduler, Consumer<VmPauseInfo> listener ) { this.measurementDurationNs = requirePositive( measureInterval.toNanos() ); this.stallAlertThresholdNs = requireNonNegative( stallAlertThreshold.toNanos() ); this.log = requireNonNull( log ); this.jobScheduler = requireNonNull( jobScheduler ); this.listener = requireNonNull( listener ); }
public StandardLockCleanerService(KeyColumnValueStore store, ConsistentKeyLockerSerializer serializer, ExecutorService exec, Duration cooldown, TimestampProvider times) { this.store = store; this.serializer = serializer; this.exec = exec; this.times = times; blocked = CacheBuilder.newBuilder() .expireAfterWrite(cooldown.toNanos(), TimeUnit.NANOSECONDS) .concurrencyLevel(COOLDOWN_CONCURRENCY_LEVEL) .<KeyColumn, Instant>build() .asMap(); }
@Override public void sleepFor(Duration duration) throws InterruptedException { if (duration.isZero()) return; TimeUnit.NANOSECONDS.sleep(duration.toNanos()); }
public FakeClock forward( Duration delta ) { return forward( delta.toNanos(), TimeUnit.NANOSECONDS ); }
@Override public void lock(Duration timeout) { boolean success = false; try { success = super.tryLock(timeout.toNanos(), TimeUnit.NANOSECONDS); } catch (InterruptedException e) { log.warn("Interrupted waiting for lock: {}",e); } if (!success) throw new TitanException("Possible dead lock detected. Waited for transaction lock without success"); }
@Override protected void waitCondition() throws InterruptedException { MessageEnvelope msg = outgoingMsg.poll(maxWaitTime().toNanos(), TimeUnit.NANOSECONDS); if (msg!=null) toSend.add(msg); }
/** * Constructs a Deadline that is a given duration after now. */ public static Deadline fromNow(Duration duration) { return new Deadline(Math.addExact(System.nanoTime(), duration.toNanos())); } }
/** * Specifies that each entry should be automatically removed from the cache once a fixed duration * has elapsed after the entry's creation, or the most recent replacement of its value. * * <p>When {@code duration} is zero, this method hands off to {@link #maximumSize(long) * maximumSize}{@code (0)}, ignoring any otherwise-specified maximum size or weight. This can be * useful in testing, or to disable caching temporarily without a code change. * * <p>Expired entries may be counted in {@link Cache#size}, but will never be visible to read or * write operations. Expired entries are cleaned up as part of the routine maintenance described * in the class javadoc. * * @param duration the length of time after an entry is created that it should be automatically * removed * @return this {@code CacheBuilder} instance (for chaining) * @throws IllegalArgumentException if {@code duration} is negative * @throws IllegalStateException if the time to live or time to idle was already set * @throws ArithmeticException for durations greater than +/- approximately 292 years * @since 25.0 */ @J2ObjCIncompatible @GwtIncompatible // java.time.Duration public CacheBuilder<K, V> expireAfterWrite(java.time.Duration duration) { return expireAfterWrite(duration.toNanos(), TimeUnit.NANOSECONDS); }
/** * Specifies that each entry should be automatically removed from the cache once a fixed duration * has elapsed after the entry's creation, the most recent replacement of its value, or its last * access. Access time is reset by all cache read and write operations (including {@code * Cache.asMap().get(Object)} and {@code Cache.asMap().put(K, V)}), but not by operations on the * collection-views of {@link Cache#asMap}. * * <p>When {@code duration} is zero, this method hands off to {@link #maximumSize(long) * maximumSize}{@code (0)}, ignoring any otherwise-specified maximum size or weight. This can be * useful in testing, or to disable caching temporarily without a code change. * * <p>Expired entries may be counted in {@link Cache#size}, but will never be visible to read or * write operations. Expired entries are cleaned up as part of the routine maintenance described * in the class javadoc. * * @param duration the length of time after an entry is last accessed that it should be * automatically removed * @return this {@code CacheBuilder} instance (for chaining) * @throws IllegalArgumentException if {@code duration} is negative * @throws IllegalStateException if the time to idle or time to live was already set * @throws ArithmeticException for durations greater than +/- approximately 292 years * @since 25.0 */ @J2ObjCIncompatible @GwtIncompatible // java.time.Duration public CacheBuilder<K, V> expireAfterAccess(java.time.Duration duration) { return expireAfterAccess(duration.toNanos(), TimeUnit.NANOSECONDS); }
/** * Specifies that each entry should be automatically removed from the cache once a fixed * duration has elapsed. The expiration policy determines when the entry's age is reset. * * @param duration the length of time after which an entry should be automatically removed * @throws IllegalArgumentException if {@code duration} is negative */ default void setExpiresAfter(@NonNull Duration duration) { // This method will be abstract in version 3.0.0 setExpiresAfter(duration.toNanos(), TimeUnit.NANOSECONDS); }
public Deadline plus(Duration other) { return new Deadline(Math.addExact(timeNanos, other.toNanos())); }
/** * Specifies that the entry should be automatically removed from the cache once the duration has * elapsed. The expiration policy determines when the entry's age is reset. * * @param key the key for the entry being set * @param duration the length of time from now when the entry should be automatically removed * @throws IllegalArgumentException if {@code duration} is negative */ default void setExpiresAfter(@NonNull K key, @NonNull Duration duration) { // This method will be abstract in version 3.0.0 setExpiresAfter(key, duration.toNanos(), TimeUnit.NANOSECONDS); }
return refreshAfterWrite(duration.toNanos(), TimeUnit.NANOSECONDS);
private void markSuccess() { if (wasCallPermitted()) { circuitBreaker.onSuccess(stopWatch.stop().getProcessingDuration().toNanos()); } }
/** * Associates the {@code value} with the {@code key} in this cache. If the cache previously * contained a value associated with the {@code key}, the old value is replaced by the new * {@code value}. This method differs from {@link Cache#put} by substituting the * configured {@link Expiry} with the specified write duration. * * @param key the key with which the specified value is to be associated * @param value value to be associated with the specified key * @param duration the length of time from now when the entry should be automatically removed * @throws IllegalArgumentException if {@code duration} is negative */ default void put(@NonNull K key, @NonNull V value, @NonNull Duration duration) { // This method will be abstract in version 3.0.0 put(key, value, duration.toNanos(), TimeUnit.NANOSECONDS); }
private void markSuccess() { if (wasCallPermitted()) { circuitBreaker.onSuccess(stopWatch.stop().getProcessingDuration().toNanos()); } } }
@Test void shouldConvertNanosOfDayToUTC() { int nanosOfDayLocal = 42; Duration offsetDuration = Duration.ofMinutes( 35 ); long nanosOfDayUTC = TemporalUtil.nanosOfDayToUTC( nanosOfDayLocal, (int) offsetDuration.getSeconds() ); assertEquals( nanosOfDayLocal - offsetDuration.toNanos(), nanosOfDayUTC ); }
@Test void shouldGetNanosOfDayUTC() { LocalTime localTime = LocalTime.of( 14, 19, 18, 123999 ); ZoneOffset offset = ZoneOffset.ofHours( -12 ); OffsetTime time = OffsetTime.of( localTime, offset ); long nanosOfDayUTC = TemporalUtil.getNanosOfDayUTC( time ); long expectedNanosOfDayUTC = Duration.ofSeconds( localTime.toSecondOfDay() ) .minus( offset.getTotalSeconds(), SECONDS ) .toNanos(); assertEquals( expectedNanosOfDayUTC + localTime.getNano(), nanosOfDayUTC ); } }