本文整理了Java中org.threeten.bp.Instant.now()
方法的一些代码示例,展示了Instant.now()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Instant.now()
方法的具体详情如下:
包路径:org.threeten.bp.Instant
类名称:Instant
方法名:now
[英]Obtains the current instant from the system clock.
This will query the Clock#systemUTC() to obtain the current instant.
Using this method will prevent the ability to use an alternate time-source for testing because the clock is effectively hard-coded.
[中]
代码示例来源:origin: JakeWharton/ThreeTenABP
public Instant now() {
return Instant.now();
}
}
代码示例来源:origin: googleapis/google-cloud-java
Instant instant() {
return Instant.now();
}
}
代码示例来源:origin: com.google.cloud/google-cloud-spanner
Instant instant() {
return Instant.now();
}
}
代码示例来源:origin: alexvoronov/geonetworking
private Instant timeInstantNow() {
return Instant.now(); // Add clock here for non-real-time.
}
代码示例来源:origin: alexvoronov/geonetworking
/** Returns the nearest to now instant that will have given amount of TAI millis since 2004. */
public static Instant millisMod32ToInstant(int intMillisX) {
long millisX = Long.parseLong(Integer.toBinaryString(intMillisX), 2); // unsigned int...
Instant now = Instant.now();
long millisNow = instantToTaiMillisSince2004Mod32(now);
long delta = millisNow - millisX;
// Small positive delta is what we expect.
// Small negative delta is fine too, it would mean that the packet came from the future,
// which can be explained by our clock being a little behind.
// Huge negative delta is from previous mod32, and should be changed to small positive.
// Huge positive delta might come from a packet a little from the future and next mod32,
// we want instead a small negative delta.
if (delta < -(1L << 31)) { delta += (1L << 32); }
if (delta > (1L << 31)) { delta -= (1L << 32); }
Instant instantX = now.minusMillis(delta);
return instantX;
}
代码示例来源:origin: alexvoronov/geonetworking
@Override public LongPositionVector getLatestPosition() {
Optional<Address> emptyAddress = Optional.empty();
return new LongPositionVector(emptyAddress,
Instant.now(),
currentPosition,
true,
speedMetersPerSecond,
headingDegreesFromNorth);
}
}
代码示例来源:origin: alexvoronov/geonetworking
/** Returns GPSd position until the first move is called. after which it never asks gpsd. */
@Override public LongPositionVector getLatestPosition() {
logger.trace("position provider request to gpsd client with current position {}", currentPosition);
Optional<Address> emptyAddress = Optional.empty();
return (currentPosition == null) ? super.getLatestPosition() :
new LongPositionVector(emptyAddress,
Instant.now(),
currentPosition,
true,
speedMetersPerSecond,
headingDegreesFromNorth);
}
}
代码示例来源:origin: alexvoronov/geonetworking
@Override public LongPositionVector getLatestPosition() {
return new LongPositionVector(emptyAddress, Instant.now(),
new Position(lat, lon), isPositionConfident, 0, 0);
}
};
代码示例来源:origin: alexvoronov/geonetworking
@Override public LongPositionVector getLatestPosition() {
return new LongPositionVector(emptyAddress, Instant.now(),
new Position(lat, lon), isPositionConfident, 0, 0);
}
};
代码示例来源:origin: jeffdcamp/dbtools-android
@Test
public void testNow() throws Exception {
System.out.println("Date: " + new Date().getTime());
System.out.println("Joda: " + DateTime.now().getMillis());
System.out.println("JSR310: " + Instant.now().toEpochMilli());
}
代码示例来源:origin: alexvoronov/geonetworking
logger.info("Sending first CAM");
send(cam);
lastSend = Instant.now();
lastSendLowFreq = Instant.now();
lastSendPos = lpv;
} else {
long deltaTime = Duration.between(lastSend, Instant.now()).toMillis();
long lowFreqDeltaTime = Duration.between(lastSendLowFreq, Instant.now()).toMillis();
LongPositionVector lpv = position.getLatestPosition();
if (farEnough(lastSendPos, lpv)) {
logger.info("Sending CAM" + (withLowFreq ? " with Low Freq container" : ""));
send(cam);
lastSend = Instant.now();
lastSendPos = lpv;
if (withLowFreq) { lastSendLowFreq = lastSend; }
代码示例来源:origin: WireGuard/wireguard-android
synchronized (lock) {
if (Duration.between(lastResolution, Instant.now()).toMinutes() > 1) {
try {
lastResolution = Instant.now();
} catch (final UnknownHostException e) {
resolved = null;
代码示例来源:origin: alexvoronov/geonetworking
public void updateFromForwardedMessage(Address address, LongPositionVector position) {
final Entry oldEntry = gnMap.get(address);
final Entry entry = (oldEntry == null ? new Entry.Builder() : new Entry.Builder(oldEntry))
.address(address)
.position(position)
.timestamp(Instant.now())
.create();
logger.debug("Adding non-(SHB/BEACON) entry {}", address.toString());
putAndSchedule(entry);
}
代码示例来源:origin: alexvoronov/geonetworking
public void updateFromDirectMessage(final Address address, final MacAddress macAddress, final LongPositionVector position) {
final Entry oldEntry = gnMap.get(address);
final Entry entry = (oldEntry == null ? new Entry.Builder() : new Entry.Builder(oldEntry))
.address(address)
.macAddress(macAddress)
.position(position)
.isNeighbour(true)
.timestamp(Instant.now())
.create();
logger.debug("Adding direct neighbour {}", address.toString());
putAndSchedule(entry);
}
代码示例来源: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);
}
代码示例来源:origin: googleapis/gax-java
@Test
public void testTimeout() {
HttpJsonChannel mockChannel = Mockito.mock(HttpJsonChannel.class);
String expectedRequest = "fake";
HttpJsonDirectCallable<String, String> callable = new HttpJsonDirectCallable<>(API_DESCRIPTOR);
// Mock the channel that captures the call options
ArgumentCaptor<HttpJsonCallOptions> capturedCallOptions =
ArgumentCaptor.forClass(HttpJsonCallOptions.class);
Mockito.when(
mockChannel.issueFutureUnaryCall(
capturedCallOptions.capture(),
Mockito.anyString(),
Mockito.any(ApiMethodDescriptor.class)))
.thenReturn(SettableApiFuture.create());
// Compose the call context
Duration timeout = Duration.ofSeconds(10);
Instant minExpectedDeadline = Instant.now().plus(timeout);
HttpJsonCallContext callContext =
HttpJsonCallContext.createDefault().withChannel(mockChannel).withTimeout(timeout);
callable.futureCall(expectedRequest, callContext);
Instant maxExpectedDeadline = Instant.now().plus(timeout);
// Verify that the timeout was converted into a deadline
assertThat(capturedCallOptions.getValue().getDeadline()).isAtLeast(minExpectedDeadline);
assertThat(capturedCallOptions.getValue().getDeadline()).isAtMost(maxExpectedDeadline);
}
代码示例来源:origin: googleapis/gax-java
@Test
public void testTimeoutBeforeDeadline() {
HttpJsonChannel mockChannel = Mockito.mock(HttpJsonChannel.class);
String expectedRequest = "fake";
HttpJsonDirectCallable<String, String> callable = new HttpJsonDirectCallable<>(API_DESCRIPTOR);
// Mock the channel that captures the call options
ArgumentCaptor<HttpJsonCallOptions> capturedCallOptions =
ArgumentCaptor.forClass(HttpJsonCallOptions.class);
Mockito.when(
mockChannel.issueFutureUnaryCall(
capturedCallOptions.capture(),
Mockito.anyString(),
Mockito.any(ApiMethodDescriptor.class)))
.thenReturn(SettableApiFuture.create());
// Compose the call context
Duration timeout = Duration.ofSeconds(10);
Instant subsequentDeadline = Instant.now().plusSeconds(15);
Instant minExpectedDeadline = Instant.now().plus(timeout);
HttpJsonCallContext callContext =
HttpJsonCallContext.createDefault()
.withChannel(mockChannel)
.withDeadline(subsequentDeadline)
.withTimeout(timeout);
callable.futureCall(expectedRequest, callContext);
Instant maxExpectedDeadline = Instant.now().plus(timeout);
// Verify that the timeout was converted into a deadline
assertThat(capturedCallOptions.getValue().getDeadline()).isAtLeast(minExpectedDeadline);
assertThat(capturedCallOptions.getValue().getDeadline()).isAtMost(maxExpectedDeadline);
}
代码示例来源:origin: googleapis/gax-java
@Test
public void testTimeoutAfterDeadline() {
HttpJsonChannel mockChannel = Mockito.mock(HttpJsonChannel.class);
String expectedRequest = "fake";
HttpJsonDirectCallable<String, String> callable = new HttpJsonDirectCallable<>(API_DESCRIPTOR);
// Mock the channel that captures the call options
ArgumentCaptor<HttpJsonCallOptions> capturedCallOptions =
ArgumentCaptor.forClass(HttpJsonCallOptions.class);
Mockito.when(
mockChannel.issueFutureUnaryCall(
capturedCallOptions.capture(),
Mockito.anyString(),
Mockito.any(ApiMethodDescriptor.class)))
.thenReturn(SettableApiFuture.create());
// Compose the call context
Instant priorDeadline = Instant.now().plusSeconds(5);
Duration timeout = Duration.ofSeconds(10);
HttpJsonCallContext callContext =
HttpJsonCallContext.createDefault()
.withChannel(mockChannel)
.withDeadline(priorDeadline)
.withTimeout(timeout);
callable.futureCall(expectedRequest, callContext);
// Verify that the timeout was ignored
assertThat(capturedCallOptions.getValue().getDeadline()).isEqualTo(priorDeadline);
}
代码示例来源:origin: alexvoronov/geonetworking
@Override
public LongPositionVector getLatestPosition() {
Optional<Address> emptyAddress = Optional.empty();
if (lastSeenTPV == null) {
Instant timestamp = Instant.now();
Position position = new Position(Double.NaN, Double.NaN); // NaN or 0?
boolean isPositionConfident = false;
double speedMetersPerSecond = 0;
double headingDegreesFromNorth = 0;
return new LongPositionVector(emptyAddress, timestamp, position, isPositionConfident,
speedMetersPerSecond, headingDegreesFromNorth);
} else {
final TPV tpv = lastSeenTPV; // Is this enough to ensure that tpv will remain the same
// through the rest of the method?
Instant timestamp = OffsetDateTime.parse(tpv.time()).toInstant();
Position position = new Position(tpv.lat(), tpv.lon());
boolean isPositionConfident = false; // TODO: double-check conditions for PAI=true.
double speedMetersPerSecond = tpv.speed();
double headingDegreesFromNorth = tpv.track();
return new LongPositionVector(emptyAddress, timestamp, position, isPositionConfident,
speedMetersPerSecond, headingDegreesFromNorth);
}
}
内容来源于网络,如有侵权,请联系作者删除!