org.apache.flink.api.common.time.Time.toMilliseconds()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(9.1k)|赞(0)|评价(0)|浏览(152)

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

Time.toMilliseconds介绍

[英]Converts the time interval to milliseconds.
[中]

代码示例

代码示例来源:origin: apache/flink

@Override
public String toString() {
  return toMilliseconds() + " ms";
}

代码示例来源:origin: apache/flink

public static String getFromHTTP(String url, Time timeout) throws Exception {
  final URL u = new URL(url);
  LOG.info("Accessing URL " + url + " as URL: " + u);
  final long deadline = timeout.toMilliseconds() + System.currentTimeMillis();
  while (System.currentTimeMillis() <= deadline) {
    HttpURLConnection connection = (HttpURLConnection) u.openConnection();
    connection.setConnectTimeout(100000);
    connection.connect();
    if (Objects.equals(HttpResponseStatus.SERVICE_UNAVAILABLE, HttpResponseStatus.valueOf(connection.getResponseCode()))) {
      // service not available --> Sleep and retry
      LOG.debug("Web service currently not available. Retrying the request in a bit.");
      Thread.sleep(100L);
    } else {
      InputStream is;
      if (connection.getResponseCode() >= 400) {
        // error!
        LOG.warn("HTTP Response code when connecting to {} was {}", url, connection.getResponseCode());
        is = connection.getErrorStream();
      } else {
        is = connection.getInputStream();
      }
      return IOUtils.toString(is, ConfigConstants.DEFAULT_CHARSET);
    }
  }
  throw new TimeoutException("Could not get HTTP response in time since the service is still unavailable.");
}

代码示例来源:origin: apache/flink

boolean expired(long lastTimestamp, long currentTimestamp) {
    return lastTimestamp + stateDesc.getTtlConfig().getTtl().toMilliseconds() <= currentTimestamp;
  }
}

代码示例来源:origin: apache/flink

void grantLeadership() throws Exception {
    rmLeaderSessionId = UUID.randomUUID();
    rmLeaderElectionService.isLeader(rmLeaderSessionId).get(TIMEOUT.toMilliseconds(), TimeUnit.MILLISECONDS);
  }
}

代码示例来源:origin: apache/flink

long timeout = DEFAULT_KAFKA_TRANSACTION_TIMEOUT.toMilliseconds();
checkState(timeout < Integer.MAX_VALUE && timeout > 0, "timeout does not fit into 32 bit integer");
this.producerConfig.put(ProducerConfig.TRANSACTION_TIMEOUT_CONFIG, (int) timeout);

代码示例来源:origin: apache/flink

long timeout = DEFAULT_KAFKA_TRANSACTION_TIMEOUT.toMilliseconds();
checkState(timeout < Integer.MAX_VALUE && timeout > 0, "timeout does not fit into 32 bit integer");
this.producerConfig.put(ProducerConfig.TRANSACTION_TIMEOUT_CONFIG, (int) timeout);

代码示例来源:origin: apache/flink

private Collection<JobID> waitForRunningJobs(ClusterClient<?> clusterClient, Time timeout) throws ExecutionException, InterruptedException {
  return FutureUtils.retrySuccessfulWithDelay(
      CheckedSupplier.unchecked(clusterClient::listJobs),
      Time.milliseconds(50L),
      Deadline.fromNow(Duration.ofMillis(timeout.toMilliseconds())),
      jobs -> !jobs.isEmpty(),
      TestingUtils.defaultScheduledExecutor())
    .get()
    .stream()
    .map(JobStatusMessage::getJobId)
    .collect(Collectors.toList());
}

代码示例来源:origin: apache/flink

private StateTtlConfig(
  UpdateType updateType,
  StateVisibility stateVisibility,
  TimeCharacteristic timeCharacteristic,
  Time ttl,
  CleanupStrategies cleanupStrategies) {
  this.updateType = Preconditions.checkNotNull(updateType);
  this.stateVisibility = Preconditions.checkNotNull(stateVisibility);
  this.timeCharacteristic = Preconditions.checkNotNull(timeCharacteristic);
  this.ttl = Preconditions.checkNotNull(ttl);
  this.cleanupStrategies = cleanupStrategies;
  Preconditions.checkArgument(ttl.toMilliseconds() > 0,
    "TTL is expected to be positive");
}

代码示例来源:origin: apache/flink

private void waitUntilAllSlotsAreUsed(DispatcherGateway dispatcherGateway, Time timeout) throws ExecutionException, InterruptedException {
  FutureUtils.retrySuccessfulWithDelay(
    () -> dispatcherGateway.requestClusterOverview(timeout),
    Time.milliseconds(50L),
    Deadline.fromNow(Duration.ofMillis(timeout.toMilliseconds())),
    clusterOverview -> clusterOverview.getNumTaskManagersConnected() >= 1 &&
      clusterOverview.getNumSlotsAvailable() == 0 &&
      clusterOverview.getNumSlotsTotal() == 2,
    TestingUtils.defaultScheduledExecutor())
    .get();
}

代码示例来源:origin: apache/flink

/**
   * Checks that in a streaming use case where checkpointing is enabled and the number
   * of execution retries is set to 42 and the delay to 1337, fixed delay restarting is used.
   */
  @Test
  public void testFixedRestartingWhenCheckpointingAndExplicitExecutionRetriesNonZero() throws Exception {
    StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    env.enableCheckpointing(500);
    env.setNumberOfExecutionRetries(42);
    env.getConfig().setExecutionRetryDelay(1337);

    env.fromElements(1).print();

    StreamGraph graph = env.getStreamGraph();
    JobGraph jobGraph = graph.getJobGraph();

    RestartStrategies.RestartStrategyConfiguration restartStrategy =
      jobGraph.getSerializedExecutionConfig().deserializeValue(getClass().getClassLoader()).getRestartStrategy();

    Assert.assertNotNull(restartStrategy);
    Assert.assertTrue(restartStrategy instanceof RestartStrategies.FixedDelayRestartStrategyConfiguration);
    Assert.assertEquals(42, ((RestartStrategies.FixedDelayRestartStrategyConfiguration) restartStrategy).getRestartAttempts());
    Assert.assertEquals(1337, ((RestartStrategies.FixedDelayRestartStrategyConfiguration) restartStrategy).getDelayBetweenAttemptsInterval().toMilliseconds());
  }
}

代码示例来源:origin: com.alibaba.blink/flink-runtime

/**
 * Shuts the given rpc service down and waits for its termination.
 *
 * @param rpcService to shut down
 * @param timeout for this operation
 * @throws InterruptedException if the operation has been interrupted
 * @throws ExecutionException if a problem occurred
 * @throws TimeoutException if a timeout occurred
 */
public static void terminateRpcService(RpcService rpcService, Time timeout) throws InterruptedException, ExecutionException, TimeoutException {
  rpcService.stopService().get(timeout.toMilliseconds(), TimeUnit.MILLISECONDS);
}

代码示例来源:origin: org.apache.flink/flink-runtime

/**
 * Shuts the given rpc service down and waits for its termination.
 *
 * @param rpcService to shut down
 * @param timeout for this operation
 * @throws InterruptedException if the operation has been interrupted
 * @throws ExecutionException if a problem occurred
 * @throws TimeoutException if a timeout occurred
 */
public static void terminateRpcService(RpcService rpcService, Time timeout) throws InterruptedException, ExecutionException, TimeoutException {
  rpcService.stopService().get(timeout.toMilliseconds(), TimeUnit.MILLISECONDS);
}

代码示例来源:origin: org.apache.flink/flink-runtime

public void shutdown(Time timeout) {
  final CompletableFuture<Void> shutDownFuture = shutdownInternally(timeout);
  try {
    shutDownFuture.get(timeout.toMilliseconds(), TimeUnit.MILLISECONDS);
    LOG.info("Rest endpoint shutdown complete.");
  } catch (Exception e) {
    LOG.warn("Rest endpoint shutdown failed.", e);
  }
}

代码示例来源:origin: org.apache.flink/flink-runtime_2.11

/**
 * Shuts the given rpc service down and waits for its termination.
 *
 * @param rpcService to shut down
 * @param timeout for this operation
 * @throws InterruptedException if the operation has been interrupted
 * @throws ExecutionException if a problem occurred
 * @throws TimeoutException if a timeout occurred
 */
public static void terminateRpcService(RpcService rpcService, Time timeout) throws InterruptedException, ExecutionException, TimeoutException {
  rpcService.stopService().get(timeout.toMilliseconds(), TimeUnit.MILLISECONDS);
}

代码示例来源:origin: com.alibaba.blink/flink-runtime

@Override
public boolean canRestart() {
  if (isRestartTimestampsQueueFull()) {
    Long now = System.currentTimeMillis();
    Long earliestFailure = restartTimestampsDeque.peek();
    return (now - earliestFailure) > failuresInterval.toMilliseconds();
  } else {
    return true;
  }
}

代码示例来源:origin: org.apache.flink/flink-runtime_2.11

@Override
public boolean canRestart() {
  if (isRestartTimestampsQueueFull()) {
    Long now = System.currentTimeMillis();
    Long earliestFailure = restartTimestampsDeque.peek();
    return (now - earliestFailure) > failuresInterval.toMilliseconds();
  } else {
    return true;
  }
}

代码示例来源:origin: org.apache.flink/flink-runtime_2.10

@Override
public boolean canRestart() {
  if (isRestartTimestampsQueueFull()) {
    Long now = System.currentTimeMillis();
    Long earliestFailure = restartTimestampsDeque.peek();
    return (now - earliestFailure) > failuresInterval.toMilliseconds();
  } else {
    return true;
  }
}

代码示例来源:origin: com.alibaba.blink/flink-runtime

/**
 * Sends the message to the RPC endpoint and returns a future containing
 * its response.
 *
 * @param message to send to the RPC endpoint
 * @param timeout time to wait until the response future is failed with a {@link TimeoutException}
 * @return Response future
 */
protected CompletableFuture<?> ask(Object message, Time timeout) {
  return FutureUtils.toJava(
    Patterns.ask(rpcEndpoint, message, timeout.toMilliseconds()));
}

代码示例来源:origin: org.apache.flink/flink-runtime

public ActorGatewayKvStateLocationOracle(
    ActorGateway jobManagerActorGateway,
    Time timeout) {
  this.jobManagerActorGateway = Preconditions.checkNotNull(jobManagerActorGateway);
  Preconditions.checkNotNull(timeout);
  this.timeout = FiniteDuration.apply(timeout.toMilliseconds(), TimeUnit.MILLISECONDS);
}

代码示例来源:origin: org.apache.flink/flink-runtime

@Override
public CompletableFuture<MetricDumpSerialization.MetricSerializationResult> queryMetrics(Time timeout) {
  return FutureUtils.toJava(
    Patterns.ask(queryServiceActorRef, MetricQueryService.getCreateDump(), timeout.toMilliseconds())
      .mapTo(ClassTag$.MODULE$.apply(MetricDumpSerialization.MetricSerializationResult.class))
  );
}

相关文章