public long extractTimestampMillis(String topic, final byte[] bytes) throws IOException { if (timestampFieldPath != null) { com.google.protobuf.Message decodedMessage = protobufUtil.decodeProtobufOrJsonMessage(topic, bytes); int i = 0; for (; i < timestampFieldPath.length - 1; ++i) { decodedMessage = (com.google.protobuf.Message) decodedMessage .getField(decodedMessage.getDescriptorForType().findFieldByName(timestampFieldPath[i])); } Object timestampObject = decodedMessage .getField(decodedMessage.getDescriptorForType().findFieldByName(timestampFieldPath[i])); if (timestampObject instanceof com.google.protobuf.Timestamp){ return Timestamps.toMillis((com.google.protobuf.Timestamp) timestampObject); }else { return toMillis((Long) timestampObject); } } else { // Assume that the timestamp field is the first field, is required, // and is a uint64. CodedInputStream input = CodedInputStream.newInstance(bytes); // Don't really care about the tag, but need to read it to get, to // the payload. input.readTag(); return toMillis(input.readUInt64()); } } }
public static Date getDateFromTimestamp(Timestamp timestamp) { return new Date(Timestamps.toMillis(timestamp)); }
/** * Convert a Timestamp to the number of milliseconds elapsed from the epoch. * * <p>The result will be rounded down to the nearest millisecond. E.g., if the * timestamp represents "1969-12-31T23:59:59.999999999Z", it will be rounded * to -1 millisecond. * * @deprecated Use {@link Timestamps#toMillis} instead. */ @Deprecated public static long toMillis(Timestamp timestamp) { return Timestamps.toMillis(timestamp); }
public static Date getDateFromTimestamp(Timestamp timestamp) { return new Date(Timestamps.toMillis(timestamp)); }
@Override public Object toSqlValue(Descriptors.FieldDescriptor fieldDescriptor, Object fieldValue) { if (fieldValue instanceof Timestamp) { return new java.sql.Timestamp(Timestamps.toMillis((Timestamp) fieldValue)); } else if (fieldValue instanceof Long || fieldValue instanceof Integer) { return new java.sql.Timestamp(((Number) fieldValue).longValue()); } else if (fieldValue instanceof java.sql.Timestamp) { return fieldValue; } throw new FieldConversionException( "fail to convert to sql value for timestamp field, fieldValue=" + FieldConversionException.toString(fieldValue) + ", sqlValueType=" + getSqlValueType().getName()); }
private void printStats(Map<ClientType, Controller.LoadtestStats> results) { long startMillis = Timestamps.toMillis(Timestamps.add(Client.startTime, Client.burnInDuration)); if (System.currentTimeMillis() < startMillis) { log.info( "Still under burn in time, will start in " + ((startMillis - System.currentTimeMillis()) / 1000) + " seconds."); return; } log.info("==============================================="); results.forEach( (type, stats) -> { log.info("Results for " + type + ":"); log.info("50%: " + LatencyDistribution.getNthPercentile(stats.bucketValues, 50.0)); log.info("99%: " + LatencyDistribution.getNthPercentile(stats.bucketValues, 99.0)); log.info("99.9%: " + LatencyDistribution.getNthPercentile(stats.bucketValues, 99.9)); log.info( "Average throughput: " + new DecimalFormat("#.##").format(stats.getQPS() * messageSize / 1000000.0) + " MB/s"); }); log.info("==============================================="); }
protected Task(StartRequest request, String type, MetricsHandler.MetricName metricName) { this.metricsHandler = new MetricsHandler(request.getProject(), type, metricName); this.burnInTimeMillis = Timestamps.toMillis(Timestamps.add(request.getStartTime(), request.getBurnInDuration())); rateLimiter = RateLimiter.create(request.getRequestRate()); outstandingRequestLimiter = new Semaphore(request.getMaxOutstandingRequests(), false); }
private static boolean shouldContinue(StartRequest request) { // If the test has been running for at least a minute, and we have been idle for a minute, we // should stop. if (System.currentTimeMillis() - Timestamps.toMillis(request.getStartTime()) > MAX_IDLE_MILLIS && System.currentTimeMillis() - task.getLastUpdateMillis() > MAX_IDLE_MILLIS) { return false; } switch (request.getStopConditionsCase()) { case TEST_DURATION: return System.currentTimeMillis() < (request.getStartTime().getSeconds() + request.getBurnInDuration().getSeconds() + request.getTestDuration().getSeconds()) * 1000; case NUMBER_OF_MESSAGES: return task.getNumberOfMessages() < request.getNumberOfMessages(); default: return false; } }
try { Date startDate = new Date(); startDate.setTime(Timestamps.toMillis(Client.startTime)); controller.waitForPublisherClients(); ListTimeSeriesResponse response =
Long timestamp = getLongValue(messageAttributes.get(kafkaMessageTimestampAttribute)); if (timestamp == null){ timestamp = Timestamps.toMillis(message.getPublishTime());
if (isProtobufTimestamp(schema)) { com.google.protobuf.Timestamp timestamp = (com.google.protobuf.Timestamp) value; return Timestamp.toLogical(schema, Timestamps.toMillis(timestamp));