本文整理了Java中java.time.Clock.instant()
方法的一些代码示例,展示了Clock.instant()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Clock.instant()
方法的具体详情如下:
包路径:java.time.Clock
类名称:Clock
方法名:instant
[英]Gets the current instant of the clock.
This returns an instant representing the current instant as defined by the clock.
[中]获取时钟的当前时刻。
它返回一个表示时钟定义的当前瞬间的瞬间。
代码示例来源:origin: GoogleContainerTools/jib
Timer(Clock clock, @Nullable Timer parentTimer) {
this.clock = clock;
this.parentTimer = parentTimer;
startTime = clock.instant();
lapStartTime = startTime;
}
代码示例来源:origin: GoogleContainerTools/jib
/**
* Captures the time since last lap or creation, and resets the start time.
*
* @return the duration of the last lap, or since creation
*/
Duration lap() {
Instant now = clock.instant();
Duration duration = Duration.between(lapStartTime, now);
lapStartTime = now;
return duration;
}
代码示例来源:origin: GoogleContainerTools/jib
/**
* Gets the total elapsed time since creation.
*
* @return the total elapsed time
*/
Duration getElapsedTime() {
return Duration.between(startTime, clock.instant());
}
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Check for expired sessions and remove them. Typically such checks are
* kicked off lazily during calls to {@link #createWebSession() create} or
* {@link #retrieveSession retrieve}, no less than 60 seconds apart.
* This method can be called to force a check at a specific time.
* @since 5.0.8
*/
public void removeExpiredSessions() {
this.expiredSessionChecker.removeExpiredSessions(this.clock.instant());
}
代码示例来源:origin: spring-projects/spring-framework
public Mono<WebSession> updateLastAccessTime(WebSession session) {
return Mono.fromSupplier(() -> {
Assert.isInstanceOf(InMemoryWebSession.class, session);
((InMemoryWebSession) session).updateLastAccessTime(this.clock.instant());
return session;
});
}
代码示例来源:origin: spring-projects/spring-framework
private void checkMaxSessionsLimit() {
if (sessions.size() >= maxSessions) {
expiredSessionChecker.removeExpiredSessions(clock.instant());
if (sessions.size() >= maxSessions) {
throw new IllegalStateException("Max sessions limit reached: " + sessions.size());
}
}
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public boolean isExpired() {
return isExpired(clock.instant());
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public Mono<WebSession> retrieveSession(String id) {
Instant now = this.clock.instant();
this.expiredSessionChecker.checkIfNecessary(now);
InMemoryWebSession session = this.sessions.get(id);
if (session == null) {
return Mono.empty();
}
else if (session.isExpired(now)) {
this.sessions.remove(id);
return Mono.empty();
}
else {
session.updateLastAccessTime(now);
return Mono.just(session);
}
}
代码示例来源:origin: org.springframework/spring-web
private void checkMaxSessionsLimit() {
if (sessions.size() >= maxSessions) {
expiredSessionChecker.removeExpiredSessions(clock.instant());
if (sessions.size() >= maxSessions) {
throw new IllegalStateException("Max sessions limit reached: " + sessions.size());
}
}
}
代码示例来源:origin: org.springframework/spring-web
public Mono<WebSession> updateLastAccessTime(WebSession session) {
return Mono.fromSupplier(() -> {
Assert.isInstanceOf(InMemoryWebSession.class, session);
((InMemoryWebSession) session).updateLastAccessTime(this.clock.instant());
return session;
});
}
代码示例来源:origin: org.springframework/spring-web
/**
* Check for expired sessions and remove them. Typically such checks are
* kicked off lazily during calls to {@link #createWebSession() create} or
* {@link #retrieveSession retrieve}, no less than 60 seconds apart.
* This method can be called to force a check at a specific time.
* @since 5.0.8
*/
public void removeExpiredSessions() {
this.expiredSessionChecker.removeExpiredSessions(this.clock.instant());
}
代码示例来源:origin: org.springframework/spring-web
@Override
public boolean isExpired() {
return isExpired(clock.instant());
}
代码示例来源:origin: Alluxio/alluxio
/**
* @param timeCtx the time context to use for time-based operations
* @param maxDuration the maximum duration
*/
public TimeBoundedRetry(TimeContext timeCtx, Duration maxDuration) {
mClock = timeCtx.getClock();
mSleeper = timeCtx.getSleeper();
mMaxDuration = maxDuration;
mStartTime = mClock.instant();
mEndTime = mStartTime.plus(mMaxDuration);
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public Mono<WebSession> createWebSession() {
Instant now = this.clock.instant();
this.expiredSessionChecker.checkIfNecessary(now);
return Mono.fromSupplier(() -> new InMemoryWebSession(now));
}
代码示例来源:origin: neo4j/neo4j
public void initializeTransaction()
{
this.transaction = Clock.fixed( system.instant(), timezone() );
this.statement = null;
}
代码示例来源:origin: neo4j/neo4j
public void initializeStatement()
{
if ( this.statement == null ) // this is the first statement in the transaction, use the transaction time
{
this.statement = this.transaction;
}
else // this is not the first statement in the transaction, initialize with a new time
{
this.statement = Clock.fixed( system.instant(), timezone() );
}
}
代码示例来源:origin: spring-projects/spring-security
private boolean hasTokenExpired(OAuth2AuthorizedClient authorizedClient) {
Instant now = this.clock.instant();
Instant expiresAt = authorizedClient.getAccessToken().getExpiresAt();
if (now.isAfter(expiresAt.minus(this.accessTokenExpiresSkew))) {
return true;
}
return false;
}
代码示例来源:origin: spring-projects/spring-security
private boolean hasTokenExpired(OAuth2AuthorizedClient authorizedClient) {
Instant now = this.clock.instant();
Instant expiresAt = authorizedClient.getAccessToken().getExpiresAt();
if (now.isAfter(expiresAt.minus(this.accessTokenExpiresSkew))) {
return true;
}
return false;
}
代码示例来源:origin: org.springframework/spring-web
@Override
public Mono<WebSession> createWebSession() {
Instant now = this.clock.instant();
this.expiredSessionChecker.checkIfNecessary(now);
return Mono.fromSupplier(() -> new InMemoryWebSession(now));
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void set_created_after_from_created_since() {
Date now = DateUtils.parseDateTime("2013-07-25T07:35:00+0100");
when(clock.instant()).thenReturn(now.toInstant());
when(clock.getZone()).thenReturn(ZoneOffset.UTC);
SearchRequest request = new SearchRequest()
.setCreatedInLast("1y2m3w4d");
assertThat(underTest.create(request).createdAfter().date()).isEqualTo(DateUtils.parseDateTime("2012-04-30T07:35:00+0100"));
assertThat(underTest.create(request).createdAfter().inclusive()).isTrue();
}
内容来源于网络,如有侵权,请联系作者删除!