org.elasticsearch.common.unit.TimeValue.toString()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(11.4k)|赞(0)|评价(0)|浏览(241)

本文整理了Java中org.elasticsearch.common.unit.TimeValue.toString()方法的一些代码示例,展示了TimeValue.toString()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TimeValue.toString()方法的具体详情如下:
包路径:org.elasticsearch.common.unit.TimeValue
类名称:TimeValue
方法名:toString

TimeValue.toString介绍

[英]Returns a String representation of the current TimeValue. Note that this method might produce fractional time values (ex 1.6m) which cannot be parsed by method like TimeValue#parse(String,String,String).
[中]返回当前时间值的字符串表示形式。请注意,此方法可能会产生分数时间值(例如1.6m),无法通过类似于TimeValue#parse(String,String,String)的方法进行解析。

代码示例

代码示例来源:origin: org.elasticsearch/elasticsearch

/**
 * Connects to all remote clusters in a blocking fashion. This should be called on node startup to establish an initial connection
 * to all configured seed nodes.
 */
void initializeRemoteClusters() {
  final TimeValue timeValue = REMOTE_INITIAL_CONNECTION_TIMEOUT_SETTING.get(settings);
  final PlainActionFuture<Void> future = new PlainActionFuture<>();
  Map<String, Tuple<String, List<Tuple<String, Supplier<DiscoveryNode>>>>> seeds =
      RemoteClusterAware.buildRemoteClustersDynamicConfig(settings);
  updateRemoteClusters(seeds, future);
  try {
    future.get(timeValue.millis(), TimeUnit.MILLISECONDS);
  } catch (InterruptedException e) {
    Thread.currentThread().interrupt();
  } catch (TimeoutException ex) {
    logger.warn("failed to connect to remote clusters within {}", timeValue.toString());
  } catch (Exception e) {
    throw new IllegalStateException("failed to connect to remote clusters", e);
  }
}

代码示例来源:origin: org.elasticsearch/elasticsearch

@Override
  public void run() {
    if (logger.isTraceEnabled()) {
      logger.trace("Submitting new rescheduling cluster info update job");
    }
    try {
      threadPool.executor(executorName()).execute(() -> {
        try {
          maybeRefresh();
        } finally { //schedule again after we refreshed
          if (isMaster) {
            if (logger.isTraceEnabled()) {
              logger.trace("Scheduling next run for updating cluster info in: {}", updateFrequency.toString());
            }
            try {
              threadPool.schedule(updateFrequency, executorName(), this);
            } catch (EsRejectedExecutionException ex) {
              logger.debug("Reschedule cluster info service was rejected", ex);
            }
          }
        }
      });
    } catch (EsRejectedExecutionException ex) {
      if (logger.isDebugEnabled()) {
        logger.debug("Couldn't re-schedule cluster info update task - node might be shutting down", ex);
      }
    }
  }
}

代码示例来源:origin: org.elasticsearch/elasticsearch

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
  builder.startObject("adaptive_selection");
  Set<String> allNodeIds = Sets.union(clientOutgoingConnections.keySet(), nodeComputedStats.keySet());
  for (String nodeId : allNodeIds) {
    builder.startObject(nodeId);
    ResponseCollectorService.ComputedNodeStats stats = nodeComputedStats.get(nodeId);
    if (stats != null) {
      long outgoingSearches = clientOutgoingConnections.getOrDefault(nodeId, 0L);
      builder.field("outgoing_searches", outgoingSearches);
      builder.field("avg_queue_size", stats.queueSize);
      if (builder.humanReadable()) {
        builder.field("avg_service_time", new TimeValue((long) stats.serviceTime, TimeUnit.NANOSECONDS).toString());
      }
      builder.field("avg_service_time_ns", (long) stats.serviceTime);
      if (builder.humanReadable()) {
        builder.field("avg_response_time", new TimeValue((long) stats.responseTime, TimeUnit.NANOSECONDS).toString());
      }
      builder.field("avg_response_time_ns", (long) stats.responseTime);
      builder.field("rank", String.format(Locale.ROOT, "%.1f", stats.rank(outgoingSearches)));
    }
    builder.endObject();
  }
  builder.endObject();
  return builder;
}

代码示例来源:origin: org.elasticsearch/elasticsearch

return Long.toString(v.days());
} else {
  return v.toString();

代码示例来源:origin: org.elasticsearch/elasticsearch

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
  builder.startObject(name);
  builder.field(Fields.TYPE, type.getType());
  if (min != -1) {
    builder.field(Fields.MIN, min);
  }
  if (max != -1) {
    builder.field(Fields.MAX, max);
  }
  if (keepAlive != null) {
    builder.field(Fields.KEEP_ALIVE, keepAlive.toString());
  }
  if (queueSize == null) {
    builder.field(Fields.QUEUE_SIZE, -1);
  } else {
    builder.field(Fields.QUEUE_SIZE, queueSize.singles());
  }
  builder.endObject();
  return builder;
}

代码示例来源:origin: org.elasticsearch/elasticsearch

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
  builder.field("node", taskId.getNodeId());
  builder.field("id", taskId.getId());
  builder.field("type", type);
  builder.field("action", action);
  if (status != null) {
    builder.field("status", status, params);
  }
  if (description != null) {
    builder.field("description", description);
  }
  builder.timeField("start_time_in_millis", "start_time", startTime);
  if (builder.humanReadable()) {
    builder.field("running_time", new TimeValue(runningTimeNanos, TimeUnit.NANOSECONDS).toString());
  }
  builder.field("running_time_in_nanos", runningTimeNanos);
  builder.field("cancellable", cancellable);
  if (parentTaskId.isSet()) {
    builder.field("parent_task_id", parentTaskId.toString());
  }
  builder.startObject("headers");
  for(Map.Entry<String, String> attribute : headers.entrySet()) {
    builder.field(attribute.getKey(), attribute.getValue());
  }
  builder.endObject();
  return builder;
}

代码示例来源:origin: org.elasticsearch/elasticsearch

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
  builder.startObject();
  builder.field(TYPE.getPreferredName(), type);
  builder.field(DESCRIPTION.getPreferredName(), description);
  if (builder.humanReadable()) {
    builder.field(NODE_TIME.getPreferredName(), new TimeValue(getTime(), TimeUnit.NANOSECONDS).toString());
  }
  builder.field(NODE_TIME_RAW.getPreferredName(), getTime());
  builder.field(BREAKDOWN.getPreferredName(), timings);
  if (!children.isEmpty()) {
    builder = builder.startArray(CHILDREN.getPreferredName());
    for (ProfileResult child : children) {
      builder = child.toXContent(builder, params);
    }
    builder = builder.endArray();
  }
  builder = builder.endObject();
  return builder;
}

代码示例来源:origin: org.elasticsearch/elasticsearch

@Override
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException {
  builder = builder.startObject();
  builder.field(NAME.getPreferredName(), getName());
  builder.field(REASON.getPreferredName(), getReason());
  if (builder.humanReadable()) {
    builder.field(TIME.getPreferredName(), new TimeValue(getTime(), TimeUnit.NANOSECONDS).toString());
  }
  builder.field(TIME_NANOS.getPreferredName(), getTime());
  if (!children.isEmpty()) {
    builder = builder.startArray(CHILDREN.getPreferredName());
    for (CollectorResult child : children) {
      builder = child.toXContent(builder, params);
    }
    builder = builder.endArray();
  }
  builder = builder.endObject();
  return builder;
}

代码示例来源:origin: apache/servicemix-bundles

/**
 * Sets an enum setting with the provided setting key and enum instance.
 *
 * @param key  The setting key
 * @param enumValue The setting value
 * @return The builder
 */
public Builder put(String key, Enum<?> enumValue) {
  return put(key, enumValue.toString());
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch

/**
 * Sets a time value setting with the provided setting key and value.
 *
 * @param key  The setting key
 * @param timeValue The setting timeValue
 * @return The builder
 */
public Builder put(String key, TimeValue timeValue) {
  return put(key, timeValue.toString());
}

代码示例来源:origin: org.elasticsearch/elasticsearch

keepAlive = poolInfo.getKeepAlive().toString();

代码示例来源:origin: org.elasticsearch/elasticsearch

private void buildRow(Table table, boolean fullId, boolean detailed, DiscoveryNodes discoveryNodes, TaskInfo taskInfo) {
  table.startRow();
  String nodeId = taskInfo.getTaskId().getNodeId();
  DiscoveryNode node = discoveryNodes.get(nodeId);
  table.addCell(taskInfo.getId());
  table.addCell(taskInfo.getAction());
  table.addCell(taskInfo.getTaskId().toString());
  if (taskInfo.getParentTaskId().isSet()) {
    table.addCell(taskInfo.getParentTaskId().toString());
  } else {
    table.addCell("-");
  }
  table.addCell(taskInfo.getType());
  table.addCell(taskInfo.getStartTime());
  table.addCell(FORMATTER.format(Instant.ofEpochMilli(taskInfo.getStartTime())));
  table.addCell(taskInfo.getRunningTimeNanos());
  table.addCell(TimeValue.timeValueNanos(taskInfo.getRunningTimeNanos()).toString());
  // Node information. Note that the node may be null because it has left the cluster between when we got this response and now.
  table.addCell(fullId ? nodeId : Strings.substring(nodeId, 0, 4));
  table.addCell(node == null ? "-" : node.getHostAddress());
  table.addCell(node.getAddress().address().getPort());
  table.addCell(node == null ? "-" : node.getName());
  table.addCell(node == null ? "-" : node.getVersion().toString());
  if (detailed) {
    table.addCell(taskInfo.getDescription());
  }
  table.endRow();
}

代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch

public XContentBuilder timeValueField(String rawFieldName, String readableFieldName, TimeValue timeValue) throws IOException {
  if (humanReadable) {
    field(readableFieldName, timeValue.toString());
  }
  field(rawFieldName, timeValue.millis());
  return this;
}

代码示例来源:origin: harbby/presto-connectors

public XContentBuilder timeValueField(XContentBuilderString rawFieldName, XContentBuilderString readableFieldName, TimeValue timeValue) throws IOException {
  if (humanReadable) {
    field(readableFieldName, timeValue.toString());
  }
  field(rawFieldName, timeValue.millis());
  return this;
}

代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch

public XContentBuilder timeValueField(String rawFieldName, String readableFieldName, long rawTime, TimeUnit timeUnit) throws
    IOException {
  if (humanReadable) {
    field(readableFieldName, new TimeValue(rawTime, timeUnit).toString());
  }
  field(rawFieldName, rawTime);
  return this;
}

代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch

public XContentBuilder timeValueField(String rawFieldName, String readableFieldName, long rawTime) throws IOException {
  if (humanReadable) {
    field(readableFieldName, new TimeValue(rawTime).toString());
  }
  field(rawFieldName, rawTime);
  return this;
}

代码示例来源:origin: harbby/presto-connectors

public XContentBuilder timeValueField(String rawFieldName, String readableFieldName, long rawTime, TimeUnit timeUnit) throws
  IOException {
  if (humanReadable) {
    field(readableFieldName, new TimeValue(rawTime, timeUnit).toString());
  }
  field(rawFieldName, rawTime);
  return this;
}

代码示例来源:origin: harbby/presto-connectors

public XContentBuilder timeValueField(String rawFieldName, String readableFieldName, TimeValue timeValue) throws IOException {
  if (humanReadable) {
    field(readableFieldName, timeValue.toString());
  }
  field(rawFieldName, timeValue.millis());
  return this;
}

代码示例来源:origin: harbby/presto-connectors

public XContentBuilder timeValueField(XContentBuilderString rawFieldName, XContentBuilderString readableFieldName, long rawTime) throws IOException {
  if (humanReadable) {
    field(readableFieldName, new TimeValue(rawTime).toString());
  }
  field(rawFieldName, rawTime);
  return this;
}

代码示例来源:origin: couchbase/couchbase-elasticsearch-connector

private void registerBackfillMetrics() {
 Metrics.gauge("backfill", () -> () -> totalBackfillItems);
 // memoize so the backfill per partition isn't logged twice every time the stats are reported
 final Supplier<Long> remainingBackfillItemsSupplier = Suppliers.memoizeWithExpiration(() -> {
  if (remainingBackfillItems != 0) {
   updateBackfillProgress();
  }
  return remainingBackfillItems;
 }, 250, TimeUnit.MILLISECONDS);
 final Gauge backfillRemainingGauge = Metrics.gauge("backfillRemaining", () -> remainingBackfillItemsSupplier::get);
 Metrics.gauge("backfillEstTimeLeft", () -> () -> {
  final long remaining = (long) backfillRemainingGauge.getValue();
  return new TimeValue((long) (remaining * Metrics.indexTimePerDocument().getSnapshot().getMean()), TimeUnit.NANOSECONDS).toString();
 });
}

相关文章