StringBuilder toString(StringBuilder b) { // TODO(user): Convert all internal toString(StringBuilder) methods to return StringBuilder. switch (mode) { case STRONG: return b.append("strong"); case READ_TIMESTAMP: return b.append("exact_timestamp: ").append(timestamp.toString()); case MIN_READ_TIMESTAMP: return b.append("min_read_timestamp: ").append(timestamp.toString()); case EXACT_STALENESS: return b.append("exact_staleness: ").append(Durations.toString(staleness)); case MAX_STALENESS: return b.append("max_staleness: ").append(Durations.toString(staleness)); default: throw new AssertionError("Unexpected mode: " + mode); } }
private static long durationToUnits(Duration duration, TimeUnit units) { // TODO(user): Handle overflow. switch (units) { case NANOSECONDS: return Durations.toNanos(duration); case MICROSECONDS: return Durations.toMicros(duration); default: return units.convert(Durations.toMillis(duration), TimeUnit.MILLISECONDS); } } }
private static Duration createDuration(long num, TimeUnit units) { switch (units) { case NANOSECONDS: return Durations.fromNanos(num); case MICROSECONDS: return Durations.fromMicros(num); default: return Durations.fromMillis(units.toMillis(num)); } }
/** * Parse from a string to produce a duration. * * @return A Duration parsed from the string. * @throws ParseException if parsing fails. * @deprecated Use {@link Durations#parse} instead. */ @Deprecated public static Duration parseDuration(String value) throws ParseException { return Durations.parse(value); }
static long extractRetryDelay(Throwable cause) { if (cause != null) { Metadata trailers = Status.trailersFromThrowable(cause); if (trailers != null && trailers.containsKey(KEY_RETRY_INFO)) { RetryInfo retryInfo = trailers.get(KEY_RETRY_INFO); if (retryInfo.hasRetryDelay()) { return Durations.toMillis(retryInfo.getRetryDelay()); } } } return -1L; } }
/** * Create a Duration from the number of milliseconds. * * @deprecated Use {@link Durations#fromMillis} instead. */ @Deprecated public static Duration createDurationFromMillis(long milliseconds) { return Durations.fromMillis(milliseconds); }
/** * Create a Duration from the number of microseconds. * * @deprecated Use {@link Durations#fromMicros} instead. */ @Deprecated public static Duration createDurationFromMicros(long microseconds) { return Durations.fromMicros(microseconds); }
/** * Convert a Duration to the number of nanoseconds. * * @deprecated Use {@link Durations#toNanos} instead. */ @Deprecated public static long toNanos(Duration duration) { return Durations.toNanos(duration); }
/** * Create a Duration from the number of nanoseconds. * * @deprecated Use {@link Durations#fromNanos} instead. */ @Deprecated public static Duration createDurationFromNanos(long nanoseconds) { return Durations.fromNanos(nanoseconds); }
/** * Convert a Duration to the number of microseconds.The result will be * rounded towards 0 to the nearest microseconds. E.g., if the duration * represents -1 nanosecond, it will be rounded to 0. * * @deprecated Use {@link Durations#toMicros} instead. */ @Deprecated public static long toMicros(Duration duration) { return Durations.toMicros(duration); }
private void mergeDuration(JsonElement json, Message.Builder builder) throws InvalidProtocolBufferException { try { Duration value = Durations.parse(json.getAsString()); builder.mergeFrom(value.toByteString()); } catch (ParseException e) { throw new InvalidProtocolBufferException("Failed to parse duration: " + json); } }
/** * Convert a Duration to the number of milliseconds.The result will be * rounded towards 0 to the nearest millisecond. E.g., if the duration * represents -1 nanosecond, it will be rounded to 0. * * @deprecated Use {@link Durations#toMillis} instead. */ @Deprecated public static long toMillis(Duration duration) { return Durations.toMillis(duration); }
try { if (value.isEmpty()) { return Durations.fromMillis(0); millis = -millis; return Durations.fromMillis(millis); } catch (Exception e) { throw new ParameterException(
@Override public void serialize( Duration duration, JsonGenerator generator, SerializerProvider serializerProvider ) throws IOException { generator.writeString(Durations.toString(duration)); } }
private void mergeDuration(JsonElement json, Message.Builder builder) throws InvalidProtocolBufferException { try { Duration value = Durations.parse(json.getAsString()); builder.mergeFrom(value.toByteString()); } catch (ParseException e) { throw new InvalidProtocolBufferException("Failed to parse duration: " + json); } }
private static long durationToUnits(Duration duration, TimeUnit units) { // TODO(user): Handle overflow. switch (units) { case NANOSECONDS: return Durations.toNanos(duration); case MICROSECONDS: return Durations.toMicros(duration); default: return units.convert(Durations.toMillis(duration), TimeUnit.MILLISECONDS); } } }
private KafkaPublisherTask(StartRequest request) { super(request, "kafka", MetricsHandler.MetricName.PUBLISH_ACK_LATENCY); this.topic = request.getTopic(); this.payload = LoadTestRunner.createMessage(request.getMessageSize()); this.batchSize = request.getPublishBatchSize(); Properties props = new Properties(); props.putAll(new ImmutableMap.Builder<>() .put("max.block.ms", "30000") .put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer") .put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer") .put("acks", "all") .put("bootstrap.servers", request.getKafkaOptions().getBroker()) .put("buffer.memory", Integer.toString(1000 * 1000 * 1000)) // 1 GB // 10M, high enough to allow for duration to control batching .put("batch.size", Integer.toString(10 * 1000 * 1000)) .put("linger.ms", Long.toString(Durations.toMillis(request.getPublishBatchDuration()))) .build() ); this.publisher = new KafkaProducer<>(props); }
private static Duration createDuration(long num, TimeUnit units) { switch (units) { case NANOSECONDS: return Durations.fromNanos(num); case MICROSECONDS: return Durations.fromMicros(num); default: return Durations.fromMillis(units.toMillis(num)); } }
/** * Convert Duration to string format. The string format will contains 3, 6, * or 9 fractional digits depending on the precision required to represent * the exact Duration value. For example: "1s", "1.010s", "1.000000100s", * "-3.100s" The range that can be represented by Duration is from * -315,576,000,000 to +315,576,000,000 inclusive (in seconds). * * @return The string representation of the given duration. * @throws IllegalArgumentException if the given duration is not in the valid * range. * @deprecated Use {@link Durations#toString} instead. */ @Deprecated public static String toString(Duration duration) { return Durations.toString(duration); }
private void mergeDuration(JsonElement json, Message.Builder builder) throws InvalidProtocolBufferException { try { Duration value = Durations.parse(json.getAsString()); builder.mergeFrom(value.toByteString()); } catch (ParseException e) { throw new InvalidProtocolBufferException("Failed to parse duration: " + json); } }