@Override public void run() { try { if (extendDeadline.getAndSet(false)) { int newDeadlineSec = computeDeadlineSeconds(); messageDeadlineSeconds.set(newDeadlineSec); extendDeadlines(); // Don't bother cancelling this when we stop. It'd just set an atomic boolean. systemExecutor.schedule( setExtendDeadline, newDeadlineSec - ackExpirationPadding.getSeconds(), TimeUnit.SECONDS); } processOutstandingAckOperations(); } catch (Throwable t) { // Catch everything so that one run failing doesn't prevent subsequent runs. logger.log(Level.WARNING, "failed to run periodic job", t); } } },
private DurationRule(Duration duration) { this.builder = com.google.protobuf.Duration.newBuilder() .setSeconds(duration.getSeconds()) .setNanos(duration.getNano()); }
double firstByteSec = (double) (firstByte.getNano()) / NS_PER_SECOND + firstByte.getSeconds(); double totalSec = (double) (total.getNano()) / NS_PER_SECOND + total.getSeconds();
assertEquals(2, ((UnionRule) columnFamilyById.get("mf1").getGCRule()).getRulesList().size()); assertEquals( 1000, ((DurationRule) columnFamilyById.get("mf2").getGCRule()).getMaxAge().getSeconds()); assertEquals( 20000, ((DurationRule) columnFamilyById.get("mf2").getGCRule()).getMaxAge().getNano()); 2, ((IntersectionRule) columnFamilyById.get("mf3").getGCRule()).getRulesList().size()); assertEquals( 360, ((DurationRule) columnFamilyById.get("mf4").getGCRule()).getMaxAge().getSeconds()); assertNotNull(columnFamilyById.get("mf7")); } finally {
.setSeconds(latency.getSeconds()) .setNanos(latency.getNano()) .build());
/** * Returns a copy of this duration with the specified duration added. * <p> * This instance is immutable and unaffected by this method call. * * @param duration the duration to add, positive or negative, not null * @return a {@code Duration} based on this duration with the specified duration added, not null * @throws ArithmeticException if numeric overflow occurs */ public Duration plus(Duration duration) { return plus(duration.getSeconds(), duration.getNano()); }
/** * Returns a copy of this duration with the specified duration added. * <p> * This instance is immutable and unaffected by this method call. * * @param duration the duration to add, positive or negative, not null * @return a {@code Duration} based on this duration with the specified duration added, not null * @throws ArithmeticException if numeric overflow occurs */ public Duration plus(Duration duration) { return plus(duration.getSeconds(), duration.getNano()); }
@Override public void serialize(Duration duration, JsonGenerator generator, SerializerProvider provider) throws IOException { if (useTimestamp(provider)) { if (provider.isEnabled(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS)) { generator.writeNumber(DecimalUtils.toBigDecimal( duration.getSeconds(), duration.getNano() )); } else { generator.writeNumber(duration.toMillis()); } } else { // Does not look like we can make any use of DateTimeFormatter here? generator.writeString(duration.toString()); } }
private DurationRule(Duration duration) { this.builder = com.google.protobuf.Duration.newBuilder() .setSeconds(duration.getSeconds()) .setNanos(duration.getNano()); }
/** * Returns a copy of this duration with the specified duration subtracted. * <p> * This instance is immutable and unaffected by this method call. * * @param duration the duration to subtract, positive or negative, not null * @return a {@code Duration} based on this duration with the specified duration subtracted, not null * @throws ArithmeticException if numeric overflow occurs */ public Duration minus(Duration duration) { long secsToSubtract = duration.getSeconds(); int nanosToSubtract = duration.getNano(); if (secsToSubtract == Long.MIN_VALUE) { return plus(Long.MAX_VALUE, -nanosToSubtract).plus(1, 0); } return plus(-secsToSubtract, -nanosToSubtract); }
/** * Returns a copy of this duration with the specified duration subtracted. * <p> * This instance is immutable and unaffected by this method call. * * @param duration the duration to subtract, positive or negative, not null * @return a {@code Duration} based on this duration with the specified duration subtracted, not null * @throws ArithmeticException if numeric overflow occurs */ public Duration minus(Duration duration) { long secsToSubtract = duration.getSeconds(); int nanosToSubtract = duration.getNano(); if (secsToSubtract == Long.MIN_VALUE) { return plus(Long.MAX_VALUE, -nanosToSubtract).plus(1, 0); } return plus(-secsToSubtract, -nanosToSubtract); }
} else if (validOffsets.size() == 0) { ZoneOffsetTransition trans = rules.getTransition(isoLDT); localDateTime = localDateTime.plusSeconds(trans.getDuration().getSeconds()); offset = trans.getOffsetAfter(); } else {
} else if (validOffsets.size() == 0) { ZoneOffsetTransition trans = rules.getTransition(isoLDT); localDateTime = localDateTime.plusSeconds(trans.getDuration().getSeconds()); offset = trans.getOffsetAfter(); } else {
@Test public void testTimeoutToDeadlineConversion() { MethodDescriptor<Color, Money> descriptor = FakeServiceGrpc.METHOD_RECOGNIZE; @SuppressWarnings("unchecked") ClientCall<Color, Money> mockClientCall = Mockito.mock(ClientCall.class); @SuppressWarnings("unchecked") ClientCall.Listener<Money> mockListener = Mockito.mock(ClientCall.Listener.class); @SuppressWarnings("unchecked") Channel mockChannel = Mockito.mock(ManagedChannel.class); ArgumentCaptor<CallOptions> capturedCallOptions = ArgumentCaptor.forClass(CallOptions.class); Mockito.when(mockChannel.newCall(Mockito.eq(descriptor), capturedCallOptions.capture())) .thenReturn(mockClientCall); Duration timeout = Duration.ofSeconds(10); Deadline minExpectedDeadline = Deadline.after(timeout.getSeconds(), TimeUnit.SECONDS); GrpcCallContext context = GrpcCallContext.createDefault().withChannel(mockChannel).withTimeout(timeout); GrpcClientCalls.newCall(descriptor, context).start(mockListener, new Metadata()); Deadline maxExpectedDeadline = Deadline.after(timeout.getSeconds(), TimeUnit.SECONDS); Truth.assertThat(capturedCallOptions.getValue().getDeadline()).isAtLeast(minExpectedDeadline); Truth.assertThat(capturedCallOptions.getValue().getDeadline()).isAtMost(maxExpectedDeadline); }
if (unitDur.getSeconds() > SECONDS_PER_DAY) { throw new DateTimeException("Unit is too large to be used for truncation");
if (unitDur.getSeconds() > SECONDS_PER_DAY) { throw new DateTimeException("Unit is too large to be used for truncation");
if (unitDur.getSeconds() > LocalTime.SECONDS_PER_DAY) { throw new DateTimeException("Unit is too large to be used for truncation");
Deadline minExpectedDeadline = Deadline.after(timeout.getSeconds(), TimeUnit.SECONDS); Deadline maxExpectedDeadline = Deadline.after(timeout.getSeconds(), TimeUnit.SECONDS);
return plusSeconds(duration.getSeconds()).plusNanos(duration.getNano());
return plusSeconds(duration.getSeconds()).plusNanos(duration.getNano());