org.threeten.bp.Instant.isBefore()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(3.1k)|赞(0)|评价(0)|浏览(171)

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

Instant.isBefore介绍

[英]Checks if this instant is before the specified instant.

The comparison is based on the time-line position of the instants.
[中]检查此瞬间是否在指定瞬间之前。
比较是基于瞬间的时间线位置。

代码示例

代码示例来源:origin: googleapis/google-cloud-java

private PooledSession findSessionToKeepAlive(
  Queue<PooledSession> queue, Instant keepAliveThreshold) {
 Iterator<PooledSession> iterator = queue.iterator();
 while (iterator.hasNext()) {
  PooledSession session = iterator.next();
  if (session.lastUseTime.isBefore(keepAliveThreshold)) {
   iterator.remove();
   return session;
  }
 }
 return null;
}

代码示例来源:origin: googleapis/google-cloud-java

@Override
 public void run() {
  try {
   if (ackHandler
     .totalExpiration
     .plusSeconds(messageDeadlineSeconds.get())
     .isBefore(now())) {
    // Message expired while waiting. We don't extend these messages anymore,
    // so it was probably sent to someone else. Don't work on it.
    // Don't nack it either, because we'd be nacking someone else's message.
    ackHandler.forget();
    return;
   }
   receiver.receiveMessage(message, consumer);
  } catch (Exception e) {
   response.setException(e);
  }
 }
});

代码示例来源:origin: com.google.cloud/google-cloud-spanner

private PooledSession findSessionToKeepAlive(
  Queue<PooledSession> queue, Instant keepAliveThreshold) {
 Iterator<PooledSession> iterator = queue.iterator();
 while (iterator.hasNext()) {
  PooledSession session = iterator.next();
  if (session.lastUseTime.isBefore(keepAliveThreshold)) {
   iterator.remove();
   return session;
  }
 }
 return null;
}

代码示例来源:origin: com.google.api/gax-httpjson

@Override
public ApiFuture<ResponseT> futureCall(RequestT request, ApiCallContext inputContext) {
 Preconditions.checkNotNull(request);
 HttpJsonCallContext context = HttpJsonCallContext.createDefault().nullToSelf(inputContext);
 @Nullable Instant deadline = context.getDeadline();
 // Try to convert the timeout into a deadline and use it if it occurs before the actual deadline
 if (context.getTimeout() != null) {
  @Nonnull Instant newDeadline = Instant.now().plus(context.getTimeout());
  if (deadline == null || newDeadline.isBefore(deadline)) {
   deadline = newDeadline;
  }
 }
 HttpJsonCallOptions callOptions =
   HttpJsonCallOptions.newBuilder()
     .setDeadline(deadline)
     .setCredentials(context.getCredentials())
     .build();
 return context.getChannel().issueFutureUnaryCall(callOptions, request, descriptor);
}

代码示例来源:origin: googleapis/gax-java

@Override
public ApiFuture<ResponseT> futureCall(RequestT request, ApiCallContext inputContext) {
 Preconditions.checkNotNull(request);
 HttpJsonCallContext context = HttpJsonCallContext.createDefault().nullToSelf(inputContext);
 @Nullable Instant deadline = context.getDeadline();
 // Try to convert the timeout into a deadline and use it if it occurs before the actual deadline
 if (context.getTimeout() != null) {
  @Nonnull Instant newDeadline = Instant.now().plus(context.getTimeout());
  if (deadline == null || newDeadline.isBefore(deadline)) {
   deadline = newDeadline;
  }
 }
 HttpJsonCallOptions callOptions =
   HttpJsonCallOptions.newBuilder()
     .setDeadline(deadline)
     .setCredentials(context.getCredentials())
     .build();
 return context.getChannel().issueFutureUnaryCall(callOptions, request, descriptor);
}

相关文章